diff --git a/hinter.css b/hinter.css index b10046f..d24e878 100644 --- a/hinter.css +++ b/hinter.css @@ -4,8 +4,8 @@ background-color: white; font-size: 80%; max-height: 300pt; - overflow-y: scroll; - overflow: -moz-scrollbars-vertical; + overflow-y: auto; + -ms-overflow-y: auto; z-index: 1000; } .hintEmptyText { diff --git a/hinter.js b/hinter.js index 3a582be..8549bfd 100644 --- a/hinter.js +++ b/hinter.js @@ -77,7 +77,7 @@ var SimpleAutocomplete = function(input, dataLoader, params) // Parameters this.input = input; this.dataLoader = dataLoader; - this.multipleDelimiter = params.multipleDelimiter || params.multipleListener; + this.multipleDelimiter = params.multipleDelimiter; this.multipleListener = params.multipleListener; this.onChangeListener = params.onChangeListener; this.emptyText = params.emptyText; @@ -138,8 +138,7 @@ 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(window, 'beforeunload', function() { e.autocomplete = 'on'; }); addListener(t, 'mousedown', function(ev) { return self.cancelBubbleOnHint(ev); }); this.onChange(); }; @@ -166,7 +165,7 @@ SimpleAutocomplete.prototype.replaceItems = function(items, append) if (!this.multipleListener) for (var i in items) items[i][2] = 0; - if (this.multipleDelimiter && !this.multipleListener) + if (this.multipleDelimiter) { var h = {}; var old = this.input.value.split(this.multipleDelimiter); @@ -195,8 +194,6 @@ 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]); @@ -222,8 +219,7 @@ SimpleAutocomplete.prototype.makeItem = function(index, item) d.id = this.id+'_item_'+index; d.className = item[2] ? 'hintDisabledItem' : (this.selectedIndex == index ? 'hintActiveItem' : 'hintItem'); d.title = item[1]; - d.innerHTML = item[0]; - if (this.multipleDelimiter) + if (this.multipleDelimiter || this.multipleListener) { var c = document.createElement('input'); c.type = 'checkbox'; @@ -231,12 +227,15 @@ SimpleAutocomplete.prototype.makeItem = function(index, item) c.checked = item[3] && true; c.disabled = item[2] && true; c.value = item[1]; - if (d.childNodes.length) - d.insertBefore(c, d.firstChild); - else - d.appendChild(c); + d.appendChild(c); + var l = document.createElement('label'); + l.htmlFor = c.id; + l.innerHTML = item[0]; + d.appendChild(l); addListener(c, 'click', this.preventCheck); } + else + 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); }); @@ -285,7 +284,7 @@ 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.multipleDelimiter) + if (!this.multipleDelimiter && !this.multipleListener) { this.input.value = this.items[index][1]; this.hide(); @@ -293,11 +292,8 @@ SimpleAutocomplete.prototype.selectItem = function(index) else { document.getElementById(this.id+'_check_'+index).checked = this.items[index][3] = !this.items[index][3]; - if (this.multipleListener) - { - this.multipleListener(this, index, this.items[index]); + if (this.multipleListener && !this.multipleListener(this, index, this.items[index])) return; - } this.toggleValue(index); } this.curValue = this.input.value; diff --git a/hinter.min.js b/hinter.min.js index b6a3191..c8f9585 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(window,"beforeunload",this.k.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='