-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
63 lines (61 loc) · 1.85 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
/**
* A typeahead component for inputs
* @class Suggestions
*
* @param {HTMLInputElement} el A valid HTML input element
* @param {Array} data An array of data used for results
* @param {Object} options
* @param {Number} [options.limit=5] Max number of results to display in the auto suggest list.
* @param {Number} [options.minLength=2] Number of characters typed into an input to trigger suggestions.
* @param {Boolean} [options.hideOnBlur=true] If `true`, hides the suggestions when focus is lost.
* @return {Suggestions} `this`
* @example
* // in the browser
* var input = document.querySelector('input');
* var data = [
* 'Roy Eldridge',
* 'Roy Hargrove',
* 'Rex Stewart'
* ];
*
* new Suggestions(input, data);
*
* // with options
* var input = document.querySelector('input');
* var data = [{
* name: 'Roy Eldridge',
* year: 1911
* }, {
* name: 'Roy Hargrove',
* year: 1969
* }, {
* name: 'Rex Stewart',
* year: 1907
* }];
*
* var typeahead = new Suggestions(input, data, {
* filter: false, // Disable filtering
* minLength: 3, // Number of characters typed into an input to trigger suggestions.
* limit: 3, // Max number of results to display.
* hideOnBlur: false // Don't hide results when input loses focus
* });
*
* // As we're passing an object of an arrays as data, override
* // `getItemValue` by specifying the specific property to search on.
* typeahead.getItemValue = function(item) { return item.name };
*
* input.addEventListener('change', function() {
* console.log(typeahead.selected); // Current selected item.
* });
*
* // With browserify
* var Suggestions = require('suggestions');
*
* new Suggestions(input, data);
*/
var Suggestions = require('./src/suggestions');
module.exports = Suggestions;
if (typeof window !== 'undefined') {
window.Suggestions = Suggestions;
}