mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-29 08:14:06 +00:00
Merge branch 'master' into ShowSuggestionAndOrCategoryOnHover
This commit is contained in:
commit
920b8193d2
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "devbridge-autocomplete",
|
"name": "devbridge-autocomplete",
|
||||||
"version": "1.2.25",
|
"version": "1.2.27",
|
||||||
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
|
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Tomas Kirda"
|
"Tomas Kirda"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
body { font-family: sans-serif; font-size: 14px; line-height: 1.6em; margin: 0; padding: 0; }
|
body { font-family: sans-serif; font-size: 14px; line-height: 1.6em; margin: 0; padding: 0; }
|
||||||
.container { width: 800px; margin: 0 auto; }
|
.container { width: 800px; margin: 0 auto; }
|
||||||
|
|
||||||
.autocomplete-suggestions { border: 1px solid #999; background: #FFF; cursor: default; overflow: auto; -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); }
|
.autocomplete-suggestions { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; border: 1px solid #999; background: #FFF; cursor: default; overflow: auto; -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64); }
|
||||||
.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
|
.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
|
||||||
.autocomplete-no-suggestion { padding: 2px 5px;}
|
.autocomplete-no-suggestion { padding: 2px 5px;}
|
||||||
.autocomplete-selected { background: #F0F0F0; }
|
.autocomplete-selected { background: #F0F0F0; }
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
"ajax",
|
"ajax",
|
||||||
"autocomplete"
|
"autocomplete"
|
||||||
],
|
],
|
||||||
"version": "1.2.25",
|
"version": "1.2.27",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Tomas Kirda",
|
"name": "Tomas Kirda",
|
||||||
"url": "https://github.com/tkirda"
|
"url": "https://github.com/tkirda"
|
||||||
|
37
dist/jquery.autocomplete.js
vendored
37
dist/jquery.autocomplete.js
vendored
@ -1,17 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Ajax Autocomplete for jQuery, version 1.2.25
|
* Ajax Autocomplete for jQuery, version 1.2.27
|
||||||
* (c) 2015 Tomas Kirda
|
* (c) 2015 Tomas Kirda
|
||||||
*
|
*
|
||||||
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
|
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
|
||||||
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
|
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*jslint browser: true, white: true, plusplus: true, vars: true */
|
/*jslint browser: true, white: true, single: true, this: true, multivar: true */
|
||||||
/*global define, window, document, jQuery, exports, require */
|
/*global define, window, document, jQuery, exports, require */
|
||||||
|
|
||||||
// Expose plugin as an AMD module if AMD loader is present:
|
// Expose plugin as an AMD module if AMD loader is present:
|
||||||
(function (factory) {
|
(function (factory) {
|
||||||
'use strict';
|
"use strict";
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
// AMD. Register as an anonymous module.
|
// AMD. Register as an anonymous module.
|
||||||
define(['jquery'], factory);
|
define(['jquery'], factory);
|
||||||
@ -29,7 +29,7 @@
|
|||||||
utils = (function () {
|
utils = (function () {
|
||||||
return {
|
return {
|
||||||
escapeRegExChars: function (value) {
|
escapeRegExChars: function (value) {
|
||||||
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||||
},
|
},
|
||||||
createNode: function (containerClass) {
|
createNode: function (containerClass) {
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
@ -52,7 +52,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function Autocomplete(el, options) {
|
function Autocomplete(el, options) {
|
||||||
var noop = function () { },
|
var noop = $.noop,
|
||||||
that = this,
|
that = this,
|
||||||
defaults = {
|
defaults = {
|
||||||
ajaxSettings: {},
|
ajaxSettings: {},
|
||||||
@ -158,7 +158,7 @@
|
|||||||
that.element.setAttribute('autocomplete', 'off');
|
that.element.setAttribute('autocomplete', 'off');
|
||||||
|
|
||||||
that.killerFn = function (e) {
|
that.killerFn = function (e) {
|
||||||
if ($(e.target).closest('.' + that.options.containerClass).length === 0) {
|
if (!$(e.target).closest('.' + that.options.containerClass).length) {
|
||||||
that.killSuggestions();
|
that.killSuggestions();
|
||||||
that.disableKillerFn();
|
that.disableKillerFn();
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@
|
|||||||
|
|
||||||
// Only set width if it was provided:
|
// Only set width if it was provided:
|
||||||
if (options.width !== 'auto') {
|
if (options.width !== 'auto') {
|
||||||
container.width(options.width);
|
container.css('width', options.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for mouse over event on suggestions list:
|
// Listen for mouse over event on suggestions list:
|
||||||
@ -332,9 +332,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -2px to account for suggestions border.
|
|
||||||
if (that.options.width === 'auto') {
|
if (that.options.width === 'auto') {
|
||||||
styles.width = (that.el.outerWidth() - 2) + 'px';
|
styles.width = that.el.outerWidth() + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
$container.css(styles);
|
$container.css(styles);
|
||||||
@ -355,7 +354,13 @@
|
|||||||
that.stopKillSuggestions();
|
that.stopKillSuggestions();
|
||||||
that.intervalId = window.setInterval(function () {
|
that.intervalId = window.setInterval(function () {
|
||||||
if (that.visible) {
|
if (that.visible) {
|
||||||
that.el.val(that.currentValue);
|
// No need to restore value when
|
||||||
|
// preserveInput === true,
|
||||||
|
// because we did not change it
|
||||||
|
if (!that.options.preserveInput) {
|
||||||
|
that.el.val(that.currentValue);
|
||||||
|
}
|
||||||
|
|
||||||
that.hide();
|
that.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,7 +641,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
suggest: function () {
|
suggest: function () {
|
||||||
if (this.suggestions.length === 0) {
|
if (!this.suggestions.length) {
|
||||||
if (this.options.showNoSuggestionNotice) {
|
if (this.options.showNoSuggestionNotice) {
|
||||||
this.noSuggestions();
|
this.noSuggestions();
|
||||||
} else {
|
} else {
|
||||||
@ -734,10 +739,9 @@
|
|||||||
// If width is auto, adjust width before displaying suggestions,
|
// If width is auto, adjust width before displaying suggestions,
|
||||||
// because if instance was created before input had width, it will be zero.
|
// because if instance was created before input had width, it will be zero.
|
||||||
// Also it adjusts if input width has changed.
|
// Also it adjusts if input width has changed.
|
||||||
// -2px to account for suggestions border.
|
|
||||||
if (options.width === 'auto') {
|
if (options.width === 'auto') {
|
||||||
width = that.el.outerWidth() - 2;
|
width = that.el.outerWidth();
|
||||||
container.width(width > 0 ? width : 300);
|
container.css('width', width > 0 ? width : 300);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -804,7 +808,7 @@
|
|||||||
// Cache results if cache is not disabled:
|
// Cache results if cache is not disabled:
|
||||||
if (!options.noCache) {
|
if (!options.noCache) {
|
||||||
that.cachedResponse[cacheKey] = result;
|
that.cachedResponse[cacheKey] = result;
|
||||||
if (options.preventBadQueries && result.suggestions.length === 0) {
|
if (options.preventBadQueries && !result.suggestions.length) {
|
||||||
that.badQueries.push(originalQuery);
|
that.badQueries.push(originalQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -849,6 +853,7 @@
|
|||||||
var that = this;
|
var that = this;
|
||||||
that.hide();
|
that.hide();
|
||||||
that.onSelect(i);
|
that.onSelect(i);
|
||||||
|
that.disableKillerFn();
|
||||||
},
|
},
|
||||||
|
|
||||||
moveUp: function () {
|
moveUp: function () {
|
||||||
@ -962,7 +967,7 @@
|
|||||||
var dataKey = 'autocomplete';
|
var dataKey = 'autocomplete';
|
||||||
// If function invoked without argument return
|
// If function invoked without argument return
|
||||||
// instance of the first matched element:
|
// instance of the first matched element:
|
||||||
if (arguments.length === 0) {
|
if (!arguments.length) {
|
||||||
return this.first().data(dataKey);
|
return this.first().data(dataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
dist/jquery.autocomplete.min.js
vendored
4
dist/jquery.autocomplete.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "devbridge-autocomplete",
|
"name": "devbridge-autocomplete",
|
||||||
"version": "1.2.25",
|
"version": "1.2.27",
|
||||||
"description": "Autocomplete provides suggestions while you type into the text field.",
|
"description": "Autocomplete provides suggestions while you type into the text field.",
|
||||||
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
|
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
|
||||||
"author": "Tomas Kirda (https://twitter.com/tkirda)",
|
"author": "Tomas Kirda (https://twitter.com/tkirda)",
|
||||||
@ -14,8 +14,8 @@
|
|||||||
"jquery": ">=1.7"
|
"jquery": ">=1.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^1.0.1",
|
||||||
"grunt-contrib-uglify": "^0.5.1"
|
"grunt-contrib-uglify": "^1.0.1"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist/",
|
"dist/",
|
||||||
|
22
readme.md
22
readme.md
@ -23,16 +23,16 @@ The standard jquery.autocomplete.js file is around 13KB when minified.
|
|||||||
* `dataType`: type of data returned from server. Either `text` (default), `json` or `jsonp`, which will cause the autocomplete to use jsonp. You may return a json object in your callback when using jsonp.
|
* `dataType`: type of data returned from server. Either `text` (default), `json` or `jsonp`, which will cause the autocomplete to use jsonp. You may return a json object in your callback when using jsonp.
|
||||||
* `paramName`: Default `query`. The name of the request parameter that contains the query.
|
* `paramName`: Default `query`. The name of the request parameter that contains the query.
|
||||||
* `params`: Additional parameters to pass with the request, optional.
|
* `params`: Additional parameters to pass with the request, optional.
|
||||||
* `deferRequestBy`: Number of miliseconds to defer ajax request. Default: `0`.
|
* `deferRequestBy`: Number of miliseconds to defer Ajax request. Default: `0`.
|
||||||
* `ajaxSettings`: Any additional [Ajax Settings](http://api.jquery.com/jquery.ajax/#jQuery-ajax-settings) that configure the jQuery Ajax request.
|
* `ajaxSettings`: Any additional [Ajax Settings](http://api.jquery.com/jquery.ajax/#jQuery-ajax-settings) that configure the jQuery Ajax request.
|
||||||
|
|
||||||
###Configuration Settings
|
###Configuration Settings
|
||||||
* `noCache`: Boolean value indicating whether to cache suggestion results. Default `false`.
|
* `noCache`: Boolean value indicating whether to cache suggestion results. Default `false`.
|
||||||
* `delimiter`: String or RegExp, that splits input value and takes last part to as query for suggestions.
|
* `delimiter`: String or RegExp, that splits input value and takes last part to as query for suggestions.
|
||||||
Useful when for example you need to fill list of coma separated values.
|
Useful when for example you need to fill list of comma separated values.
|
||||||
* `onSearchStart`: `function (query) {}` called before ajax request. `this` is bound to input element.
|
* `onSearchStart`: `function (query) {}` called before Ajax request. `this` is bound to input element.
|
||||||
* `onSearchComplete`: `function (query, suggestions) {}` called after ajax response is processed. `this` is bound to input element. `suggestions` is an array containing the results.
|
* `onSearchComplete`: `function (query, suggestions) {}` called after Ajax response is processed. `this` is bound to input element. `suggestions` is an array containing the results.
|
||||||
* `onSearchError`: `function (query, jqXHR, textStatus, errorThrown) {}` called if ajax request fails. `this` is bound to input element.
|
* `onSearchError`: `function (query, jqXHR, textStatus, errorThrown) {}` called if Ajax request fails. `this` is bound to input element.
|
||||||
* `transformResult`: `function(response, originalQuery) {}` called after the result of the query is ready. Converts the result into response.suggestions format.
|
* `transformResult`: `function(response, originalQuery) {}` called after the result of the query is ready. Converts the result into response.suggestions format.
|
||||||
* `onSelect`: `function (suggestion) {}` Callback function invoked when user selects suggestion
|
* `onSelect`: `function (suggestion) {}` Callback function invoked when user selects suggestion
|
||||||
from the list. `this` inside callback refers to input HtmlElement.
|
from the list. `this` inside callback refers to input HtmlElement.
|
||||||
@ -42,7 +42,7 @@ The standard jquery.autocomplete.js file is around 13KB when minified.
|
|||||||
* `suggestion`: An object literal with the following format: `{ value: 'string', data: any }`.
|
* `suggestion`: An object literal with the following format: `{ value: 'string', data: any }`.
|
||||||
* `lookupFilter`: `function (suggestion, query, queryLowerCase) {}` filter function for local lookups. By default it does partial string match (case insensitive).
|
* `lookupFilter`: `function (suggestion, query, queryLowerCase) {}` filter function for local lookups. By default it does partial string match (case insensitive).
|
||||||
* `triggerSelectOnValidInput`: Boolean value indicating if `select` should be triggered if it matches suggestion. Default `true`.
|
* `triggerSelectOnValidInput`: Boolean value indicating if `select` should be triggered if it matches suggestion. Default `true`.
|
||||||
* `preventBadQueries`: Boolean value indicating if it shoud prevent future ajax requests for queries with the same root if no results were returned. E.g. if `Jam` returns no suggestions, it will not fire for any future query that starts with `Jam`. Default `true`.
|
* `preventBadQueries`: Boolean value indicating if it should prevent future Ajax requests for queries with the same root if no results were returned. E.g. if `Jam` returns no suggestions, it will not fire for any future query that starts with `Jam`. Default `true`.
|
||||||
* `autoSelectFirst`: if set to `true`, first item will be selected when showing suggestions. Default value `false`.
|
* `autoSelectFirst`: if set to `true`, first item will be selected when showing suggestions. Default value `false`.
|
||||||
* `onHide`: `function (container) {}` called before container will be hidden
|
* `onHide`: `function (container) {}` called before container will be hidden
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ The standard jquery.autocomplete.js file is around 13KB when minified.
|
|||||||
* `maxHeight`: Maximum height of the suggestions container in pixels. Default: `300`.
|
* `maxHeight`: Maximum height of the suggestions container in pixels. Default: `300`.
|
||||||
* `width`: Suggestions container width in pixels, e.g.: 300. Default: `auto`, takes input field width.
|
* `width`: Suggestions container width in pixels, e.g.: 300. Default: `auto`, takes input field width.
|
||||||
* `zIndex`: 'z-index' for suggestions container. Default: `9999`.
|
* `zIndex`: 'z-index' for suggestions container. Default: `9999`.
|
||||||
* `appendTo`: container where suggestions will be appended. Default value `document.body`. Can be jQuery object, selector or html element. Make sure to set `position: absolute` or `position: relative` for that element.
|
* `appendTo`: container where suggestions will be appended. Default value `document.body`. Can be jQuery object, selector or HTML element. Make sure to set `position: absolute` or `position: relative` for that element.
|
||||||
* `forceFixPosition`: Default: `false`. Suggestions are automatically positioned when their container is appended to body (look at `appendTo` option), in other cases suggestions are rendered but no positioning is applied.
|
* `forceFixPosition`: Default: `false`. Suggestions are automatically positioned when their container is appended to body (look at `appendTo` option), in other cases suggestions are rendered but no positioning is applied.
|
||||||
Set this option to force auto positioning in other cases.
|
Set this option to force auto positioning in other cases.
|
||||||
* `orientation`: Default `bottom`. Vertical orientation of the displayed suggestions, available values are `auto`, `top`, `bottom`.
|
* `orientation`: Default `bottom`. Vertical orientation of the displayed suggestions, available values are `auto`, `top`, `bottom`.
|
||||||
@ -72,7 +72,7 @@ The standard jquery.autocomplete.js file is around 13KB when minified.
|
|||||||
Autocomplete instance has following methods:
|
Autocomplete instance has following methods:
|
||||||
|
|
||||||
* `setOptions(options)`: you may update any option at any time. Options are listed above.
|
* `setOptions(options)`: you may update any option at any time. Options are listed above.
|
||||||
* `clear`: clears suggestion cache and current suggestions suggestions.
|
* `clear`: clears suggestion cache and current suggestions.
|
||||||
* `clearCache`: clears suggestion cache.
|
* `clearCache`: clears suggestion cache.
|
||||||
* `disable`: deactivate autocomplete.
|
* `disable`: deactivate autocomplete.
|
||||||
* `enable`: activates autocomplete if it was deactivated before.
|
* `enable`: activates autocomplete if it was deactivated before.
|
||||||
@ -113,7 +113,7 @@ $('#autocomplete').autocomplete({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Local lookup (no ajax):
|
Local lookup (no Ajax):
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var countries = [
|
var countries = [
|
||||||
@ -135,7 +135,7 @@ Custom lookup function:
|
|||||||
|
|
||||||
$('#autocomplete').autocomplete({
|
$('#autocomplete').autocomplete({
|
||||||
lookup: function (query, done) {
|
lookup: function (query, done) {
|
||||||
// Do ajax call or lookup locally, when done,
|
// Do Ajax call or lookup locally, when done,
|
||||||
// call the callback and pass your results:
|
// call the callback and pass your results:
|
||||||
var result = {
|
var result = {
|
||||||
suggestions: [
|
suggestions: [
|
||||||
@ -207,7 +207,7 @@ supply just a string array for suggestions:
|
|||||||
|
|
||||||
## Non standard query/results
|
## Non standard query/results
|
||||||
|
|
||||||
If your ajax service expects the query in a different format, and returns data in a different format than the standard response,
|
If your Ajax service expects the query in a different format, and returns data in a different format than the standard response,
|
||||||
you can supply the "paramName" and "transformResult" options:
|
you can supply the "paramName" and "transformResult" options:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
|
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*jslint browser: true, white: true, plusplus: true, vars: true */
|
/*jslint browser: true, white: true, single: true, this: true, multivar: true */
|
||||||
/*global define, window, document, jQuery, exports, require */
|
/*global define, window, document, jQuery, exports, require */
|
||||||
|
|
||||||
// Expose plugin as an AMD module if AMD loader is present:
|
// Expose plugin as an AMD module if AMD loader is present:
|
||||||
(function (factory) {
|
(function (factory) {
|
||||||
'use strict';
|
"use strict";
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
// AMD. Register as an anonymous module.
|
// AMD. Register as an anonymous module.
|
||||||
define(['jquery'], factory);
|
define(['jquery'], factory);
|
||||||
@ -29,7 +29,7 @@
|
|||||||
utils = (function () {
|
utils = (function () {
|
||||||
return {
|
return {
|
||||||
escapeRegExChars: function (value) {
|
escapeRegExChars: function (value) {
|
||||||
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
||||||
},
|
},
|
||||||
createNode: function (containerClass) {
|
createNode: function (containerClass) {
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
@ -52,7 +52,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function Autocomplete(el, options) {
|
function Autocomplete(el, options) {
|
||||||
var noop = function () { },
|
var noop = $.noop,
|
||||||
that = this,
|
that = this,
|
||||||
defaults = {
|
defaults = {
|
||||||
ajaxSettings: {},
|
ajaxSettings: {},
|
||||||
@ -160,7 +160,7 @@
|
|||||||
that.element.setAttribute('autocomplete', 'off');
|
that.element.setAttribute('autocomplete', 'off');
|
||||||
|
|
||||||
that.killerFn = function (e) {
|
that.killerFn = function (e) {
|
||||||
if ($(e.target).closest('.' + that.options.containerClass).length === 0) {
|
if (!$(e.target).closest('.' + that.options.containerClass).length) {
|
||||||
that.killSuggestions();
|
that.killSuggestions();
|
||||||
that.disableKillerFn();
|
that.disableKillerFn();
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@
|
|||||||
|
|
||||||
// Only set width if it was provided:
|
// Only set width if it was provided:
|
||||||
if (options.width !== 'auto') {
|
if (options.width !== 'auto') {
|
||||||
container.width(options.width);
|
container.css('width', options.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for mouse over event on suggestions list:
|
// Listen for mouse over event on suggestions list:
|
||||||
@ -334,9 +334,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -2px to account for suggestions border.
|
|
||||||
if (that.options.width === 'auto') {
|
if (that.options.width === 'auto') {
|
||||||
styles.width = (that.el.outerWidth() - 2) + 'px';
|
styles.width = that.el.outerWidth() + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
$container.css(styles);
|
$container.css(styles);
|
||||||
@ -357,7 +356,13 @@
|
|||||||
that.stopKillSuggestions();
|
that.stopKillSuggestions();
|
||||||
that.intervalId = window.setInterval(function () {
|
that.intervalId = window.setInterval(function () {
|
||||||
if (that.visible) {
|
if (that.visible) {
|
||||||
that.el.val(that.currentValue);
|
// No need to restore value when
|
||||||
|
// preserveInput === true,
|
||||||
|
// because we did not change it
|
||||||
|
if (!that.options.preserveInput) {
|
||||||
|
that.el.val(that.currentValue);
|
||||||
|
}
|
||||||
|
|
||||||
that.hide();
|
that.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,7 +643,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
suggest: function () {
|
suggest: function () {
|
||||||
if (this.suggestions.length === 0) {
|
if (!this.suggestions.length) {
|
||||||
if (this.options.showNoSuggestionNotice) {
|
if (this.options.showNoSuggestionNotice) {
|
||||||
this.noSuggestions();
|
this.noSuggestions();
|
||||||
} else {
|
} else {
|
||||||
@ -744,10 +749,9 @@
|
|||||||
// If width is auto, adjust width before displaying suggestions,
|
// If width is auto, adjust width before displaying suggestions,
|
||||||
// because if instance was created before input had width, it will be zero.
|
// because if instance was created before input had width, it will be zero.
|
||||||
// Also it adjusts if input width has changed.
|
// Also it adjusts if input width has changed.
|
||||||
// -2px to account for suggestions border.
|
|
||||||
if (options.width === 'auto') {
|
if (options.width === 'auto') {
|
||||||
width = that.el.outerWidth() - 2;
|
width = that.el.outerWidth();
|
||||||
container.width(width > 0 ? width : 300);
|
container.css('width', width > 0 ? width : 300);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -814,7 +818,7 @@
|
|||||||
// Cache results if cache is not disabled:
|
// Cache results if cache is not disabled:
|
||||||
if (!options.noCache) {
|
if (!options.noCache) {
|
||||||
that.cachedResponse[cacheKey] = result;
|
that.cachedResponse[cacheKey] = result;
|
||||||
if (options.preventBadQueries && result.suggestions.length === 0) {
|
if (options.preventBadQueries && !result.suggestions.length) {
|
||||||
that.badQueries.push(originalQuery);
|
that.badQueries.push(originalQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -859,6 +863,7 @@
|
|||||||
var that = this;
|
var that = this;
|
||||||
that.hide();
|
that.hide();
|
||||||
that.onSelect(i);
|
that.onSelect(i);
|
||||||
|
that.disableKillerFn();
|
||||||
},
|
},
|
||||||
|
|
||||||
moveUp: function () {
|
moveUp: function () {
|
||||||
@ -972,7 +977,7 @@
|
|||||||
var dataKey = 'autocomplete';
|
var dataKey = 'autocomplete';
|
||||||
// If function invoked without argument return
|
// If function invoked without argument return
|
||||||
// instance of the first matched element:
|
// instance of the first matched element:
|
||||||
if (arguments.length === 0) {
|
if (!arguments.length) {
|
||||||
return this.first().data(dataKey);
|
return this.first().data(dataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,10 +134,7 @@ input.autocomplete({
|
|||||||
formatResult(suggestion: AutocompleteSuggestion, currentValue: string): string {
|
formatResult(suggestion: AutocompleteSuggestion, currentValue: string): string {
|
||||||
return currentValue;
|
return currentValue;
|
||||||
},
|
},
|
||||||
groupBy: [
|
groupBy: "category",
|
||||||
{ value: 'Chicago Blackhawks', data: { category: 'NHL' } },
|
|
||||||
{ value: 'Chicago Bulls', data: { category: 'NBA' } }
|
|
||||||
],
|
|
||||||
maxHeight: 300,
|
maxHeight: 300,
|
||||||
width: "auto",
|
width: "auto",
|
||||||
zIndex: 9999,
|
zIndex: 9999,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Type definitions for jQuery-Autocomplete 1.2.24
|
// Type definitions for jQuery-Autocomplete 1.2.25
|
||||||
// Project: https://www.devbridge.com/sourcery/components/jquery-autocomplete/
|
// Project: https://www.devbridge.com/sourcery/components/jquery-autocomplete/
|
||||||
// Definitions by: John Gouigouix <https://github.com/orchestra-ts/DefinitelyTyped/>
|
// Definitions by: John Gouigouix <https://github.com/orchestra-ts/DefinitelyTyped/>
|
||||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||||
@ -130,7 +130,7 @@ interface JQueryAutocompleteOptions {
|
|||||||
* Callback function or lookup array for the suggestions. It may be array of strings or suggestion object literals.
|
* Callback function or lookup array for the suggestions. It may be array of strings or suggestion object literals.
|
||||||
* -> suggestion: An object literal with the following format: { value: 'string', data: any }.
|
* -> suggestion: An object literal with the following format: { value: 'string', data: any }.
|
||||||
*/
|
*/
|
||||||
lookup?: AutocompleteSuggestion[];
|
lookup?: Function | AutocompleteSuggestion[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter function for local lookups. By default it does partial string match (case insensitive).
|
* Filter function for local lookups. By default it does partial string match (case insensitive).
|
||||||
@ -184,7 +184,8 @@ interface JQueryAutocompleteOptions {
|
|||||||
/**
|
/**
|
||||||
* Property name of the suggestion data object, by which results should be grouped.
|
* Property name of the suggestion data object, by which results should be grouped.
|
||||||
*/
|
*/
|
||||||
groupBy?: AutocompleteSuggestion | AutocompleteSuggestion[];
|
groupBy?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum height of the suggestions container in pixels.
|
* Maximum height of the suggestions container in pixels.
|
||||||
* @default 300
|
* @default 300
|
||||||
@ -301,8 +302,7 @@ interface JQuery {
|
|||||||
/**
|
/**
|
||||||
* Create Autocomplete component
|
* Create Autocomplete component
|
||||||
*/
|
*/
|
||||||
autocomplete(): AutocompleteInstance;
|
autocomplete(options?: JQueryAutocompleteOptions): AutocompleteInstance;
|
||||||
autocomplete(options: JQueryAutocompleteOptions): AutocompleteInstance;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger non-specialized signature method
|
* Trigger non-specialized signature method
|
||||||
@ -354,4 +354,59 @@ interface JQuery {
|
|||||||
*/
|
*/
|
||||||
autocomplete(methodName: "dispose"): AutocompleteInstance;
|
autocomplete(methodName: "dispose"): AutocompleteInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Autocomplete component via plugin alias
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(options?: JQueryAutocompleteOptions): AutocompleteInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger non-specialized signature method
|
||||||
|
* @param methodName
|
||||||
|
* @param arg
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(methodName: string, ...arg: any[]): any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You may update any option at any time. Options are listed above.
|
||||||
|
* @param methodName The name of the method
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(methodName: "setOptions", options: JQueryAutocompleteOptions): AutocompleteInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears suggestion cache and current suggestions suggestions.
|
||||||
|
* @param methodName The name of the method
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(methodName: "clear"): AutocompleteInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears suggestion cache.
|
||||||
|
* @param methodName The name of the method
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(methodName: "clearCache"): AutocompleteInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deactivate autocomplete.
|
||||||
|
* @param methodName The name of the method
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(methodName: "disable"): AutocompleteInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activates autocomplete if it was deactivated before.
|
||||||
|
* @param methodName The name of the method
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(methodName: "enable"): AutocompleteInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hides suggestions.
|
||||||
|
* @param methodName The name of the method
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(methodName: "hide"): AutocompleteInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys autocomplete instance. All events are detached and suggestion containers removed.
|
||||||
|
* @param methodName The name of the method
|
||||||
|
*/
|
||||||
|
devbridgeAutocomplete(methodName: "dispose"): AutocompleteInstance;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user