diff --git a/hinter.js b/hinter.js index 8549bfd..2a5771e 100644 --- a/hinter.js +++ b/hinter.js @@ -110,7 +110,6 @@ var SimpleAutocomplete = function(input, dataLoader, params) SimpleAutocomplete.prototype.init = function() { var e = this.input; - e.autocomplete = 'off'; var l = SimpleAutocomplete.SimpleAutocompletes; this.id = this.input.id + l.length; l.push(this); @@ -131,6 +130,13 @@ SimpleAutocomplete.prototype.init = function() e.SimpleAutocomplete_input = this; t.SimpleAutocomplete_layer = this; + // Set autocomplete to off and reenable before unload + if (typeof e.autocomplete !== 'undefined') + { + e.autocomplete = 'off'; + addListener(window, 'beforeunload', function() { e.autocomplete = 'on'; }); + } + // Set event listeners var self = this; this.addRmListener('keydown', function(ev) { return self.onKeyDown(ev); }); @@ -138,7 +144,6 @@ SimpleAutocomplete.prototype.init = function() this.addRmListener('change', function() { return self.onChange(); }); this.addRmListener('focus', function() { return self.onInputFocus(); }); this.addRmListener('blur', function() { return self.onInputBlur(); }); - addListener(window, 'beforeunload', function() { e.autocomplete = 'on'; }); addListener(t, 'mousedown', function(ev) { return self.cancelBubbleOnHint(ev); }); this.onChange(); }; @@ -238,7 +243,7 @@ SimpleAutocomplete.prototype.makeItem = function(index, item) d.innerHTML = item[0]; var self = this; addListener(d, 'mouseover', function() { return self.onItemMouseOver(this); }); - addListener(d, 'mousedown', function(ev) { return self.onItemClick(ev, this); }); + addListener(d, 'click', function(ev) { return self.onItemClick(ev, this); }); return d; }; diff --git a/hinter.min.js b/hinter.min.js index c8f9585..c0e8db5 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;f.autocomplete="off";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;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(window,"beforeunload",function(){f.autocomplete="on"});addListener(c,"mousedown",function(e){return b.y(e)});this.onChange()};SimpleAutocomplete.prototype.replaceItems=function(b,e){if(!e){this.s.scrollTop=0;this.n=0;this.l=[];if(!b||b.length==0){if(this.e){this.s.innerHTML='
'+this.e+"
"}else{this.z()}return}this.s.innerHTML=this.f?'
'+this.f+"
":"";this.aa()}if(!this.c){for(var c in b){b[c][2]=0}}if(this.b){var d={};var a=this.input.value.split(this.b);for(var c=0;c=0){var d=this.ah();if(d){d.className="hintItem"}}this.n=a;b.className="hintActiveItem";return false};SimpleAutocomplete.prototype.ah=function(a){if(a==null){a=this.n}if(a<0){return null}return document.getElementById(this.r+"_item_"+this.n)};SimpleAutocomplete.prototype.ai=function(a){if(!this.b&&!this.c){this.input.value=this.l[a][1];this.hide()}else{document.getElementById(this.r+"_check_"+a).checked=this.l[a][3]=!this.l[a][3];if(this.c&&!this.c(this,a,this.l[a])){return}this.aj(a)}this.ak=this.input.value;if(this.d){this.d(this,a)}};SimpleAutocomplete.prototype.aj=function(c){var b=this.input.value.split(this.b);for(var d=0;d=0;d--){if(b[d]==this.l[c][1]){b.splice(d,1)}}this.input.value=b.join(this.b+" ")}else{var e={};for(var d=0;d=0){this.ai(this.n)}return stopEvent(e,true,true)}else{if(e.keyCode==27){this.hide();return stopEvent(e,true,true)}else{return true}}}}if(this.n>=0){var f=this.ah();var b=this.s;var a=getOffset(f).top+b.scrollTop-b.style.top.substr(0,b.style.top.length-2);var d=f.scrollHeight;if(a+d-b.offsetHeight>b.scrollTop){b.scrollTop=a+d-b.offsetHeight}else{if(a'+this.e+""}else{this.z()}return}this.s.innerHTML=this.f?'
'+this.f+"
":"";this.aa()}if(!this.c){for(var d in c){c[d][2]=0}}if(this.b){var e={};var b=this.input.value.split(this.b);for(var d=0;d=0){var d=this.ah();if(d){d.className="hintItem"}}this.n=a;b.className="hintActiveItem";return false};SimpleAutocomplete.prototype.ah=function(a){if(a==null){a=this.n}if(a<0){return null}return document.getElementById(this.r+"_item_"+this.n)};SimpleAutocomplete.prototype.selectItem=function(a){if(!this.b&&!this.c){this.input.value=this.l[a][1];this.hide()}else{document.getElementById(this.r+"_check_"+a).checked=this.l[a][3]=!this.l[a][3];if(this.c&&!this.c(this,a,this.l[a])){return}this.ai(a)}this.aj=this.input.value;if(this.d){this.d(this,a)}};SimpleAutocomplete.prototype.ai=function(c){var b=this.input.value.split(this.b);for(var d=0;d=0;d--){if(b[d]==this.l[c][1]){b.splice(d,1)}}this.input.value=b.join(this.b+" ")}else{var e={};for(var d=0;d=0){this.selectItem(this.n)}return stopEvent(e,true,true)}else{if(e.keyCode==27){this.hide();return stopEvent(e,true,true)}else{return true}}}}if(this.n>=0){var f=this.ah();var b=this.s;var a=getOffset(f).top+b.scrollTop-b.style.top.substr(0,b.style.top.length-2);var d=f.scrollHeight;if(a+d-b.offsetHeight>b.scrollTop){b.scrollTop=a+d-b.offsetHeight}else{if(a 1 } qw(input remove replaceItems hide onChange); +my %whitelist = map { $_ => 1 } qw(input remove replaceItems show hide onChange selectItem); my %var = (); my @names = 'a'..'ba';