diff --git a/hinter.js b/hinter.js index 2a5771e..da9dcb6 100644 --- a/hinter.js +++ b/hinter.js @@ -289,6 +289,17 @@ SimpleAutocomplete.prototype.getItem = function(index) // Select index'th item - change the input value and hide the hint if not a multi-select SimpleAutocomplete.prototype.selectItem = function(index) { + if (this.items[index][2]) + return false; + if (this.moreMarker && this.items[index][1] == this.moreMarker) + { + // User clicked 'more'. Load more items without delay. + this.items.splice(index, 1); + elm.parentNode.removeChild(elm); + this.more++; + this.onChange(true); + return; + } if (!this.multipleDelimiter && !this.multipleListener) { this.input.value = this.items[index][1]; @@ -406,17 +417,6 @@ SimpleAutocomplete.prototype.onItemMouseOver = function(elm) SimpleAutocomplete.prototype.onItemClick = function(ev, elm) { var index = parseInt(elm.id.substr(this.id.length+6)); - if (this.items[index][2]) - return false; - if (this.moreMarker && this.items[index][1] == this.moreMarker) - { - // User clicked 'more'. Load more items without delay. - this.items.splice(index, 1); - elm.parentNode.removeChild(elm); - this.more++; - this.onChange(true); - return true; - } this.selectItem(index); return true; }; diff --git a/hinter.min.js b/hinter.min.js index c0e8db5..8ccad36 100644 --- a/hinter.min.js +++ b/hinter.min.js @@ -1,4 +1,4 @@ // (c) Vitaliy Filippov 2011-2013 // @license MPL 2.0 http://www.mozilla.org/MPL/2.0/ // http://yourcmc.ru/wiki/SimpleAutocomplete -var SimpleAutocomplete=function(b,a,c){if(typeof(b)=="string"){b=document.getElementById(b)}if(!c){c={}}this.input=b;this.a=a;this.b=c.multipleDelimiter;this.c=c.multipleListener;this.d=c.onChangeListener;this.e=c.emptyText;this.f=c.prompt;this.g=c.delay;this.h=c.moreMarker;if(this.h===undefined){this.h="#MORE"}if(this.g===undefined){this.g=300}this.i=0;this.j=null;this.k=[];this.l=[];this.m=0;this.n=-1;this.o=false;this.p()};SimpleAutocomplete.prototype.p=function(){var f=this.input;var a=SimpleAutocomplete.q;this.r=this.input.id+a.length;a.push(this);var d=getOffset(f);var c=this.s=document.createElement("div");c.className="hintLayer";c.style.display="none";c.style.position="absolute";c.style.top=(d.top+f.offsetHeight)+"px";c.style.zIndex=1000;c.style.left=d.left+"px";document.body.appendChild(c);f.SimpleAutocomplete_input=this;c.SimpleAutocomplete_layer=this;if(typeof f.autocomplete!=="undefined"){f.autocomplete="off";addListener(window,"beforeunload",function(){f.autocomplete="on"})}var b=this;this.t("keydown",function(e){return b.u(e)});this.t("keyup",function(e){return b.v(e)});this.t("change",function(){return b.onChange()});this.t("focus",function(){return b.w()});this.t("blur",function(){return b.x()});addListener(c,"mousedown",function(e){return b.y(e)});this.onChange()};SimpleAutocomplete.prototype.replaceItems=function(c,a){if(!a){this.s.scrollTop=0;this.n=0;this.l=[];if(!c||c.length==0){if(this.e){this.s.innerHTML='