1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.ComboBox");
|
|
|
14 |
dojo.require("dojo.widget.*");
|
|
|
15 |
dojo.require("dojo.event.*");
|
|
|
16 |
dojo.require("dojo.io.*");
|
|
|
17 |
dojo.require("dojo.html.*");
|
|
|
18 |
dojo.require("dojo.string");
|
|
|
19 |
dojo.require("dojo.widget.html.stabile");
|
|
|
20 |
dojo.require("dojo.widget.PopupContainer");
|
|
|
21 |
dojo.declare("dojo.widget.incrementalComboBoxDataProvider", null, function (options) {
|
|
|
22 |
this.searchUrl = options.dataUrl;
|
|
|
23 |
this._cache = {};
|
|
|
24 |
this._inFlight = false;
|
|
|
25 |
this._lastRequest = null;
|
|
|
26 |
this.allowCache = false;
|
|
|
27 |
}, {_addToCache:function (keyword, data) {
|
|
|
28 |
if (this.allowCache) {
|
|
|
29 |
this._cache[keyword] = data;
|
|
|
30 |
}
|
|
|
31 |
}, startSearch:function (searchStr, callback) {
|
|
|
32 |
if (this._inFlight) {
|
|
|
33 |
}
|
|
|
34 |
var tss = encodeURIComponent(searchStr);
|
|
|
35 |
var realUrl = dojo.string.substituteParams(this.searchUrl, {"searchString":tss});
|
|
|
36 |
var _this = this;
|
|
|
37 |
var request = this._lastRequest = dojo.io.bind({url:realUrl, method:"get", mimetype:"text/json", load:function (type, data, evt) {
|
|
|
38 |
_this._inFlight = false;
|
|
|
39 |
if (!dojo.lang.isArray(data)) {
|
|
|
40 |
var arrData = [];
|
|
|
41 |
for (var key in data) {
|
|
|
42 |
arrData.push([data[key], key]);
|
|
|
43 |
}
|
|
|
44 |
data = arrData;
|
|
|
45 |
}
|
|
|
46 |
_this._addToCache(searchStr, data);
|
|
|
47 |
if (request == _this._lastRequest) {
|
|
|
48 |
callback(data);
|
|
|
49 |
}
|
|
|
50 |
}});
|
|
|
51 |
this._inFlight = true;
|
|
|
52 |
}});
|
|
|
53 |
dojo.declare("dojo.widget.basicComboBoxDataProvider", null, function (options, node) {
|
|
|
54 |
this._data = [];
|
|
|
55 |
this.searchLimit = 30;
|
|
|
56 |
this.searchType = "STARTSTRING";
|
|
|
57 |
this.caseSensitive = false;
|
|
|
58 |
if (!dj_undef("dataUrl", options) && !dojo.string.isBlank(options.dataUrl)) {
|
|
|
59 |
this._getData(options.dataUrl);
|
|
|
60 |
} else {
|
|
|
61 |
if ((node) && (node.nodeName.toLowerCase() == "select")) {
|
|
|
62 |
var opts = node.getElementsByTagName("option");
|
|
|
63 |
var ol = opts.length;
|
|
|
64 |
var data = [];
|
|
|
65 |
for (var x = 0; x < ol; x++) {
|
|
|
66 |
var text = opts[x].textContent || opts[x].innerText || opts[x].innerHTML;
|
|
|
67 |
var keyValArr = [String(text), String(opts[x].value)];
|
|
|
68 |
data.push(keyValArr);
|
|
|
69 |
if (opts[x].selected) {
|
|
|
70 |
options.setAllValues(keyValArr[0], keyValArr[1]);
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
this.setData(data);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
}, {_getData:function (url) {
|
|
|
77 |
dojo.io.bind({url:url, load:dojo.lang.hitch(this, function (type, data, evt) {
|
|
|
78 |
if (!dojo.lang.isArray(data)) {
|
|
|
79 |
var arrData = [];
|
|
|
80 |
for (var key in data) {
|
|
|
81 |
arrData.push([data[key], key]);
|
|
|
82 |
}
|
|
|
83 |
data = arrData;
|
|
|
84 |
}
|
|
|
85 |
this.setData(data);
|
|
|
86 |
}), mimetype:"text/json"});
|
|
|
87 |
}, startSearch:function (searchStr, callback) {
|
|
|
88 |
this._performSearch(searchStr, callback);
|
|
|
89 |
}, _performSearch:function (searchStr, callback) {
|
|
|
90 |
var st = this.searchType;
|
|
|
91 |
var ret = [];
|
|
|
92 |
if (!this.caseSensitive) {
|
|
|
93 |
searchStr = searchStr.toLowerCase();
|
|
|
94 |
}
|
|
|
95 |
for (var x = 0; x < this._data.length; x++) {
|
|
|
96 |
if ((this.searchLimit > 0) && (ret.length >= this.searchLimit)) {
|
|
|
97 |
break;
|
|
|
98 |
}
|
|
|
99 |
var dataLabel = new String((!this.caseSensitive) ? this._data[x][0].toLowerCase() : this._data[x][0]);
|
|
|
100 |
if (dataLabel.length < searchStr.length) {
|
|
|
101 |
continue;
|
|
|
102 |
}
|
|
|
103 |
if (st == "STARTSTRING") {
|
|
|
104 |
if (searchStr == dataLabel.substr(0, searchStr.length)) {
|
|
|
105 |
ret.push(this._data[x]);
|
|
|
106 |
}
|
|
|
107 |
} else {
|
|
|
108 |
if (st == "SUBSTRING") {
|
|
|
109 |
if (dataLabel.indexOf(searchStr) >= 0) {
|
|
|
110 |
ret.push(this._data[x]);
|
|
|
111 |
}
|
|
|
112 |
} else {
|
|
|
113 |
if (st == "STARTWORD") {
|
|
|
114 |
var idx = dataLabel.indexOf(searchStr);
|
|
|
115 |
if (idx == 0) {
|
|
|
116 |
ret.push(this._data[x]);
|
|
|
117 |
}
|
|
|
118 |
if (idx <= 0) {
|
|
|
119 |
continue;
|
|
|
120 |
}
|
|
|
121 |
var matches = false;
|
|
|
122 |
while (idx != -1) {
|
|
|
123 |
if (" ,/(".indexOf(dataLabel.charAt(idx - 1)) != -1) {
|
|
|
124 |
matches = true;
|
|
|
125 |
break;
|
|
|
126 |
}
|
|
|
127 |
idx = dataLabel.indexOf(searchStr, idx + 1);
|
|
|
128 |
}
|
|
|
129 |
if (!matches) {
|
|
|
130 |
continue;
|
|
|
131 |
} else {
|
|
|
132 |
ret.push(this._data[x]);
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
callback(ret);
|
|
|
139 |
}, setData:function (pdata) {
|
|
|
140 |
this._data = pdata;
|
|
|
141 |
}});
|
|
|
142 |
dojo.widget.defineWidget("dojo.widget.ComboBox", dojo.widget.HtmlWidget, {forceValidOption:false, searchType:"stringstart", dataProvider:null, autoComplete:true, searchDelay:100, dataUrl:"", fadeTime:200, maxListLength:8, mode:"local", selectedResult:null, dataProviderClass:"", buttonSrc:dojo.uri.moduleUri("dojo.widget", "templates/images/combo_box_arrow.png"), dropdownToggle:"fade", templateString:"<span _=\"whitespace and CR's between tags adds in FF\"\n\tclass=\"dojoComboBoxOuter\"\n\t><input style=\"display:none\" tabindex=\"-1\" name=\"\" value=\"\" \n\t\tdojoAttachPoint=\"comboBoxValue\"\n\t><input style=\"display:none\" tabindex=\"-1\" name=\"\" value=\"\" \n\t\tdojoAttachPoint=\"comboBoxSelectionValue\"\n\t><input type=\"text\" autocomplete=\"off\" class=\"dojoComboBox\"\n\t\tdojoAttachEvent=\"key:_handleKeyEvents; keyUp: onKeyUp; compositionEnd; onResize;\"\n\t\tdojoAttachPoint=\"textInputNode\"\n\t><img hspace=\"0\"\n\t\tvspace=\"0\"\n\t\tclass=\"dojoComboBox\"\n\t\tdojoAttachPoint=\"downArrowNode\"\n\t\tdojoAttachEvent=\"onMouseUp: handleArrowClick; onResize;\"\n\t\tsrc=\"${this.buttonSrc}\"\n></span>\n", templateCssString:".dojoComboBoxOuter {\n\tborder: 0px !important;\n\tmargin: 0px !important;\n\tpadding: 0px !important;\n\tbackground: transparent !important;\n\twhite-space: nowrap !important;\n}\n\n.dojoComboBox {\n\tborder: 1px inset #afafaf;\n\tmargin: 0px;\n\tpadding: 0px;\n\tvertical-align: middle !important;\n\tfloat: none !important;\n\tposition: static !important;\n\tdisplay: inline !important;\n}\n\n/* the input box */\ninput.dojoComboBox {\n\tborder-right-width: 0px !important; \n\tmargin-right: 0px !important;\n\tpadding-right: 0px !important;\n}\n\n/* the down arrow */\nimg.dojoComboBox {\n\tborder-left-width: 0px !important;\n\tpadding-left: 0px !important;\n\tmargin-left: 0px !important;\n}\n\n/* IE vertical-alignment calculations can be off by +-1 but these margins are collapsed away */\n.dj_ie img.dojoComboBox {\n\tmargin-top: 1px; \n\tmargin-bottom: 1px; \n}\n\n/* the drop down */\n.dojoComboBoxOptions {\n\tfont-family: Verdana, Helvetica, Garamond, sans-serif;\n\t/* font-size: 0.7em; */\n\tbackground-color: white;\n\tborder: 1px solid #afafaf;\n\tposition: absolute;\n\tz-index: 1000; \n\toverflow: auto;\n\tcursor: default;\n}\n\n.dojoComboBoxItem {\n\tpadding-left: 2px;\n\tpadding-top: 2px;\n\tmargin: 0px;\n}\n\n.dojoComboBoxItemEven {\n\tbackground-color: #f4f4f4;\n}\n\n.dojoComboBoxItemOdd {\n\tbackground-color: white;\n}\n\n.dojoComboBoxItemHighlight {\n\tbackground-color: #63709A;\n\tcolor: white;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/ComboBox.css"), setValue:function (value) {
|
|
|
143 |
this.comboBoxValue.value = value;
|
|
|
144 |
if (this.textInputNode.value != value) {
|
|
|
145 |
this.textInputNode.value = value;
|
|
|
146 |
dojo.widget.html.stabile.setState(this.widgetId, this.getState(), true);
|
|
|
147 |
this.onValueChanged(value);
|
|
|
148 |
}
|
|
|
149 |
}, onValueChanged:function (value) {
|
|
|
150 |
}, getValue:function () {
|
|
|
151 |
return this.comboBoxValue.value;
|
|
|
152 |
}, getState:function () {
|
|
|
153 |
return {value:this.getValue()};
|
|
|
154 |
}, setState:function (state) {
|
|
|
155 |
this.setValue(state.value);
|
|
|
156 |
}, enable:function () {
|
|
|
157 |
this.disabled = false;
|
|
|
158 |
this.textInputNode.removeAttribute("disabled");
|
|
|
159 |
}, disable:function () {
|
|
|
160 |
this.disabled = true;
|
|
|
161 |
this.textInputNode.setAttribute("disabled", true);
|
|
|
162 |
}, _getCaretPos:function (element) {
|
|
|
163 |
if (dojo.lang.isNumber(element.selectionStart)) {
|
|
|
164 |
return element.selectionStart;
|
|
|
165 |
} else {
|
|
|
166 |
if (dojo.render.html.ie) {
|
|
|
167 |
var tr = document.selection.createRange().duplicate();
|
|
|
168 |
var ntr = element.createTextRange();
|
|
|
169 |
tr.move("character", 0);
|
|
|
170 |
ntr.move("character", 0);
|
|
|
171 |
try {
|
|
|
172 |
ntr.setEndPoint("EndToEnd", tr);
|
|
|
173 |
return String(ntr.text).replace(/\r/g, "").length;
|
|
|
174 |
}
|
|
|
175 |
catch (e) {
|
|
|
176 |
return 0;
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
}, _setCaretPos:function (element, location) {
|
|
|
181 |
location = parseInt(location);
|
|
|
182 |
this._setSelectedRange(element, location, location);
|
|
|
183 |
}, _setSelectedRange:function (element, start, end) {
|
|
|
184 |
if (!end) {
|
|
|
185 |
end = element.value.length;
|
|
|
186 |
}
|
|
|
187 |
if (element.setSelectionRange) {
|
|
|
188 |
element.focus();
|
|
|
189 |
element.setSelectionRange(start, end);
|
|
|
190 |
} else {
|
|
|
191 |
if (element.createTextRange) {
|
|
|
192 |
var range = element.createTextRange();
|
|
|
193 |
with (range) {
|
|
|
194 |
collapse(true);
|
|
|
195 |
moveEnd("character", end);
|
|
|
196 |
moveStart("character", start);
|
|
|
197 |
select();
|
|
|
198 |
}
|
|
|
199 |
} else {
|
|
|
200 |
element.value = element.value;
|
|
|
201 |
element.blur();
|
|
|
202 |
element.focus();
|
|
|
203 |
var dist = parseInt(element.value.length) - end;
|
|
|
204 |
var tchar = String.fromCharCode(37);
|
|
|
205 |
var tcc = tchar.charCodeAt(0);
|
|
|
206 |
for (var x = 0; x < dist; x++) {
|
|
|
207 |
var te = document.createEvent("KeyEvents");
|
|
|
208 |
te.initKeyEvent("keypress", true, true, null, false, false, false, false, tcc, tcc);
|
|
|
209 |
element.dispatchEvent(te);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
}
|
|
|
213 |
}, _handleKeyEvents:function (evt) {
|
|
|
214 |
if (evt.ctrlKey || evt.altKey || !evt.key) {
|
|
|
215 |
return;
|
|
|
216 |
}
|
|
|
217 |
this._prev_key_backspace = false;
|
|
|
218 |
this._prev_key_esc = false;
|
|
|
219 |
var k = dojo.event.browser.keys;
|
|
|
220 |
var doSearch = true;
|
|
|
221 |
switch (evt.key) {
|
|
|
222 |
case k.KEY_DOWN_ARROW:
|
|
|
223 |
if (!this.popupWidget.isShowingNow) {
|
|
|
224 |
this._startSearchFromInput();
|
|
|
225 |
}
|
|
|
226 |
this._highlightNextOption();
|
|
|
227 |
dojo.event.browser.stopEvent(evt);
|
|
|
228 |
return;
|
|
|
229 |
case k.KEY_UP_ARROW:
|
|
|
230 |
this._highlightPrevOption();
|
|
|
231 |
dojo.event.browser.stopEvent(evt);
|
|
|
232 |
return;
|
|
|
233 |
case k.KEY_TAB:
|
|
|
234 |
if (!this.autoComplete && this.popupWidget.isShowingNow && this._highlighted_option) {
|
|
|
235 |
dojo.event.browser.stopEvent(evt);
|
|
|
236 |
this._selectOption({"target":this._highlighted_option, "noHide":false});
|
|
|
237 |
this._setSelectedRange(this.textInputNode, this.textInputNode.value.length, null);
|
|
|
238 |
} else {
|
|
|
239 |
this._selectOption();
|
|
|
240 |
return;
|
|
|
241 |
}
|
|
|
242 |
break;
|
|
|
243 |
case k.KEY_ENTER:
|
|
|
244 |
if (this.popupWidget.isShowingNow) {
|
|
|
245 |
dojo.event.browser.stopEvent(evt);
|
|
|
246 |
}
|
|
|
247 |
if (this.autoComplete) {
|
|
|
248 |
this._selectOption();
|
|
|
249 |
return;
|
|
|
250 |
}
|
|
|
251 |
case " ":
|
|
|
252 |
if (this.popupWidget.isShowingNow && this._highlighted_option) {
|
|
|
253 |
dojo.event.browser.stopEvent(evt);
|
|
|
254 |
this._selectOption();
|
|
|
255 |
this._hideResultList();
|
|
|
256 |
return;
|
|
|
257 |
}
|
|
|
258 |
break;
|
|
|
259 |
case k.KEY_ESCAPE:
|
|
|
260 |
this._hideResultList();
|
|
|
261 |
this._prev_key_esc = true;
|
|
|
262 |
return;
|
|
|
263 |
case k.KEY_BACKSPACE:
|
|
|
264 |
this._prev_key_backspace = true;
|
|
|
265 |
if (!this.textInputNode.value.length) {
|
|
|
266 |
this.setAllValues("", "");
|
|
|
267 |
this._hideResultList();
|
|
|
268 |
doSearch = false;
|
|
|
269 |
}
|
|
|
270 |
break;
|
|
|
271 |
case k.KEY_RIGHT_ARROW:
|
|
|
272 |
case k.KEY_LEFT_ARROW:
|
|
|
273 |
doSearch = false;
|
|
|
274 |
break;
|
|
|
275 |
default:
|
|
|
276 |
if (evt.charCode == 0) {
|
|
|
277 |
doSearch = false;
|
|
|
278 |
}
|
|
|
279 |
}
|
|
|
280 |
if (this.searchTimer) {
|
|
|
281 |
clearTimeout(this.searchTimer);
|
|
|
282 |
}
|
|
|
283 |
if (doSearch) {
|
|
|
284 |
this._blurOptionNode();
|
|
|
285 |
this.searchTimer = setTimeout(dojo.lang.hitch(this, this._startSearchFromInput), this.searchDelay);
|
|
|
286 |
}
|
|
|
287 |
}, compositionEnd:function (evt) {
|
|
|
288 |
evt.key = evt.keyCode;
|
|
|
289 |
this._handleKeyEvents(evt);
|
|
|
290 |
}, onKeyUp:function (evt) {
|
|
|
291 |
this.setValue(this.textInputNode.value);
|
|
|
292 |
}, setSelectedValue:function (value) {
|
|
|
293 |
this.comboBoxSelectionValue.value = value;
|
|
|
294 |
}, setAllValues:function (value1, value2) {
|
|
|
295 |
this.setSelectedValue(value2);
|
|
|
296 |
this.setValue(value1);
|
|
|
297 |
}, _focusOptionNode:function (node) {
|
|
|
298 |
if (this._highlighted_option != node) {
|
|
|
299 |
this._blurOptionNode();
|
|
|
300 |
this._highlighted_option = node;
|
|
|
301 |
dojo.html.addClass(this._highlighted_option, "dojoComboBoxItemHighlight");
|
|
|
302 |
}
|
|
|
303 |
}, _blurOptionNode:function () {
|
|
|
304 |
if (this._highlighted_option) {
|
|
|
305 |
dojo.html.removeClass(this._highlighted_option, "dojoComboBoxItemHighlight");
|
|
|
306 |
this._highlighted_option = null;
|
|
|
307 |
}
|
|
|
308 |
}, _highlightNextOption:function () {
|
|
|
309 |
if ((!this._highlighted_option) || !this._highlighted_option.parentNode) {
|
|
|
310 |
this._focusOptionNode(this.optionsListNode.firstChild);
|
|
|
311 |
} else {
|
|
|
312 |
if (this._highlighted_option.nextSibling) {
|
|
|
313 |
this._focusOptionNode(this._highlighted_option.nextSibling);
|
|
|
314 |
}
|
|
|
315 |
}
|
|
|
316 |
dojo.html.scrollIntoView(this._highlighted_option);
|
|
|
317 |
}, _highlightPrevOption:function () {
|
|
|
318 |
if (this._highlighted_option && this._highlighted_option.previousSibling) {
|
|
|
319 |
this._focusOptionNode(this._highlighted_option.previousSibling);
|
|
|
320 |
} else {
|
|
|
321 |
this._highlighted_option = null;
|
|
|
322 |
this._hideResultList();
|
|
|
323 |
return;
|
|
|
324 |
}
|
|
|
325 |
dojo.html.scrollIntoView(this._highlighted_option);
|
|
|
326 |
}, _itemMouseOver:function (evt) {
|
|
|
327 |
if (evt.target === this.optionsListNode) {
|
|
|
328 |
return;
|
|
|
329 |
}
|
|
|
330 |
this._focusOptionNode(evt.target);
|
|
|
331 |
dojo.html.addClass(this._highlighted_option, "dojoComboBoxItemHighlight");
|
|
|
332 |
}, _itemMouseOut:function (evt) {
|
|
|
333 |
if (evt.target === this.optionsListNode) {
|
|
|
334 |
return;
|
|
|
335 |
}
|
|
|
336 |
this._blurOptionNode();
|
|
|
337 |
}, onResize:function () {
|
|
|
338 |
var inputSize = dojo.html.getContentBox(this.textInputNode);
|
|
|
339 |
if (inputSize.height <= 0) {
|
|
|
340 |
dojo.lang.setTimeout(this, "onResize", 100);
|
|
|
341 |
return;
|
|
|
342 |
}
|
|
|
343 |
var buttonSize = {width:inputSize.height, height:inputSize.height};
|
|
|
344 |
dojo.html.setContentBox(this.downArrowNode, buttonSize);
|
|
|
345 |
}, fillInTemplate:function (args, frag) {
|
|
|
346 |
dojo.html.applyBrowserClass(this.domNode);
|
|
|
347 |
var source = this.getFragNodeRef(frag);
|
|
|
348 |
if (!this.name && source.name) {
|
|
|
349 |
this.name = source.name;
|
|
|
350 |
}
|
|
|
351 |
this.comboBoxValue.name = this.name;
|
|
|
352 |
this.comboBoxSelectionValue.name = this.name + "_selected";
|
|
|
353 |
dojo.html.copyStyle(this.domNode, source);
|
|
|
354 |
dojo.html.copyStyle(this.textInputNode, source);
|
|
|
355 |
dojo.html.copyStyle(this.downArrowNode, source);
|
|
|
356 |
with (this.downArrowNode.style) {
|
|
|
357 |
width = "0px";
|
|
|
358 |
height = "0px";
|
|
|
359 |
}
|
|
|
360 |
var dpClass;
|
|
|
361 |
if (this.dataProviderClass) {
|
|
|
362 |
if (typeof this.dataProviderClass == "string") {
|
|
|
363 |
dpClass = dojo.evalObjPath(this.dataProviderClass);
|
|
|
364 |
} else {
|
|
|
365 |
dpClass = this.dataProviderClass;
|
|
|
366 |
}
|
|
|
367 |
} else {
|
|
|
368 |
if (this.mode == "remote") {
|
|
|
369 |
dpClass = dojo.widget.incrementalComboBoxDataProvider;
|
|
|
370 |
} else {
|
|
|
371 |
dpClass = dojo.widget.basicComboBoxDataProvider;
|
|
|
372 |
}
|
|
|
373 |
}
|
|
|
374 |
this.dataProvider = new dpClass(this, this.getFragNodeRef(frag));
|
|
|
375 |
this.popupWidget = new dojo.widget.createWidget("PopupContainer", {toggle:this.dropdownToggle, toggleDuration:this.toggleDuration});
|
|
|
376 |
dojo.event.connect(this, "destroy", this.popupWidget, "destroy");
|
|
|
377 |
this.optionsListNode = this.popupWidget.domNode;
|
|
|
378 |
this.domNode.appendChild(this.optionsListNode);
|
|
|
379 |
dojo.html.addClass(this.optionsListNode, "dojoComboBoxOptions");
|
|
|
380 |
dojo.event.connect(this.optionsListNode, "onclick", this, "_selectOption");
|
|
|
381 |
dojo.event.connect(this.optionsListNode, "onmouseover", this, "_onMouseOver");
|
|
|
382 |
dojo.event.connect(this.optionsListNode, "onmouseout", this, "_onMouseOut");
|
|
|
383 |
dojo.event.connect(this.optionsListNode, "onmouseover", this, "_itemMouseOver");
|
|
|
384 |
dojo.event.connect(this.optionsListNode, "onmouseout", this, "_itemMouseOut");
|
|
|
385 |
}, _openResultList:function (results) {
|
|
|
386 |
if (this.disabled) {
|
|
|
387 |
return;
|
|
|
388 |
}
|
|
|
389 |
this._clearResultList();
|
|
|
390 |
if (!results.length) {
|
|
|
391 |
this._hideResultList();
|
|
|
392 |
}
|
|
|
393 |
if ((this.autoComplete) && (results.length) && (!this._prev_key_backspace) && (this.textInputNode.value.length > 0)) {
|
|
|
394 |
var cpos = this._getCaretPos(this.textInputNode);
|
|
|
395 |
if ((cpos + 1) > this.textInputNode.value.length) {
|
|
|
396 |
this.textInputNode.value += results[0][0].substr(cpos);
|
|
|
397 |
this._setSelectedRange(this.textInputNode, cpos, this.textInputNode.value.length);
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
var even = true;
|
|
|
401 |
while (results.length) {
|
|
|
402 |
var tr = results.shift();
|
|
|
403 |
if (tr) {
|
|
|
404 |
var td = document.createElement("div");
|
|
|
405 |
td.appendChild(document.createTextNode(tr[0]));
|
|
|
406 |
td.setAttribute("resultName", tr[0]);
|
|
|
407 |
td.setAttribute("resultValue", tr[1]);
|
|
|
408 |
td.className = "dojoComboBoxItem " + ((even) ? "dojoComboBoxItemEven" : "dojoComboBoxItemOdd");
|
|
|
409 |
even = (!even);
|
|
|
410 |
this.optionsListNode.appendChild(td);
|
|
|
411 |
}
|
|
|
412 |
}
|
|
|
413 |
this._showResultList();
|
|
|
414 |
}, _onFocusInput:function () {
|
|
|
415 |
this._hasFocus = true;
|
|
|
416 |
}, _onBlurInput:function () {
|
|
|
417 |
this._hasFocus = false;
|
|
|
418 |
this._handleBlurTimer(true, 500);
|
|
|
419 |
}, _handleBlurTimer:function (clear, millisec) {
|
|
|
420 |
if (this.blurTimer && (clear || millisec)) {
|
|
|
421 |
clearTimeout(this.blurTimer);
|
|
|
422 |
}
|
|
|
423 |
if (millisec) {
|
|
|
424 |
this.blurTimer = dojo.lang.setTimeout(this, "_checkBlurred", millisec);
|
|
|
425 |
}
|
|
|
426 |
}, _onMouseOver:function (evt) {
|
|
|
427 |
if (!this._mouseover_list) {
|
|
|
428 |
this._handleBlurTimer(true, 0);
|
|
|
429 |
this._mouseover_list = true;
|
|
|
430 |
}
|
|
|
431 |
}, _onMouseOut:function (evt) {
|
|
|
432 |
var relTarget = evt.relatedTarget;
|
|
|
433 |
try {
|
|
|
434 |
if (!relTarget || relTarget.parentNode != this.optionsListNode) {
|
|
|
435 |
this._mouseover_list = false;
|
|
|
436 |
this._handleBlurTimer(true, 100);
|
|
|
437 |
this._tryFocus();
|
|
|
438 |
}
|
|
|
439 |
}
|
|
|
440 |
catch (e) {
|
|
|
441 |
}
|
|
|
442 |
}, _isInputEqualToResult:function (result) {
|
|
|
443 |
var input = this.textInputNode.value;
|
|
|
444 |
if (!this.dataProvider.caseSensitive) {
|
|
|
445 |
input = input.toLowerCase();
|
|
|
446 |
result = result.toLowerCase();
|
|
|
447 |
}
|
|
|
448 |
return (input == result);
|
|
|
449 |
}, _isValidOption:function () {
|
|
|
450 |
var tgt = dojo.html.firstElement(this.optionsListNode);
|
|
|
451 |
var isValidOption = false;
|
|
|
452 |
while (!isValidOption && tgt) {
|
|
|
453 |
if (this._isInputEqualToResult(tgt.getAttribute("resultName"))) {
|
|
|
454 |
isValidOption = true;
|
|
|
455 |
} else {
|
|
|
456 |
tgt = dojo.html.nextElement(tgt);
|
|
|
457 |
}
|
|
|
458 |
}
|
|
|
459 |
return isValidOption;
|
|
|
460 |
}, _checkBlurred:function () {
|
|
|
461 |
if (!this._hasFocus && !this._mouseover_list) {
|
|
|
462 |
this._hideResultList();
|
|
|
463 |
if (!this.textInputNode.value.length) {
|
|
|
464 |
this.setAllValues("", "");
|
|
|
465 |
return;
|
|
|
466 |
}
|
|
|
467 |
var isValidOption = this._isValidOption();
|
|
|
468 |
if (this.forceValidOption && !isValidOption) {
|
|
|
469 |
this.setAllValues("", "");
|
|
|
470 |
return;
|
|
|
471 |
}
|
|
|
472 |
if (!isValidOption) {
|
|
|
473 |
this.setSelectedValue("");
|
|
|
474 |
}
|
|
|
475 |
}
|
|
|
476 |
}, _selectOption:function (evt) {
|
|
|
477 |
var tgt = null;
|
|
|
478 |
if (!evt) {
|
|
|
479 |
evt = {target:this._highlighted_option};
|
|
|
480 |
}
|
|
|
481 |
if (!dojo.html.isDescendantOf(evt.target, this.optionsListNode)) {
|
|
|
482 |
if (!this.textInputNode.value.length) {
|
|
|
483 |
return;
|
|
|
484 |
}
|
|
|
485 |
tgt = dojo.html.firstElement(this.optionsListNode);
|
|
|
486 |
if (!tgt || !this._isInputEqualToResult(tgt.getAttribute("resultName"))) {
|
|
|
487 |
return;
|
|
|
488 |
}
|
|
|
489 |
} else {
|
|
|
490 |
tgt = evt.target;
|
|
|
491 |
}
|
|
|
492 |
while ((tgt.nodeType != 1) || (!tgt.getAttribute("resultName"))) {
|
|
|
493 |
tgt = tgt.parentNode;
|
|
|
494 |
if (tgt === dojo.body()) {
|
|
|
495 |
return false;
|
|
|
496 |
}
|
|
|
497 |
}
|
|
|
498 |
this.selectedResult = [tgt.getAttribute("resultName"), tgt.getAttribute("resultValue")];
|
|
|
499 |
this.setAllValues(tgt.getAttribute("resultName"), tgt.getAttribute("resultValue"));
|
|
|
500 |
if (!evt.noHide) {
|
|
|
501 |
this._hideResultList();
|
|
|
502 |
this._setSelectedRange(this.textInputNode, 0, null);
|
|
|
503 |
}
|
|
|
504 |
this._tryFocus();
|
|
|
505 |
}, _clearResultList:function () {
|
|
|
506 |
if (this.optionsListNode.innerHTML) {
|
|
|
507 |
this.optionsListNode.innerHTML = "";
|
|
|
508 |
}
|
|
|
509 |
}, _hideResultList:function () {
|
|
|
510 |
this.popupWidget.close();
|
|
|
511 |
}, _showResultList:function () {
|
|
|
512 |
var childs = this.optionsListNode.childNodes;
|
|
|
513 |
if (childs.length) {
|
|
|
514 |
var visibleCount = Math.min(childs.length, this.maxListLength);
|
|
|
515 |
with (this.optionsListNode.style) {
|
|
|
516 |
display = "";
|
|
|
517 |
if (visibleCount == childs.length) {
|
|
|
518 |
height = "";
|
|
|
519 |
} else {
|
|
|
520 |
height = visibleCount * dojo.html.getMarginBox(childs[0]).height + "px";
|
|
|
521 |
}
|
|
|
522 |
width = (dojo.html.getMarginBox(this.domNode).width - 2) + "px";
|
|
|
523 |
}
|
|
|
524 |
this.popupWidget.open(this.domNode, this, this.downArrowNode);
|
|
|
525 |
} else {
|
|
|
526 |
this._hideResultList();
|
|
|
527 |
}
|
|
|
528 |
}, handleArrowClick:function () {
|
|
|
529 |
this._handleBlurTimer(true, 0);
|
|
|
530 |
this._tryFocus();
|
|
|
531 |
if (this.popupWidget.isShowingNow) {
|
|
|
532 |
this._hideResultList();
|
|
|
533 |
} else {
|
|
|
534 |
this._startSearch("");
|
|
|
535 |
}
|
|
|
536 |
}, _tryFocus:function () {
|
|
|
537 |
try {
|
|
|
538 |
this.textInputNode.focus();
|
|
|
539 |
}
|
|
|
540 |
catch (e) {
|
|
|
541 |
}
|
|
|
542 |
}, _startSearchFromInput:function () {
|
|
|
543 |
this._startSearch(this.textInputNode.value);
|
|
|
544 |
}, _startSearch:function (key) {
|
|
|
545 |
this.dataProvider.startSearch(key, dojo.lang.hitch(this, "_openResultList"));
|
|
|
546 |
}, postCreate:function () {
|
|
|
547 |
this.onResize();
|
|
|
548 |
dojo.event.connect(this.textInputNode, "onblur", this, "_onBlurInput");
|
|
|
549 |
dojo.event.connect(this.textInputNode, "onfocus", this, "_onFocusInput");
|
|
|
550 |
if (this.disabled) {
|
|
|
551 |
this.disable();
|
|
|
552 |
}
|
|
|
553 |
var s = dojo.widget.html.stabile.getState(this.widgetId);
|
|
|
554 |
if (s) {
|
|
|
555 |
this.setState(s);
|
|
|
556 |
}
|
|
|
557 |
}});
|
|
|
558 |
|