|
1 | 1 | /** |
2 | | -* Ajax Autocomplete for jQuery, version 1.2.25 |
| 2 | +* Ajax Autocomplete for jQuery, version 1.2.26 |
3 | 3 | * (c) 2015 Tomas Kirda |
4 | 4 | * |
5 | 5 | * Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license. |
6 | 6 | * For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete |
7 | 7 | */ |
8 | 8 |
|
9 | | -/*jslint browser: true, white: true, plusplus: true, vars: true */ |
| 9 | +/*jslint browser: true, white: true, single: true, this: true, multivar: true */ |
10 | 10 | /*global define, window, document, jQuery, exports, require */ |
11 | 11 |
|
12 | 12 | // Expose plugin as an AMD module if AMD loader is present: |
13 | 13 | (function (factory) { |
14 | | - 'use strict'; |
| 14 | + "use strict"; |
15 | 15 | if (typeof define === 'function' && define.amd) { |
16 | 16 | // AMD. Register as an anonymous module. |
17 | 17 | define(['jquery'], factory); |
|
29 | 29 | utils = (function () { |
30 | 30 | return { |
31 | 31 | escapeRegExChars: function (value) { |
32 | | - return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); |
| 32 | + return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&"); |
33 | 33 | }, |
34 | 34 | createNode: function (containerClass) { |
35 | 35 | var div = document.createElement('div'); |
|
52 | 52 | }; |
53 | 53 |
|
54 | 54 | function Autocomplete(el, options) { |
55 | | - var noop = function () { }, |
| 55 | + var noop = $.noop, |
56 | 56 | that = this, |
57 | 57 | defaults = { |
58 | 58 | ajaxSettings: {}, |
|
158 | 158 | that.element.setAttribute('autocomplete', 'off'); |
159 | 159 |
|
160 | 160 | that.killerFn = function (e) { |
161 | | - if ($(e.target).closest('.' + that.options.containerClass).length === 0) { |
| 161 | + if (!$(e.target).closest('.' + that.options.containerClass).length) { |
162 | 162 | that.killSuggestions(); |
163 | 163 | that.disableKillerFn(); |
164 | 164 | } |
|
354 | 354 | that.stopKillSuggestions(); |
355 | 355 | that.intervalId = window.setInterval(function () { |
356 | 356 | if (that.visible) { |
357 | | - that.el.val(that.currentValue); |
| 357 | + // No need to restore value when |
| 358 | + // preserveInput === true, |
| 359 | + // because we did not change it |
| 360 | + if (!that.options.preserveInput) { |
| 361 | + that.el.val(that.currentValue); |
| 362 | + } |
| 363 | + |
358 | 364 | that.hide(); |
359 | 365 | } |
360 | 366 |
|
|
635 | 641 | }, |
636 | 642 |
|
637 | 643 | suggest: function () { |
638 | | - if (this.suggestions.length === 0) { |
| 644 | + if (!this.suggestions.length) { |
639 | 645 | if (this.options.showNoSuggestionNotice) { |
640 | 646 | this.noSuggestions(); |
641 | 647 | } else { |
|
733 | 739 | // If width is auto, adjust width before displaying suggestions, |
734 | 740 | // because if instance was created before input had width, it will be zero. |
735 | 741 | // Also it adjusts if input width has changed. |
736 | | - // -2px to account for suggestions border. |
737 | 742 | if (options.width === 'auto') { |
738 | 743 | width = that.el.outerWidth(); |
739 | 744 | container.css('width', width > 0 ? width : 300); |
|
803 | 808 | // Cache results if cache is not disabled: |
804 | 809 | if (!options.noCache) { |
805 | 810 | that.cachedResponse[cacheKey] = result; |
806 | | - if (options.preventBadQueries && result.suggestions.length === 0) { |
| 811 | + if (options.preventBadQueries && !result.suggestions.length) { |
807 | 812 | that.badQueries.push(originalQuery); |
808 | 813 | } |
809 | 814 | } |
|
961 | 966 | var dataKey = 'autocomplete'; |
962 | 967 | // If function invoked without argument return |
963 | 968 | // instance of the first matched element: |
964 | | - if (arguments.length === 0) { |
| 969 | + if (!arguments.length) { |
965 | 970 | return this.first().data(dataKey); |
966 | 971 | } |
967 | 972 |
|
|
0 commit comments