diff --git a/hinter.js b/hinter.js index 8fb8260..3a582be 100644 --- a/hinter.js +++ b/hinter.js @@ -138,6 +138,8 @@ 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(); }); + // Set autocomplete=on to prevent FF and Chrome from clearing inputs on Back click + addListener(window, 'beforeunload', this.closure['beforeunload'] = function() { e.autocomplete = 'on'; }); addListener(t, 'mousedown', function(ev) { return self.cancelBubbleOnHint(ev); }); this.onChange(); }; @@ -193,6 +195,8 @@ SimpleAutocomplete.prototype.remove = function() if (!this.hintLayer) return; this.hintLayer.parentNode.removeChild(this.hintLayer); + removeListener(window, 'beforeunload', this.closure['beforeunload']); + delete this.closure['beforeunload']; for (var i in this.closure) { removeListener(this.input, i, this.closure[i]); diff --git a/hinter.min.js b/hinter.min.js index 860fef5..b6a3191 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||c.multipleListener;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(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='