From 8cc7be8b6397976c67d8ab68df31814af6622ae1 Mon Sep 17 00:00:00 2001 From: disfated Date: Mon, 6 Apr 2015 17:55:07 +0500 Subject: [PATCH 1/2] Let defaults override --- src/jquery.autocomplete.js | 83 +++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index b6f9f7d5..d69e50a4 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -53,46 +53,7 @@ function Autocomplete(el, options) { var noop = function () { }, - that = this, - defaults = { - ajaxSettings: {}, - autoSelectFirst: false, - appendTo: document.body, - serviceUrl: null, - lookup: null, - onSelect: null, - width: 'auto', - minChars: 1, - maxHeight: 300, - deferRequestBy: 0, - params: {}, - formatResult: Autocomplete.formatResult, - delimiter: null, - zIndex: 9999, - type: 'GET', - noCache: false, - onSearchStart: noop, - onSearchComplete: noop, - onSearchError: noop, - preserveInput: false, - containerClass: 'autocomplete-suggestions', - tabDisabled: false, - dataType: 'text', - currentRequest: null, - triggerSelectOnValidInput: true, - preventBadQueries: true, - lookupFilter: function (suggestion, originalQuery, queryLowerCase) { - return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1; - }, - paramName: 'query', - transformResult: function (response) { - return typeof response === 'string' ? $.parseJSON(response) : response; - }, - showNoSuggestionNotice: false, - noSuggestionNotice: 'No results', - orientation: 'bottom', - forceFixPosition: false - }; + that = this; // Shared variables: that.element = el; @@ -108,7 +69,7 @@ that.isLocal = false; that.suggestionsContainer = null; that.noSuggestionsContainer = null; - that.options = $.extend({}, defaults, options); + that.options = $.extend({}, Autocomplete.defaults, options); that.classes = { selected: 'autocomplete-selected', suggestion: 'autocomplete-suggestion' @@ -138,6 +99,46 @@ return htmlSafeString.replace(new RegExp(pattern, 'gi'), '$1<\/strong>'); }; + Autocomplete.defaults = { + ajaxSettings: {}, + autoSelectFirst: false, + appendTo: document.body, + serviceUrl: null, + lookup: null, + onSelect: null, + width: 'auto', + minChars: 1, + maxHeight: 300, + deferRequestBy: 0, + params: {}, + formatResult: Autocomplete.formatResult, + delimiter: null, + zIndex: 9999, + type: 'GET', + noCache: false, + onSearchStart: noop, + onSearchComplete: noop, + onSearchError: noop, + preserveInput: false, + containerClass: 'autocomplete-suggestions', + tabDisabled: false, + dataType: 'text', + currentRequest: null, + triggerSelectOnValidInput: true, + preventBadQueries: true, + lookupFilter: function (suggestion, originalQuery, queryLowerCase) { + return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1; + }, + paramName: 'query', + transformResult: function (response) { + return typeof response === 'string' ? $.parseJSON(response) : response; + }, + showNoSuggestionNotice: false, + noSuggestionNotice: 'No results', + orientation: 'bottom', + forceFixPosition: false + }; + Autocomplete.prototype = { killerFn: null, From 8db1dd9f16d5030b620cca9def4e58c891583087 Mon Sep 17 00:00:00 2001 From: disfated Date: Mon, 6 Apr 2015 18:22:06 +0500 Subject: [PATCH 2/2] Update jquery.autocomplete.js --- src/jquery.autocomplete.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index d69e50a4..3440af48 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -52,8 +52,7 @@ }; function Autocomplete(el, options) { - var noop = function () { }, - that = this; + var that = this; // Shared variables: that.element = el; @@ -102,7 +101,7 @@ Autocomplete.defaults = { ajaxSettings: {}, autoSelectFirst: false, - appendTo: document.body, + appendTo: 'body', serviceUrl: null, lookup: null, onSelect: null, @@ -116,9 +115,9 @@ zIndex: 9999, type: 'GET', noCache: false, - onSearchStart: noop, - onSearchComplete: noop, - onSearchError: noop, + onSearchStart: $.noop, + onSearchComplete: $.noop, + onSearchError: $.noop, preserveInput: false, containerClass: 'autocomplete-suggestions', tabDisabled: false, @@ -168,7 +167,7 @@ container = $(that.suggestionsContainer); - container.appendTo(options.appendTo); + container.appendTo($(options.appendTo)); // Only set width if it was provided: if (options.width !== 'auto') {