From c17437ff7c63f3cfe9369428b7eca83982c72e41 Mon Sep 17 00:00:00 2001 From: Merten Hanisch Date: Tue, 14 Jun 2016 12:26:25 +0200 Subject: [PATCH 1/4] improve readability in unminified js --- auto-complete.js | 272 +++++++++++++++++++++++++++-------------------- 1 file changed, 157 insertions(+), 115 deletions(-) diff --git a/auto-complete.js b/auto-complete.js index 2f5a88c..edd4c52 100644 --- a/auto-complete.js +++ b/auto-complete.js @@ -1,31 +1,35 @@ /* - JavaScript autoComplete v1.0.4 - Copyright (c) 2014 Simon Steinberger / Pixabay - GitHub: https://github.com/Pixabay/JavaScript-autoComplete - License: http://www.opensource.org/licenses/mit-license.php -*/ + JavaScript autoComplete v1.0.4 + Copyright (c) 2014 Simon Steinberger / Pixabay + GitHub: https://github.com/Pixabay/JavaScript-autoComplete + License: http://www.opensource.org/licenses/mit-license.php + */ -var autoComplete = (function(){ +var autoComplete = (function() { // "use strict"; - function autoComplete(options){ - if (!document.querySelector) return; + function autoComplete( options ) { + if ( !document.querySelector ) return; // helpers - function hasClass(el, className){ return el.classList ? el.classList.contains(className) : new RegExp('\\b'+ className+'\\b').test(el.className); } + function hasClass( el, className ) { + return el.classList ? el.classList.contains( className ) : new RegExp( '\\b' + className + '\\b' ).test( el.className ); + } - function addEvent(el, type, handler){ - if (el.attachEvent) el.attachEvent('on'+type, handler); else el.addEventListener(type, handler); + function addEvent( el, type, handler ) { + if ( el.attachEvent ) el.attachEvent( 'on' + type, handler ); else el.addEventListener( type, handler ); } - function removeEvent(el, type, handler){ + + function removeEvent( el, type, handler ) { // if (el.removeEventListener) not working in IE11 - if (el.detachEvent) el.detachEvent('on'+type, handler); else el.removeEventListener(type, handler); + if ( el.detachEvent ) el.detachEvent( 'on' + type, handler ); else el.removeEventListener( type, handler ); } - function live(elClass, event, cb, context){ - addEvent(context || document, event, function(e){ + + function live( elClass, event, cb, context ) { + addEvent( context || document, event, function( e ) { var found, el = e.target || e.srcElement; - while (el && !(found = hasClass(el, elClass))) el = el.parentElement; - if (found) cb.call(el, e); - }); + while ( el && !(found = hasClass( el, elClass )) ) el = el.parentElement; + if ( found ) cb.call( el, e ); + } ); } var o = { @@ -37,144 +41,179 @@ var autoComplete = (function(){ offsetTop: 1, cache: 1, menuClass: '', - renderItem: function (item, search){ + renderItem: function( item, search ) { // escape special characters - search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); - var re = new RegExp("(" + search.split(' ').join('|') + ")", "gi"); - return '
' + item.replace(re, "$1") + '
'; + search = search.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' ); + var re = new RegExp( "(" + search.split( ' ' ).join( '|' ) + ")", "gi" ); + return '
' + item.replace( re, "$1" ) + '
'; }, - onSelect: function(e, term, item){} + onSelect: function( e, term, item ) { + } }; - for (var k in options) { if (options.hasOwnProperty(k)) o[k] = options[k]; } + for ( var k in options ) { + if ( options.hasOwnProperty( k ) ) o[ k ] = options[ k ]; + } // init - var elems = typeof o.selector == 'object' ? [o.selector] : document.querySelectorAll(o.selector); - for (var i=0; i 0) + if ( selTop + that.sc.suggestionHeight - that.sc.maxHeight > 0 ) that.sc.scrollTop = selTop + that.sc.suggestionHeight + scrTop - that.sc.maxHeight; - else if (selTop < 0) + else if ( selTop < 0 ) that.sc.scrollTop = selTop + scrTop; } } } - addEvent(window, 'resize', that.updateSC); - document.body.appendChild(that.sc); + addEvent( window, 'resize', that.updateSC ); + document.body.appendChild( that.sc ); - live('autocomplete-suggestion', 'mouseleave', function(e){ - var sel = that.sc.querySelector('.autocomplete-suggestion.selected'); - if (sel) setTimeout(function(){ sel.className = sel.className.replace('selected', ''); }, 20); - }, that.sc); + live( 'autocomplete-suggestion', 'mouseleave', function( e ) { + var sel = that.sc.querySelector( '.autocomplete-suggestion.selected' ); + if ( sel ) setTimeout( function() { + sel.className = sel.className.replace( 'selected', '' ); + }, 20 ); + }, that.sc ); - live('autocomplete-suggestion', 'mouseover', function(e){ - var sel = that.sc.querySelector('.autocomplete-suggestion.selected'); - if (sel) sel.className = sel.className.replace('selected', ''); + live( 'autocomplete-suggestion', 'mouseover', function( e ) { + var sel = that.sc.querySelector( '.autocomplete-suggestion.selected' ); + if ( sel ) sel.className = sel.className.replace( 'selected', '' ); this.className += ' selected'; - }, that.sc); + }, that.sc ); - live('autocomplete-suggestion', 'mousedown', function(e){ - if (hasClass(this, 'autocomplete-suggestion')) { // else outside click - var v = this.getAttribute('data-val'); + live( 'autocomplete-suggestion', 'mousedown', function( e ) { + if ( hasClass( this, 'autocomplete-suggestion' ) ) { // else outside click + var v = this.getAttribute( 'data-val' ); that.value = v; - o.onSelect(e, v, this); + o.onSelect( e, v, this ); that.sc.style.display = 'none'; } - }, that.sc); + }, that.sc ); - that.blurHandler = function(){ - try { var over_sb = document.querySelector('.autocomplete-suggestions:hover'); } catch(e){ var over_sb = 0; } - if (!over_sb) { + that.blurHandler = function() { + try { + var over_sb = document.querySelector( '.autocomplete-suggestions:hover' ); + } catch ( e ) { + var over_sb = 0; + } + if ( !over_sb ) { that.last_val = that.value; that.sc.style.display = 'none'; - setTimeout(function(){ that.sc.style.display = 'none'; }, 350); // hide suggestions on fast input - } else if (that !== document.activeElement) setTimeout(function(){ that.focus(); }, 20); + setTimeout( function() { + that.sc.style.display = 'none'; + }, 350 ); // hide suggestions on fast input + } else if ( that !== document.activeElement ) setTimeout( function() { + that.focus(); + }, 20 ); }; - addEvent(that, 'blur', that.blurHandler); + addEvent( that, 'blur', that.blurHandler ); - var suggest = function(data){ + var suggest = function( data ) { var val = that.value; - that.cache[val] = data; - if (data.length && val.length >= o.minChars) { + that.cache[ val ] = data; + if ( data.length && val.length >= o.minChars ) { var s = ''; - for (var i=0;i 40) && key != 13 && key != 27) { + if ( !key || (key < 35 || key > 40) && key != 13 && key != 27 ) { var val = that.value; - if (val.length >= o.minChars) { - if (val != that.last_val) { + if ( val.length >= o.minChars ) { + if ( val != that.last_val ) { that.last_val = val; - clearTimeout(that.timer); - if (o.cache) { - if (val in that.cache) { suggest(that.cache[val]); return; } + clearTimeout( that.timer ); + if ( o.cache ) { + if ( val in that.cache ) { + suggest( that.cache[ val ] ); + return; + } // no requests if previous suggestions were empty - for (var i=1; i Date: Tue, 14 Jun 2016 13:12:15 +0200 Subject: [PATCH 2/4] fix multiple closure accessabilities and missing semicolons there are still some closure problems, specificly in the suggest func --- auto-complete.js | 310 ++++++++++++++++++++++++----------------------- 1 file changed, 157 insertions(+), 153 deletions(-) diff --git a/auto-complete.js b/auto-complete.js index edd4c52..f3f2eb0 100644 --- a/auto-complete.js +++ b/auto-complete.js @@ -7,32 +7,32 @@ var autoComplete = (function() { // "use strict"; - function autoComplete( options ) { - if ( !document.querySelector ) return; + function autoComplete(options) { + if (!document.querySelector) return; // helpers - function hasClass( el, className ) { - return el.classList ? el.classList.contains( className ) : new RegExp( '\\b' + className + '\\b' ).test( el.className ); + function hasClass(el, className) { + return el.classList ? el.classList.contains(className) : new RegExp('\\b' + className + '\\b').test(el.className); } - function addEvent( el, type, handler ) { - if ( el.attachEvent ) el.attachEvent( 'on' + type, handler ); else el.addEventListener( type, handler ); + function addEvent(el, type, handler) { + if (el.attachEvent) el.attachEvent('on' + type, handler); else el.addEventListener(type, handler); } - function removeEvent( el, type, handler ) { + function removeEvent(el, type, handler) { // if (el.removeEventListener) not working in IE11 - if ( el.detachEvent ) el.detachEvent( 'on' + type, handler ); else el.removeEventListener( type, handler ); + if (el.detachEvent) el.detachEvent('on' + type, handler); else el.removeEventListener(type, handler); } - function live( elClass, event, cb, context ) { - addEvent( context || document, event, function( e ) { + function live(elClass, event, cb, context) { + addEvent(context || document, event, function(e) { var found, el = e.target || e.srcElement; - while ( el && !(found = hasClass( el, elClass )) ) el = el.parentElement; - if ( found ) cb.call( el, e ); - } ); + while (el && !(found = hasClass(el, elClass))) el = el.parentElement; + if (found) cb.call(el, e); + }); } - var o = { + var defaultOptions = { selector: 0, source: 0, minChars: 3, @@ -41,209 +41,213 @@ var autoComplete = (function() { offsetTop: 1, cache: 1, menuClass: '', - renderItem: function( item, search ) { + renderItem: function(item, search) { // escape special characters - search = search.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' ); - var re = new RegExp( "(" + search.split( ' ' ).join( '|' ) + ")", "gi" ); - return '
' + item.replace( re, "$1" ) + '
'; + search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + var re = new RegExp("(" + search.split(' ').join('|') + ")", "gi"); + return '
' + item.replace(re, "$1") + '
'; }, - onSelect: function( e, term, item ) { + onSelect: function(e, term, item) { } }; - for ( var k in options ) { - if ( options.hasOwnProperty( k ) ) o[ k ] = options[ k ]; + for (var option in options) { + if (options.hasOwnProperty(option)) defaultOptions[option] = options[option]; } // init - var elems = typeof o.selector == 'object' ? [ o.selector ] : document.querySelectorAll( o.selector ); - for ( var i = 0; i < elems.length; i++ ) { - var that = elems[ i ]; + var elems = typeof defaultOptions.selector == 'object' ? [defaultOptions.selector] : document.querySelectorAll(defaultOptions.selector); + for (var i = 0; i < elems.length; i++) { + var elem = elems[i]; - // create suggestions container "sc" - that.sc = document.createElement( 'div' ); - that.sc.className = 'autocomplete-suggestions ' + o.menuClass; + // create suggestions container + elem.suggestionsContainer = document.createElement('div'); + elem.suggestionsContainer.className = 'autocomplete-suggestions ' + defaultOptions.menuClass; - that.autocompleteAttr = that.getAttribute( 'autocomplete' ); - that.setAttribute( 'autocomplete', 'off' ); - that.cache = {}; - that.last_val = ''; + elem.autocompleteAttr = elem.getAttribute('autocomplete'); + elem.setAttribute('autocomplete', 'off'); + elem.cache = {}; + elem.last_val = ''; - that.updateSC = function( resize, next ) { - var rect = that.getBoundingClientRect(); - that.sc.style.left = Math.round( rect.left + (window.pageXOffset || document.documentElement.scrollLeft) + o.offsetLeft ) + 'px'; - that.sc.style.top = Math.round( rect.bottom + (window.pageYOffset || document.documentElement.scrollTop) + o.offsetTop ) + 'px'; - that.sc.style.width = Math.round( rect.right - rect.left ) + 'px'; // outerWidth - if ( !resize ) { - that.sc.style.display = 'block'; - if ( !that.sc.maxHeight ) { - that.sc.maxHeight = parseInt( (window.getComputedStyle ? getComputedStyle( that.sc, null ) : that.sc.currentStyle).maxHeight ); + elem.updateSuggestionsContainer = function(resize, next) { + var rect = this.getBoundingClientRect(); + this.suggestionsContainer.style.left = Math.round(rect.left + (window.pageXOffset || document.documentElement.scrollLeft) + defaultOptions.offsetLeft) + 'px'; + this.suggestionsContainer.style.top = Math.round(rect.bottom + (window.pageYOffset || document.documentElement.scrollTop) + defaultOptions.offsetTop) + 'px'; + this.suggestionsContainer.style.width = Math.round(rect.right - rect.left) + 'px'; // outerWidth + if (!resize) { + this.suggestionsContainer.style.display = 'block'; + if (!this.suggestionsContainer.maxHeight) { + this.suggestionsContainer.maxHeight = parseInt((window.getComputedStyle ? getComputedStyle(this.suggestionsContainer, null) : this.suggestionsContainer.currentStyle).maxHeight); } - if ( !that.sc.suggestionHeight ) that.sc.suggestionHeight = that.sc.querySelector( '.autocomplete-suggestion' ).offsetHeight; - if ( that.sc.suggestionHeight ) - if ( !next ) that.sc.scrollTop = 0; + if (!this.suggestionsContainer.suggestionHeight) this.suggestionsContainer.suggestionHeight = this.suggestionsContainer.querySelector('.autocomplete-suggestion').offsetHeight; + if (this.suggestionsContainer.suggestionHeight) + if (!next) this.suggestionsContainer.scrollTop = 0; else { - var scrTop = that.sc.scrollTop, selTop = next.getBoundingClientRect().top - that.sc.getBoundingClientRect().top; - if ( selTop + that.sc.suggestionHeight - that.sc.maxHeight > 0 ) - that.sc.scrollTop = selTop + that.sc.suggestionHeight + scrTop - that.sc.maxHeight; - else if ( selTop < 0 ) - that.sc.scrollTop = selTop + scrTop; + var scrTop = this.suggestionsContainer.scrollTop, selTop = next.getBoundingClientRect().top - this.suggestionsContainer.getBoundingClientRect().top; + if (selTop + this.suggestionsContainer.suggestionHeight - this.suggestionsContainer.maxHeight > 0) + this.suggestionsContainer.scrollTop = selTop + this.suggestionsContainer.suggestionHeight + scrTop - this.suggestionsContainer.maxHeight; + else if (selTop < 0) + this.suggestionsContainer.scrollTop = selTop + scrTop; } } - } - addEvent( window, 'resize', that.updateSC ); - document.body.appendChild( that.sc ); + }; + addEvent(window, 'resize', elem.updateSuggestionsContainer); + document.body.appendChild(elem.suggestionsContainer); - live( 'autocomplete-suggestion', 'mouseleave', function( e ) { - var sel = that.sc.querySelector( '.autocomplete-suggestion.selected' ); - if ( sel ) setTimeout( function() { - sel.className = sel.className.replace( 'selected', '' ); - }, 20 ); - }, that.sc ); + live('autocomplete-suggestion', 'mouseleave', function() { + var sel = elem.suggestionsContainer.querySelector('.autocomplete-suggestion.selected'); + if (sel) setTimeout(function() { + sel.className = sel.className.replace('selected', ''); + }, 20); + }, elem.suggestionsContainer); - live( 'autocomplete-suggestion', 'mouseover', function( e ) { - var sel = that.sc.querySelector( '.autocomplete-suggestion.selected' ); - if ( sel ) sel.className = sel.className.replace( 'selected', '' ); + live('autocomplete-suggestion', 'mouseover', function() { + var sel = elem.suggestionsContainer.querySelector('.autocomplete-suggestion.selected'); + if (sel) sel.className = sel.className.replace('selected', ''); this.className += ' selected'; - }, that.sc ); + }, elem.suggestionsContainer); - live( 'autocomplete-suggestion', 'mousedown', function( e ) { - if ( hasClass( this, 'autocomplete-suggestion' ) ) { // else outside click - var v = this.getAttribute( 'data-val' ); - that.value = v; - o.onSelect( e, v, this ); - that.sc.style.display = 'none'; + live('autocomplete-suggestion', 'mousedown', function(e) { + if (hasClass(this, 'autocomplete-suggestion')) { // else outside click + var v = this.getAttribute('data-val'); + elem.value = v; + defaultOptions.onSelect(e, v, this); + elem.suggestionsContainer.style.display = 'none'; } - }, that.sc ); + }, elem.suggestionsContainer); - that.blurHandler = function() { + elem.blurHandler = function() { + var that = this; try { - var over_sb = document.querySelector( '.autocomplete-suggestions:hover' ); - } catch ( e ) { + var over_sb = document.querySelector('.autocomplete-suggestions:hover'); + } catch (e) { var over_sb = 0; } - if ( !over_sb ) { - that.last_val = that.value; - that.sc.style.display = 'none'; - setTimeout( function() { - that.sc.style.display = 'none'; - }, 350 ); // hide suggestions on fast input - } else if ( that !== document.activeElement ) setTimeout( function() { - that.focus(); - }, 20 ); + if (!over_sb) { + this.last_val = this.value; + this.suggestionsContainer.style.display = 'none'; + setTimeout(function() { + that.suggestionsContainer.style.display = 'none'; + }, 350); // hide suggestions on fast input + } else if (this !== document.activeElement) setTimeout(function() { + this.focus(); + }, 20); }; - addEvent( that, 'blur', that.blurHandler ); + addEvent(elem, 'blur', elem.blurHandler); - var suggest = function( data ) { - var val = that.value; - that.cache[ val ] = data; - if ( data.length && val.length >= o.minChars ) { + var suggest = function(data) { + var val = elem.value; + elem.cache[val] = data; + if (data.length && val.length >= defaultOptions.minChars) { var s = ''; - for ( var i = 0; i < data.length; i++ ) s += o.renderItem( data[ i ], val ); - that.sc.innerHTML = s; - that.updateSC( 0 ); + for (var i = 0; i < data.length; i++) s += defaultOptions.renderItem(data[i], val); + elem.suggestionsContainer.innerHTML = s; + elem.updateSuggestionsContainer(0); } else - that.sc.style.display = 'none'; - } + elem.suggestionsContainer.style.display = 'none'; + }; - that.keydownHandler = function( e ) { - var key = window.event ? e.keyCode : e.which; + elem.keydownHandler = function(e) { + var sel, + that = this, + key = window.event ? e.keyCode : e.which; // down (40), up (38) - if ( (key == 40 || key == 38) && that.sc.innerHTML ) { - var next, sel = that.sc.querySelector( '.autocomplete-suggestion.selected' ); - if ( !sel ) { - next = (key == 40) ? that.sc.querySelector( '.autocomplete-suggestion' ) : that.sc.childNodes[ that.sc.childNodes.length - 1 ]; // first : last + if ((key == 40 || key == 38) && this.suggestionsContainer.innerHTML) { + var next; + sel = this.suggestionsContainer.querySelector('.autocomplete-suggestion.selected'); + if (!sel) { + next = (key == 40) ? this.suggestionsContainer.querySelector('.autocomplete-suggestion') : this.suggestionsContainer.childNodes[this.suggestionsContainer.childNodes.length - 1]; // first : last next.className += ' selected'; - that.value = next.getAttribute( 'data-val' ); + this.value = next.getAttribute('data-val'); } else { next = (key == 40) ? sel.nextSibling : sel.previousSibling; - if ( next ) { - sel.className = sel.className.replace( 'selected', '' ); + if (next) { + sel.className = sel.className.replace('selected', ''); next.className += ' selected'; - that.value = next.getAttribute( 'data-val' ); + this.value = next.getAttribute('data-val'); } else { - sel.className = sel.className.replace( 'selected', '' ); - that.value = that.last_val; + sel.className = sel.className.replace('selected', ''); + this.value = this.last_val; next = 0; } } - that.updateSC( 0, next ); + this.updateSuggestionsContainer(0, next); return false; } // esc - else if ( key == 27 ) { - that.value = that.last_val; - that.sc.style.display = 'none'; + else if (key == 27) { + this.value = this.last_val; + this.suggestionsContainer.style.display = 'none'; } // enter - else if ( key == 13 || key == 9 ) { - var sel = that.sc.querySelector( '.autocomplete-suggestion.selected' ); - if ( sel && that.sc.style.display != 'none' ) { - o.onSelect( e, sel.getAttribute( 'data-val' ), sel ); - setTimeout( function() { - that.sc.style.display = 'none'; - }, 20 ); + else if (key == 13 || key == 9) { + sel = this.suggestionsContainer.querySelector('.autocomplete-suggestion.selected'); + if (sel && this.suggestionsContainer.style.display != 'none') { + defaultOptions.onSelect(e, sel.getAttribute('data-val'), sel); + setTimeout(function() { + that.suggestionsContainer.style.display = 'none'; + }, 20); } } }; - addEvent( that, 'keydown', that.keydownHandler ); + addEvent(elem, 'keydown', elem.keydownHandler); - that.keyupHandler = function( e ) { + elem.keyupHandler = function(e) { var key = window.event ? e.keyCode : e.which; - if ( !key || (key < 35 || key > 40) && key != 13 && key != 27 ) { - var val = that.value; - if ( val.length >= o.minChars ) { - if ( val != that.last_val ) { - that.last_val = val; - clearTimeout( that.timer ); - if ( o.cache ) { - if ( val in that.cache ) { - suggest( that.cache[ val ] ); + if (!key || (key < 35 || key > 40) && key != 13 && key != 27) { + var val = this.value; + if (val.length >= defaultOptions.minChars) { + if (val != this.last_val) { + this.last_val = val; + clearTimeout(this.timer); + if (defaultOptions.cache) { + if (val in this.cache) { + suggest(this.cache[val]); return; } // no requests if previous suggestions were empty - for ( var i = 1; i < val.length - o.minChars; i++ ) { - var part = val.slice( 0, val.length - i ); - if ( part in that.cache && !that.cache[ part ].length ) { - suggest( [] ); + for (var i = 1; i < val.length - defaultOptions.minChars; i++) { + var part = val.slice(0, val.length - i); + if (part in this.cache && !this.cache[part].length) { + suggest([]); return; } } } - that.timer = setTimeout( function() { - o.source( val, suggest ) - }, o.delay ); + this.timer = setTimeout(function() { + defaultOptions.source(val, suggest) + }, defaultOptions.delay); } } else { - that.last_val = val; - that.sc.style.display = 'none'; + this.last_val = val; + this.suggestionsContainer.style.display = 'none'; } } }; - addEvent( that, 'keyup', that.keyupHandler ); + addEvent(elem, 'keyup', elem.keyupHandler); - that.focusHandler = function( e ) { - that.last_val = '\n'; - that.keyupHandler( e ) + elem.focusHandler = function(e) { + this.last_val = '\n'; + this.keyupHandler(e) }; - if ( !o.minChars ) addEvent( that, 'focus', that.focusHandler ); + if (!defaultOptions.minChars) addEvent(elem, 'focus', elem.focusHandler); } // public destroy method this.destroy = function() { - for ( var i = 0; i < elems.length; i++ ) { - var that = elems[ i ]; - removeEvent( window, 'resize', that.updateSC ); - removeEvent( that, 'blur', that.blurHandler ); - removeEvent( that, 'focus', that.focusHandler ); - removeEvent( that, 'keydown', that.keydownHandler ); - removeEvent( that, 'keyup', that.keyupHandler ); - if ( that.autocompleteAttr ) - that.setAttribute( 'autocomplete', that.autocompleteAttr ); + for (var i = 0; i < elems.length; i++) { + var that = elems[i]; + removeEvent(window, 'resize', that.updateSuggestionsContainer); + removeEvent(that, 'blur', that.blurHandler); + removeEvent(that, 'focus', that.focusHandler); + removeEvent(that, 'keydown', that.keydownHandler); + removeEvent(that, 'keyup', that.keyupHandler); + if (that.autocompleteAttr) + that.setAttribute('autocomplete', that.autocompleteAttr); else - that.removeAttribute( 'autocomplete' ); - document.body.removeChild( that.sc ); + that.removeAttribute('autocomplete'); + document.body.removeChild(that.suggestionsContainer); that = null; } }; @@ -253,11 +257,11 @@ var autoComplete = (function() { })(); (function() { - if ( typeof define === 'function' && define.amd ) - define( 'autoComplete', function() { + if (typeof define === 'function' && define.amd) + define('autoComplete', function() { return autoComplete; - } ); - else if ( typeof module !== 'undefined' && module.exports ) + }); + else if (typeof module !== 'undefined' && module.exports) module.exports = autoComplete; else window.autoComplete = autoComplete; From 4ccaf3f80443d49443baf799fca4e1fc99e9d9ce Mon Sep 17 00:00:00 2001 From: Merten Hanisch Date: Tue, 14 Jun 2016 13:21:25 +0200 Subject: [PATCH 3/4] fix duplicate declaration --- auto-complete.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/auto-complete.js b/auto-complete.js index f3f2eb0..0331ba6 100644 --- a/auto-complete.js +++ b/auto-complete.js @@ -116,11 +116,12 @@ var autoComplete = (function() { }, elem.suggestionsContainer); elem.blurHandler = function() { - var that = this; + var that = this, + over_sb; try { - var over_sb = document.querySelector('.autocomplete-suggestions:hover'); + over_sb = document.querySelector('.autocomplete-suggestions:hover'); } catch (e) { - var over_sb = 0; + over_sb = 0; } if (!over_sb) { this.last_val = this.value; From 008adf532f179f742ae745d5556acbf3e877dd40 Mon Sep 17 00:00:00 2001 From: Merten Hanisch Date: Tue, 14 Jun 2016 13:23:51 +0200 Subject: [PATCH 4/4] add special character term to suggestions for testing purposes and because Plankalkuel is awesome --- demo.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo.html b/demo.html index ab7b1a2..c6e4f0a 100644 --- a/demo.html +++ b/demo.html @@ -271,7 +271,7 @@

Advanced suggestions handling and custom layout

minChars: 1, source: function(term, suggest){ term = term.toLowerCase(); - var choices = ['ActionScript', 'AppleScript', 'Asp', 'Assembly', 'BASIC', 'Batch', 'C', 'C++', 'CSS', 'Clojure', 'COBOL', 'ColdFusion', 'Erlang', 'Fortran', 'Groovy', 'Haskell', 'HTML', 'Java', 'JavaScript', 'Lisp', 'Perl', 'PHP', 'PowerShell', 'Python', 'Ruby', 'Scala', 'Scheme', 'SQL', 'TeX', 'XML']; + var choices = ['ActionScript', 'AppleScript', 'Asp', 'Assembly', 'BASIC', 'Batch', 'C', 'C++', 'CSS', 'Clojure', 'COBOL', 'ColdFusion', 'Erlang', 'Fortran', 'Groovy', 'Haskell', 'HTML', 'Java', 'JavaScript', 'Plankalkül', 'Lisp', 'Perl', 'PHP', 'PowerShell', 'Python', 'Ruby', 'Scala', 'Scheme', 'SQL', 'TeX', 'XML']; var suggestions = []; for (i=0;i