diff --git a/auto-complete.js b/auto-complete.js index 2f5a88c..ebfbe9f 100644 --- a/auto-complete.js +++ b/auto-complete.js @@ -3,6 +3,7 @@ Copyright (c) 2014 Simon Steinberger / Pixabay GitHub: https://github.com/Pixabay/JavaScript-autoComplete License: http://www.opensource.org/licenses/mit-license.php + Fixed by: https://github.com/ProtocolNebula */ var autoComplete = (function(){ @@ -116,7 +117,8 @@ var autoComplete = (function(){ var suggest = function(data){ var val = that.value; - that.cache[val] = data; + var cleanVal = that.getClean(val); + that.cache[cleanVal] = data; if (data.length && val.length >= o.minChars) { var s = ''; for (var i=0;i 40) && key != 13 && key != 27) { var val = that.value; if (val.length >= o.minChars) { + if (o.cache) { + // Fix by ProtocolNebula for bug with spaces + var cleanVal = that.getClean(val); + if (cleanVal in that.cache) { suggest(that.cache[cleanVal]); return; } + // no requests if previous suggestions were empty + for (var i=1; i'+e.replace(o,"$1")+""},onSelect:function(){}};for(var c in e)e.hasOwnProperty(c)&&(l[c]=e[c]);for(var a="object"==typeof l.selector?[l.selector]:document.querySelectorAll(l.selector),u=0;u0?i.sc.scrollTop=n+i.sc.suggestionHeight+s-i.sc.maxHeight:0>n&&(i.sc.scrollTop=n+s)}else i.sc.scrollTop=0},o(window,"resize",i.updateSC),document.body.appendChild(i.sc),n("autocomplete-suggestion","mouseleave",function(){var e=i.sc.querySelector(".autocomplete-suggestion.selected");e&&setTimeout(function(){e.className=e.className.replace("selected","")},20)},i.sc),n("autocomplete-suggestion","mouseover",function(){var e=i.sc.querySelector(".autocomplete-suggestion.selected");e&&(e.className=e.className.replace("selected","")),this.className+=" selected"},i.sc),n("autocomplete-suggestion","mousedown",function(e){if(t(this,"autocomplete-suggestion")){var o=this.getAttribute("data-val");i.value=o,l.onSelect(e,o,this),i.sc.style.display="none"}},i.sc),i.blurHandler=function(){try{var e=document.querySelector(".autocomplete-suggestions:hover")}catch(t){var e=0}e?i!==document.activeElement&&setTimeout(function(){i.focus()},20):(i.last_val=i.value,i.sc.style.display="none",setTimeout(function(){i.sc.style.display="none"},350))},o(i,"blur",i.blurHandler);var r=function(e){var t=i.value;if(i.cache[t]=e,e.length&&t.length>=l.minChars){for(var o="",s=0;st||t>40)&&13!=t&&27!=t){var o=i.value;if(o.length>=l.minChars){if(o!=i.last_val){if(i.last_val=o,clearTimeout(i.timer),l.cache){if(o in i.cache)return void r(i.cache[o]);for(var s=1;s