From 56316867753d6e1482b0cab9f2cb42881b5a0332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Arroyo?= Date: Thu, 26 Jan 2017 17:24:55 +0100 Subject: [PATCH 1/3] Fix cache with spaces. Now you can find with multiple words. --- auto-complete.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/auto-complete.js b/auto-complete.js index 2f5a88c..a698752 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(){ @@ -167,10 +168,12 @@ var autoComplete = (function(){ that.last_val = val; clearTimeout(that.timer); if (o.cache) { - if (val in that.cache) { suggest(that.cache[val]); return; } + // Fix by ProtocolNebula for bug with spaces + var cleanVal = name.replace(/[^a-zA-Z0-9]/g, '-'); + if (cleanVal in that.cache) { suggest(that.cache[cleanVal]); return; } // no requests if previous suggestions were empty - for (var i=1; i Date: Fri, 27 Jan 2017 09:43:20 +0100 Subject: [PATCH 2/3] Update auto-complete.js cleanVal had a bad variable name replacement --- auto-complete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto-complete.js b/auto-complete.js index a698752..30bb312 100644 --- a/auto-complete.js +++ b/auto-complete.js @@ -169,7 +169,7 @@ var autoComplete = (function(){ clearTimeout(that.timer); if (o.cache) { // Fix by ProtocolNebula for bug with spaces - var cleanVal = name.replace(/[^a-zA-Z0-9]/g, '-'); + var cleanVal = val.replace(/[^a-zA-Z0-9]/g, '-'); if (cleanVal in that.cache) { suggest(that.cache[cleanVal]); return; } // no requests if previous suggestions were empty for (var i=1; i Date: Mon, 30 Jan 2017 18:01:51 +0100 Subject: [PATCH 3/3] Fix cache issues and fix support for focus event --- auto-complete.js | 36 ++++++++++++++++++++++-------------- auto-complete.min.js | 3 --- 2 files changed, 22 insertions(+), 17 deletions(-) delete mode 100644 auto-complete.min.js diff --git a/auto-complete.js b/auto-complete.js index 30bb312..ebfbe9f 100644 --- a/auto-complete.js +++ b/auto-complete.js @@ -117,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