diff --git a/hinter.js b/hinter.js index 9c97afa..40f797e 100644 --- a/hinter.js +++ b/hinter.js @@ -2,7 +2,7 @@ Homepage: http://yourcmc.ru/wiki/SimpleAutocomplete License: MPL 2.0+ (http://www.mozilla.org/MPL/2.0/) - Version: 2014-09-05 + Version: 2014-09-11 (c) Vitaliy Filippov 2011-2014 Usage: @@ -122,8 +122,6 @@ SimpleAutocomplete.prototype.init = function() this.id = this.input.id + l.length; l.push(this); - var p = getOffset(e); - // Create hint layer var t = this.hintLayer = document.createElement('div'); t.className = this.className; @@ -131,9 +129,7 @@ SimpleAutocomplete.prototype.init = function() { t.style.display = 'none'; t.style.position = 'absolute'; - t.style.top = (p.top+e.offsetHeight) + 'px'; t.style.zIndex = 1000; - t.style.left = p.left + 'px'; document.body.appendChild(t); } else @@ -567,21 +563,6 @@ SimpleAutocomplete.GlobalMouseDown = function(ev) // *** UTILITY FUNCTIONS *** // Remove this section if you already have these functions defined somewhere else -// Cross-browser add/remove event listeners -var addListener = function() -{ - return window.addEventListener - ? function(el, type, fn) { el.addEventListener(type, fn, false); } - : function(el, type, fn) { el.attachEvent('on'+type, fn); }; -}(); - -var removeListener = function() -{ - return window.removeEventListener - ? function(el, type, fn) { el.removeEventListener(type, fn, false); } - : function(el, type, fn) { el.detachEvent('on'+type, fn); }; -}(); - // Cancel event bubbling and/or default action var stopEvent = function(ev, cancelBubble, preventDefault) { @@ -598,15 +579,6 @@ var stopEvent = function(ev, cancelBubble, preventDefault) return !preventDefault; }; -// Remove leading and trailing whitespace -if (!String.prototype.trim) -{ - String.prototype.trim = function() - { - return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); - }; -} - // Get element position, relative to the top-left corner of page var getOffset = function(elem) { diff --git a/hinter.min.js b/hinter.min.js index 03fee68..a0c15d7 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;this.i=c.persist;this.j=c.className||"hintLayer";if(this.h===undefined){this.h="#MORE"}if(this.g===undefined){this.g=300}this.k=0;this.l=null;this.m=[];this.n=[];this.o=0;this.p=-1;this.q=false;this.r()};SimpleAutocomplete.prototype.r=function(){var f=this.input;var a=SimpleAutocomplete.s;this.t=this.input.id+a.length;a.push(this);var d=getOffset(f);var c=this.u=document.createElement("div");c.className=this.j;if(!this.i){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)}else{f.nextSibling?f.parentNode.insertBefore(c,f.nextSibling):f.parentNode.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.v("keydown",function(e){return b.w(e)});this.v("keyup",function(e){return b.x(e)});this.v("change",function(){return b.onChange()});this.v("focus",function(){return b.y()});this.v("blur",function(){return b.z()});addListener(c,"mousedown",function(e){return b.aa(e)});this.onChange(true)};SimpleAutocomplete.prototype.replaceItems=function(c,a){if(!a){this.u.scrollTop=0;this.p=0;this.n=[];if(!c||c.length==0){if(this.e){this.u.innerHTML='
'+this.e+"
"}else{this.ab()}return}while(this.p'+this.f+"":"";this.ac()}if(this.b){var e={};var b=this.input.value.split(this.b);for(var d=0;d=0){var d=this.aj();if(d){d.className=this.n[this.p][2]?"hintDisabledItem":"hintItem"}}this.p=a;b.className="hintActiveItem";return false};SimpleAutocomplete.prototype.aj=function(a){if(a==null){a=this.p}if(a<0){return null}return document.getElementById(this.t+"_item_"+this.p)};SimpleAutocomplete.prototype.selectItem=function(a){if(this.n[a][2]){return false}if(this.h&&this.n[a][1]==this.h){this.n.splice(a,1);elm.parentNode.removeChild(elm);this.k++;this.onChange(true);return}if(!this.b&&!this.c){this.input.value=this.n[a][1];this.hide()}else{document.getElementById(this.t+"_check_"+a).checked=this.n[a][3]=!this.n[a][3];if(this.c&&!this.c(this,a,this.n[a])){return}this.ak(a)}this.al=this.input.value;if(this.d){this.d(this,a,this.n[a])}};SimpleAutocomplete.prototype.ak=function(c){var b=this.input.value.split(this.b);for(var d=0;d=0;d--){if(b[d]==this.n[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.p)}return stopEvent(e,true,true)}else{if(e.keyCode==27){this.hide();return stopEvent(e,true,true)}else{return true}}}}if(this.p>=0){var f=this.aj();var b=this.u;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.ab()}return}while(this.p'+this.f+"":"";this.ac()}if(this.b){var e={};var b=this.input.value.split(this.b);for(var d=0;d=0){var d=this.aj();if(d){d.className=this.n[this.p][2]?"hintDisabledItem":"hintItem"}}this.p=a;b.className="hintActiveItem";return false};SimpleAutocomplete.prototype.aj=function(a){if(a==null){a=this.p}if(a<0){return null}return document.getElementById(this.t+"_item_"+this.p)};SimpleAutocomplete.prototype.selectItem=function(a){if(this.n[a][2]){return false}if(this.h&&this.n[a][1]==this.h){this.n.splice(a,1);elm.parentNode.removeChild(elm);this.k++;this.onChange(true);return}if(!this.b&&!this.c){this.input.value=this.n[a][1];this.hide()}else{document.getElementById(this.t+"_check_"+a).checked=this.n[a][3]=!this.n[a][3];if(this.c&&!this.c(this,a,this.n[a])){return}this.ak(a)}this.al=this.input.value;if(this.d){this.d(this,a,this.n[a])}};SimpleAutocomplete.prototype.ak=function(c){var b=this.input.value.split(this.b);for(var d=0;d=0;d--){if(b[d]==this.n[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.p)}return stopEvent(e,true,true)}else{if(e.keyCode==27){this.hide();return stopEvent(e,true,true)}else{return true}}}}if(this.p>=0){var f=this.aj();var b=this.u;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