OpenLayers OpenLayers

Changeset 7563

Show
Ignore:
Timestamp:
07/25/08 17:57:13 (4 months ago)
Author:
sbenthall
Message:

fixes and renaming for MIS

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/topp/almanac/lib/OpenLayers/Control/MultiItemSelect.js

    r7560 r7563  
    2929    items : null, 
    3030 
     31    texts : null, 
     32 
    3133    /* 
    3234     * Property: chosen 
     
    4345     * ID's for DOM elements 
    4446     */ 
    45     textId: "text", 
     47    queryId: "query", 
    4648    itemListId: "items", 
    4749    chooseButtonId: "choose", 
     
    5153     * DOM elements 
    5254     */ 
    53     text : null, 
     55    query : null, 
    5456    itemList : null, 
    5557    chooseButton : null, 
     
    6264    keyHandler : null, 
    6365 
    64     //is the text input focused? 
     66    //is the text query focused? 
    6567    textFocus : false, 
    6668 
     
    6870        OpenLayers.Util.extend(this, options); 
    6971 
    70         this.text = document.getElementById(this.textId); 
     72        this.query = document.getElementById(this.queryId); 
    7173        this.itemList = document.getElementById(this.itemListId); 
    7274        this.chooseButton = document.getElementById(this.chooseButtonId); 
    7375        this.chosenList = document.getElementById(this.chosenListId); 
    7476 
    75         this.items = items.sort(); 
     77        this.items = items; 
     78        this.texts = []; 
     79        for(var i = 0; i < this.items.length; i++){ 
     80            this.texts.push(this.items[i].text); 
     81        } 
     82 
    7683        this.chosen = chosen; 
    7784 
     
    8289            { 
    8390                'keypress' : function(){ 
    84                     if(multiItemSelect.textFocus){ 
     91                    if(multiItemSelect.queryFocus){ 
    8592                        setTimeout(function(){ 
    8693                            multiItemSelect.updateItems(); 
     
    98105        var multiItemSelect = this; 
    99106 
    100         this.text.onfocus = function(){multiItemSelect.textFocus = true;} 
    101         this.text.onblur = function(){multiItemSelect.textFocus = false;} 
     107        this.query.onfocus = function(){multiItemSelect.queryFocus = true;} 
     108        this.query.onblur = function(){multiItemSelect.queryFocus = false;} 
    102109 
    103110        this.updateItems(); 
     
    106113 
    107114    updateItems : function(){ 
    108         var query = this.text.value; 
     115        var query = this.query.value; 
    109116 
    110117        //the slow way first 
     
    118125 
    119126        //add things if there is a match 
    120         for(var i = 0; i < this.items.length; i++){ 
    121             item = this.items[i] 
     127        for(var i = 0; i < this.texts.length; i++){ 
     128            item = this.texts[i] 
    122129 
    123130            if(item.match(this.escape(query)) && !this.isChosen(item)){ 
     
    151158            var li = document.createElement("li"); 
    152159                 
    153             index = OpenLayers.Util.indexOf(this.items, this.chosen[i]); 
     160            index = OpenLayers.Util.indexOf(this.texts, this.chosen[i]); 
    154161            li.id = this.chosenPrefix + "." + index; 
    155162                 
     
    169176        if(this.selectedItem == -1 || 
    170177            document.getElementById(this.itemPrefix + "." + this.selectedItem)){ 
    171             this.chosen.push(this.items[this.selectedItem]); 
     178            this.chosen.push(this.texts[this.selectedItem]); 
    172179        } else { 
    173             OpenLayers.Util.removeItem(this.chosen, this.items[this.selectedItem]); 
     180            OpenLayers.Util.removeItem(this.chosen, this.texts[this.selectedItem]); 
    174181        } 
    175182 
     
    216223    }, 
    217224 
    218     noTextSelect : function(element){ 
     225    noQuerySelect : function(element){ 
    219226        if(element){ 
    220227            element.onselectstart = function () { return false; } // ie 
     
    223230    }, 
    224231 
     232    getChosenItems : function(){ 
     233        var chosenItems = []; 
     234        for(var i = 0; i < this.chosen.length; i++){ 
     235            chosenItems.push(this.items[OpenLayers.Util.indexOf(this.texts,this.chosen[i])]); 
     236        } 
     237 
     238        return chosenItems; 
     239    }, 
     240 
    225241    //escapes a literal string to be passed on as a regex 
    226     escape : function(text) { 
     242    escape : function(str) { 
    227243        if (!arguments.callee.sRE) { 
    228244            var specials = [ 
     
    234250            ); 
    235251        } 
    236         return text.replace(arguments.callee.sRE, '\\$1'); 
     252        return str.replace(arguments.callee.sRE, '\\$1'); 
    237253    }, 
    238254