2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-09-19 16:59:01 +00:00

Merge branch 'master' into ShowSuggestionAndOrCategoryOnHover

This commit is contained in:
Preetpal Sohal 2016-12-09 09:51:42 -08:00
commit 920b8193d2
10 changed files with 121 additions and 59 deletions

View File

@ -1,6 +1,6 @@
{
"name": "devbridge-autocomplete",
"version": "1.2.25",
"version": "1.2.27",
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
"authors": [
"Tomas Kirda"

View File

@ -1,7 +1,7 @@
body { font-family: sans-serif; font-size: 14px; line-height: 1.6em; margin: 0; padding: 0; }
.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-no-suggestion { padding: 2px 5px;}
.autocomplete-selected { background: #F0F0F0; }

View File

@ -6,7 +6,7 @@
"ajax",
"autocomplete"
],
"version": "1.2.25",
"version": "1.2.27",
"author": {
"name": "Tomas Kirda",
"url": "https://github.com/tkirda"

View File

@ -1,17 +1,17 @@
/**
* Ajax Autocomplete for jQuery, version 1.2.25
* Ajax Autocomplete for jQuery, version 1.2.27
* (c) 2015 Tomas Kirda
*
* 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
*/
/*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 */
// Expose plugin as an AMD module if AMD loader is present:
(function (factory) {
'use strict';
"use strict";
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
@ -29,7 +29,7 @@
utils = (function () {
return {
escapeRegExChars: function (value) {
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
},
createNode: function (containerClass) {
var div = document.createElement('div');
@ -52,7 +52,7 @@
};
function Autocomplete(el, options) {
var noop = function () { },
var noop = $.noop,
that = this,
defaults = {
ajaxSettings: {},
@ -158,7 +158,7 @@
that.element.setAttribute('autocomplete', 'off');
that.killerFn = function (e) {
if ($(e.target).closest('.' + that.options.containerClass).length === 0) {
if (!$(e.target).closest('.' + that.options.containerClass).length) {
that.killSuggestions();
that.disableKillerFn();
}
@ -176,7 +176,7 @@
// Only set width if it was provided:
if (options.width !== 'auto') {
container.width(options.width);
container.css('width', options.width);
}
// Listen for mouse over event on suggestions list:
@ -332,9 +332,8 @@
}
}
// -2px to account for suggestions border.
if (that.options.width === 'auto') {
styles.width = (that.el.outerWidth() - 2) + 'px';
styles.width = that.el.outerWidth() + 'px';
}
$container.css(styles);
@ -355,7 +354,13 @@
that.stopKillSuggestions();
that.intervalId = window.setInterval(function () {
if (that.visible) {
// 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();
}
@ -636,7 +641,7 @@
},
suggest: function () {
if (this.suggestions.length === 0) {
if (!this.suggestions.length) {
if (this.options.showNoSuggestionNotice) {
this.noSuggestions();
} else {
@ -734,10 +739,9 @@
// If width is auto, adjust width before displaying suggestions,
// because if instance was created before input had width, it will be zero.
// Also it adjusts if input width has changed.
// -2px to account for suggestions border.
if (options.width === 'auto') {
width = that.el.outerWidth() - 2;
container.width(width > 0 ? width : 300);
width = that.el.outerWidth();
container.css('width', width > 0 ? width : 300);
}
},
@ -804,7 +808,7 @@
// Cache results if cache is not disabled:
if (!options.noCache) {
that.cachedResponse[cacheKey] = result;
if (options.preventBadQueries && result.suggestions.length === 0) {
if (options.preventBadQueries && !result.suggestions.length) {
that.badQueries.push(originalQuery);
}
}
@ -849,6 +853,7 @@
var that = this;
that.hide();
that.onSelect(i);
that.disableKillerFn();
},
moveUp: function () {
@ -962,7 +967,7 @@
var dataKey = 'autocomplete';
// If function invoked without argument return
// instance of the first matched element:
if (arguments.length === 0) {
if (!arguments.length) {
return this.first().data(dataKey);
}

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "devbridge-autocomplete",
"version": "1.2.25",
"version": "1.2.27",
"description": "Autocomplete provides suggestions while you type into the text field.",
"homepage": "https://github.com/devbridge/jQuery-Autocomplete",
"author": "Tomas Kirda (https://twitter.com/tkirda)",
@ -14,8 +14,8 @@
"jquery": ">=1.7"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.5.1"
"grunt": "^1.0.1",
"grunt-contrib-uglify": "^1.0.1"
},
"files": [
"dist/",

View File

@ -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.
* `paramName`: Default `query`. The name of the request parameter that contains the query.
* `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.
###Configuration Settings
* `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.
Useful when for example you need to fill list of coma separated values.
* `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.
* `onSearchError`: `function (query, jqXHR, textStatus, errorThrown) {}` called if ajax request fails. `this` is bound to input element.
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.
* `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.
* `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
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 }`.
* `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`.
* `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`.
* `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`.
* `width`: Suggestions container width in pixels, e.g.: 300. Default: `auto`, takes input field width.
* `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.
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`.
@ -72,7 +72,7 @@ The standard jquery.autocomplete.js file is around 13KB when minified.
Autocomplete instance has following methods:
* `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.
* `disable`: deactivate autocomplete.
* `enable`: activates autocomplete if it was deactivated before.
@ -113,7 +113,7 @@ $('#autocomplete').autocomplete({
});
```
Local lookup (no ajax):
Local lookup (no Ajax):
```javascript
var countries = [
@ -135,7 +135,7 @@ Custom lookup function:
$('#autocomplete').autocomplete({
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:
var result = {
suggestions: [
@ -207,7 +207,7 @@ supply just a string array for suggestions:
## 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:
```javascript

View File

@ -6,12 +6,12 @@
* 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 */
// Expose plugin as an AMD module if AMD loader is present:
(function (factory) {
'use strict';
"use strict";
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
@ -29,7 +29,7 @@
utils = (function () {
return {
escapeRegExChars: function (value) {
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
},
createNode: function (containerClass) {
var div = document.createElement('div');
@ -52,7 +52,7 @@
};
function Autocomplete(el, options) {
var noop = function () { },
var noop = $.noop,
that = this,
defaults = {
ajaxSettings: {},
@ -160,7 +160,7 @@
that.element.setAttribute('autocomplete', 'off');
that.killerFn = function (e) {
if ($(e.target).closest('.' + that.options.containerClass).length === 0) {
if (!$(e.target).closest('.' + that.options.containerClass).length) {
that.killSuggestions();
that.disableKillerFn();
}
@ -178,7 +178,7 @@
// Only set width if it was provided:
if (options.width !== 'auto') {
container.width(options.width);
container.css('width', options.width);
}
// Listen for mouse over event on suggestions list:
@ -334,9 +334,8 @@
}
}
// -2px to account for suggestions border.
if (that.options.width === 'auto') {
styles.width = (that.el.outerWidth() - 2) + 'px';
styles.width = that.el.outerWidth() + 'px';
}
$container.css(styles);
@ -357,7 +356,13 @@
that.stopKillSuggestions();
that.intervalId = window.setInterval(function () {
if (that.visible) {
// 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();
}
@ -638,7 +643,7 @@
},
suggest: function () {
if (this.suggestions.length === 0) {
if (!this.suggestions.length) {
if (this.options.showNoSuggestionNotice) {
this.noSuggestions();
} else {
@ -744,10 +749,9 @@
// If width is auto, adjust width before displaying suggestions,
// because if instance was created before input had width, it will be zero.
// Also it adjusts if input width has changed.
// -2px to account for suggestions border.
if (options.width === 'auto') {
width = that.el.outerWidth() - 2;
container.width(width > 0 ? width : 300);
width = that.el.outerWidth();
container.css('width', width > 0 ? width : 300);
}
},
@ -814,7 +818,7 @@
// Cache results if cache is not disabled:
if (!options.noCache) {
that.cachedResponse[cacheKey] = result;
if (options.preventBadQueries && result.suggestions.length === 0) {
if (options.preventBadQueries && !result.suggestions.length) {
that.badQueries.push(originalQuery);
}
}
@ -859,6 +863,7 @@
var that = this;
that.hide();
that.onSelect(i);
that.disableKillerFn();
},
moveUp: function () {
@ -972,7 +977,7 @@
var dataKey = 'autocomplete';
// If function invoked without argument return
// instance of the first matched element:
if (arguments.length === 0) {
if (!arguments.length) {
return this.first().data(dataKey);
}

View File

@ -134,10 +134,7 @@ input.autocomplete({
formatResult(suggestion: AutocompleteSuggestion, currentValue: string): string {
return currentValue;
},
groupBy: [
{ value: 'Chicago Blackhawks', data: { category: 'NHL' } },
{ value: 'Chicago Bulls', data: { category: 'NBA' } }
],
groupBy: "category",
maxHeight: 300,
width: "auto",
zIndex: 9999,

View File

@ -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/
// Definitions by: John Gouigouix <https://github.com/orchestra-ts/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.
* -> 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).
@ -184,7 +184,8 @@ interface JQueryAutocompleteOptions {
/**
* 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.
* @default 300
@ -301,8 +302,7 @@ interface JQuery {
/**
* Create Autocomplete component
*/
autocomplete(): AutocompleteInstance;
autocomplete(options: JQueryAutocompleteOptions): AutocompleteInstance;
autocomplete(options?: JQueryAutocompleteOptions): AutocompleteInstance;
/**
* Trigger non-specialized signature method
@ -354,4 +354,59 @@ interface JQuery {
*/
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;
}