diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index b6f9f7d5..3440af48 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -52,47 +52,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 - }; + var that = this; // Shared variables: that.element = el; @@ -108,7 +68,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 +98,46 @@ return htmlSafeString.replace(new RegExp(pattern, 'gi'), '$1<\/strong>'); }; + Autocomplete.defaults = { + ajaxSettings: {}, + autoSelectFirst: false, + appendTo: '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, @@ -167,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') {