From 7eae459e1acabf3e8b8d6e11d67e2c390ec980cb Mon Sep 17 00:00:00 2001 From: Marcio Vicente Date: Thu, 8 Oct 2015 16:56:07 -0300 Subject: [PATCH 1/3] Make this repository as node module --- package.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..30c1f52 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "javascript-autocomplete", + "version": "1.0.0", + "description": "An extremely lightweight and powerful vanilla JavaScript completion suggester.", + "main": "auto-complete.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/jusbrasil/JavaScript-autoComplete.git" + }, + "keywords": [ + "autocomplete", + "vanilla", + "javascript" + ], + "license": "MIT", + "bugs": { + "url": "https://github.com/jusbrasil/JavaScript-autoComplete/issues" + }, + "homepage": "https://github.com/jusbrasil/JavaScript-autoComplete#readme" +} From 196e3622b12c59af5c0e4ad01a63dc34fbf8513c Mon Sep 17 00:00:00 2001 From: Marcio Vicente Date: Tue, 24 Nov 2015 11:55:21 -0300 Subject: [PATCH 2/3] Append autocomplete-suggestions inside autocomplete parent instead body --- auto-complete.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/auto-complete.js b/auto-complete.js index 3cf6dfa..935fe87 100644 --- a/auto-complete.js +++ b/auto-complete.js @@ -63,7 +63,6 @@ var autoComplete = (function(){ that.updateSC = function(resize, next){ var rect = that.getBoundingClientRect(); that.sc.style.left = rect.left + (window.pageXOffset || document.documentElement.scrollLeft) + 'px'; - that.sc.style.top = rect.bottom + (window.pageYOffset || document.documentElement.scrollTop) + 1 + 'px'; that.sc.style.width = rect.right - rect.left + 'px'; // outerWidth if (!resize) { that.sc.style.display = 'block'; @@ -81,7 +80,7 @@ var autoComplete = (function(){ } } addEvent(window, 'resize', that.updateSC); - document.body.appendChild(that.sc); + that.parentElement.appendChild(that.sc); live('autocomplete-suggestion', 'mouseleave', function(e){ var sel = that.sc.querySelector('.autocomplete-suggestion.selected'); @@ -203,7 +202,7 @@ var autoComplete = (function(){ that.setAttribute('autocomplete', that.autocompleteAttr); else that.removeAttribute('autocomplete'); - document.body.removeChild(that.sc); + that.parentElement.removeChild(that.sc); that = null; } }; From febd1bd14b6ae7b1667af9e4e42cccaaca64d9c6 Mon Sep 17 00:00:00 2001 From: Osvaldo Matos-Junior Date: Tue, 12 Jan 2016 13:45:58 -0300 Subject: [PATCH 3/3] Drop response of old requests --- auto-complete.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/auto-complete.js b/auto-complete.js index 935fe87..ab25d7a 100644 --- a/auto-complete.js +++ b/auto-complete.js @@ -5,6 +5,9 @@ License: http://www.opensource.org/licenses/mit-license.php */ + +var requestId = 0; + var autoComplete = (function(){ // "use strict"; function autoComplete(options){ @@ -172,7 +175,17 @@ var autoComplete = (function(){ if (part in that.cache && !that.cache[part].length) { suggest([]); return; } } } - that.timer = setTimeout(function(){ o.source(val, suggest) }, o.delay); + that.timer = setTimeout(function(){ + var thisRequestId = that._currentRequestId = requestId++; + var suggestWrap = function(data) { + // drop response of old requests + if (thisRequestId !== that._currentRequestId) { + return; + } + return suggest(data); + } + o.source(val, suggestWrap); + }, o.delay); } } else { that.last_val = val;