Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/externals/javelin/lib/control/typeahead/Typeahead.js
Show First 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | showResults : function(results, value) { | ||||
// In all cases, just throw these results away. They are no longer | // In all cases, just throw these results away. They are no longer | ||||
// relevant. | // relevant. | ||||
return; | return; | ||||
} | } | ||||
var obj = {show: results}; | var obj = {show: results}; | ||||
var e = this.invoke('show', obj); | var e = this.invoke('show', obj); | ||||
// If the user has an element focused, store the value before we redraw. | |||||
// After we redraw, try to select the same element if it still exists in | |||||
// the list. This prevents redraws from disrupting keyboard element | |||||
// selection. | |||||
var old_focus = null; | |||||
if (this._focus >= 0 && this._display[this._focus]) { | |||||
old_focus = this._display[this._focus].name; | |||||
} | |||||
// Note that the results list may have been update by the "show" event | // Note that the results list may have been update by the "show" event | ||||
// listener. Non-result node (e.g. divider or label) may have been | // listener. Non-result node (e.g. divider or label) may have been | ||||
// inserted. | // inserted. | ||||
JX.DOM.setContent(this._root, results); | JX.DOM.setContent(this._root, results); | ||||
this._display = JX.DOM.scry(this._root, 'a', 'typeahead-result'); | this._display = JX.DOM.scry(this._root, 'a', 'typeahead-result'); | ||||
if (this._display.length && !e.getPrevented()) { | if (this._display.length && !e.getPrevented()) { | ||||
this._changeFocus(Number.NEGATIVE_INFINITY); | this._changeFocus(Number.NEGATIVE_INFINITY); | ||||
var d = JX.Vector.getDim(this._hardpoint); | var d = JX.Vector.getDim(this._hardpoint); | ||||
d.x = 0; | d.x = 0; | ||||
d.setPos(this._root); | d.setPos(this._root); | ||||
if (this._root.parentNode !== this._hardpoint) { | if (this._root.parentNode !== this._hardpoint) { | ||||
this._hardpoint.appendChild(this._root); | this._hardpoint.appendChild(this._root); | ||||
} | } | ||||
JX.DOM.show(this._root); | JX.DOM.show(this._root); | ||||
// If we had a node focused before, look for a node with the same value | |||||
// and focus it. | |||||
if (old_focus !== null) { | |||||
for (var ii = 0; ii < this._display.length; ii++) { | |||||
if (this._display[ii].name == old_focus) { | |||||
this._focus = ii; | |||||
this._drawFocus(); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} else { | } else { | ||||
this.hide(); | this.hide(); | ||||
JX.DOM.setContent(this._root, null); | JX.DOM.setContent(this._root, null); | ||||
} | } | ||||
}, | }, | ||||
refresh : function() { | refresh : function() { | ||||
if (this._stop) { | if (this._stop) { | ||||
▲ Show 20 Lines • Show All 273 Lines • Show Last 20 Lines |