Changeset 7563
- Timestamp:
- 07/25/08 17:57:13 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/topp/almanac/lib/OpenLayers/Control/MultiItemSelect.js
r7560 r7563 29 29 items : null, 30 30 31 texts : null, 32 31 33 /* 32 34 * Property: chosen … … 43 45 * ID's for DOM elements 44 46 */ 45 textId: "text",47 queryId: "query", 46 48 itemListId: "items", 47 49 chooseButtonId: "choose", … … 51 53 * DOM elements 52 54 */ 53 text: null,55 query : null, 54 56 itemList : null, 55 57 chooseButton : null, … … 62 64 keyHandler : null, 63 65 64 //is the text inputfocused?66 //is the text query focused? 65 67 textFocus : false, 66 68 … … 68 70 OpenLayers.Util.extend(this, options); 69 71 70 this. text = document.getElementById(this.textId);72 this.query = document.getElementById(this.queryId); 71 73 this.itemList = document.getElementById(this.itemListId); 72 74 this.chooseButton = document.getElementById(this.chooseButtonId); 73 75 this.chosenList = document.getElementById(this.chosenListId); 74 76 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 76 83 this.chosen = chosen; 77 84 … … 82 89 { 83 90 'keypress' : function(){ 84 if(multiItemSelect. textFocus){91 if(multiItemSelect.queryFocus){ 85 92 setTimeout(function(){ 86 93 multiItemSelect.updateItems(); … … 98 105 var multiItemSelect = this; 99 106 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;} 102 109 103 110 this.updateItems(); … … 106 113 107 114 updateItems : function(){ 108 var query = this. text.value;115 var query = this.query.value; 109 116 110 117 //the slow way first … … 118 125 119 126 //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] 122 129 123 130 if(item.match(this.escape(query)) && !this.isChosen(item)){ … … 151 158 var li = document.createElement("li"); 152 159 153 index = OpenLayers.Util.indexOf(this. items, this.chosen[i]);160 index = OpenLayers.Util.indexOf(this.texts, this.chosen[i]); 154 161 li.id = this.chosenPrefix + "." + index; 155 162 … … 169 176 if(this.selectedItem == -1 || 170 177 document.getElementById(this.itemPrefix + "." + this.selectedItem)){ 171 this.chosen.push(this. items[this.selectedItem]);178 this.chosen.push(this.texts[this.selectedItem]); 172 179 } else { 173 OpenLayers.Util.removeItem(this.chosen, this. items[this.selectedItem]);180 OpenLayers.Util.removeItem(this.chosen, this.texts[this.selectedItem]); 174 181 } 175 182 … … 216 223 }, 217 224 218 no TextSelect : function(element){225 noQuerySelect : function(element){ 219 226 if(element){ 220 227 element.onselectstart = function () { return false; } // ie … … 223 230 }, 224 231 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 225 241 //escapes a literal string to be passed on as a regex 226 escape : function( text) {242 escape : function(str) { 227 243 if (!arguments.callee.sRE) { 228 244 var specials = [ … … 234 250 ); 235 251 } 236 return text.replace(arguments.callee.sRE, '\\$1');252 return str.replace(arguments.callee.sRE, '\\$1'); 237 253 }, 238 254
