|
49 | 49 | UP: 38,
|
50 | 50 | RIGHT: 39,
|
51 | 51 | DOWN: 40
|
52 |
| - }; |
| 52 | + }, |
| 53 | + |
| 54 | + noop = $.noop; |
53 | 55 |
|
54 | 56 | function Autocomplete(el, options) {
|
55 |
| - var noop = $.noop, |
56 |
| - that = this, |
57 |
| - defaults = { |
58 |
| - ajaxSettings: {}, |
59 |
| - autoSelectFirst: false, |
60 |
| - appendTo: document.body, |
61 |
| - serviceUrl: null, |
62 |
| - lookup: null, |
63 |
| - onSelect: null, |
64 |
| - width: 'auto', |
65 |
| - minChars: 1, |
66 |
| - maxHeight: 300, |
67 |
| - deferRequestBy: 0, |
68 |
| - params: {}, |
69 |
| - formatResult: Autocomplete.formatResult, |
70 |
| - formatGroup: Autocomplete.formatGroup, |
71 |
| - delimiter: null, |
72 |
| - zIndex: 9999, |
73 |
| - type: 'GET', |
74 |
| - noCache: false, |
75 |
| - onSearchStart: noop, |
76 |
| - onSearchComplete: noop, |
77 |
| - onSearchError: noop, |
78 |
| - preserveInput: false, |
79 |
| - containerClass: 'autocomplete-suggestions', |
80 |
| - tabDisabled: false, |
81 |
| - dataType: 'text', |
82 |
| - currentRequest: null, |
83 |
| - triggerSelectOnValidInput: true, |
84 |
| - preventBadQueries: true, |
85 |
| - lookupFilter: function (suggestion, originalQuery, queryLowerCase) { |
86 |
| - return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1; |
87 |
| - }, |
88 |
| - paramName: 'query', |
89 |
| - transformResult: function (response) { |
90 |
| - return typeof response === 'string' ? $.parseJSON(response) : response; |
91 |
| - }, |
92 |
| - showNoSuggestionNotice: false, |
93 |
| - noSuggestionNotice: 'No results', |
94 |
| - orientation: 'bottom', |
95 |
| - forceFixPosition: false |
96 |
| - }; |
| 57 | + var that = this; |
97 | 58 |
|
98 | 59 | // Shared variables:
|
99 | 60 | that.element = el;
|
|
109 | 70 | that.isLocal = false;
|
110 | 71 | that.suggestionsContainer = null;
|
111 | 72 | that.noSuggestionsContainer = null;
|
112 |
| - that.options = $.extend({}, defaults, options); |
| 73 | + that.options = $.extend({}, Autocomplete.defaults, options); |
113 | 74 | that.classes = {
|
114 | 75 | selected: 'autocomplete-selected',
|
115 | 76 | suggestion: 'autocomplete-suggestion'
|
|
127 | 88 |
|
128 | 89 | $.Autocomplete = Autocomplete;
|
129 | 90 |
|
130 |
| - Autocomplete.formatResult = function (suggestion, currentValue) { |
| 91 | + Autocomplete.defaults = { |
| 92 | + ajaxSettings: {}, |
| 93 | + autoSelectFirst: false, |
| 94 | + appendTo: document.body, |
| 95 | + serviceUrl: null, |
| 96 | + lookup: null, |
| 97 | + onSelect: null, |
| 98 | + width: 'auto', |
| 99 | + minChars: 1, |
| 100 | + maxHeight: 300, |
| 101 | + deferRequestBy: 0, |
| 102 | + params: {}, |
| 103 | + formatResult: _formatResult, |
| 104 | + formatGroup: _formatGroup, |
| 105 | + delimiter: null, |
| 106 | + zIndex: 9999, |
| 107 | + type: 'GET', |
| 108 | + noCache: false, |
| 109 | + onSearchStart: noop, |
| 110 | + onSearchComplete: noop, |
| 111 | + onSearchError: noop, |
| 112 | + preserveInput: false, |
| 113 | + containerClass: 'autocomplete-suggestions', |
| 114 | + tabDisabled: false, |
| 115 | + dataType: 'text', |
| 116 | + currentRequest: null, |
| 117 | + triggerSelectOnValidInput: true, |
| 118 | + preventBadQueries: true, |
| 119 | + lookupFilter: _lookupFilter, |
| 120 | + paramName: 'query', |
| 121 | + transformResult: _transformResult, |
| 122 | + showNoSuggestionNotice: false, |
| 123 | + noSuggestionNotice: 'No results', |
| 124 | + orientation: 'bottom', |
| 125 | + forceFixPosition: false |
| 126 | + }; |
| 127 | + |
| 128 | + function _lookupFilter(suggestion, originalQuery, queryLowerCase) { |
| 129 | + return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1; |
| 130 | + }; |
| 131 | + |
| 132 | + function _transformResult(response) { |
| 133 | + return typeof response === 'string' ? $.parseJSON(response) : response; |
| 134 | + }; |
| 135 | + |
| 136 | + function _formatResult(suggestion, currentValue) { |
131 | 137 | // Do not replace anything if there current value is empty
|
132 | 138 | if (!currentValue) {
|
133 | 139 | return suggestion.value;
|
|
144 | 150 | .replace(/<(\/?strong)>/g, '<$1>');
|
145 | 151 | };
|
146 | 152 |
|
147 |
| - Autocomplete.formatGroup = function (suggestion, category) { |
| 153 | + function _formatGroup(suggestion, category) { |
148 | 154 | return '<div class="autocomplete-group"><strong>' + category + '</strong></div>';
|
149 | 155 | };
|
150 | 156 |
|
|
0 commit comments