|
1 | 1 | /*! |
2 | 2 | * typeahead.js 0.11.1 |
3 | 3 | * https://github.com/twitter/typeahead.js |
4 | | - * Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT |
| 4 | + * Copyright 2013-2016 Twitter, Inc. and other contributors; Licensed MIT |
5 | 5 | */ |
6 | 6 |
|
7 | 7 | (function(root, factory) { |
|
12 | 12 | } else if (typeof exports === "object") { |
13 | 13 | module.exports = factory(require("jquery")); |
14 | 14 | } else { |
15 | | - root["Bloodhound"] = factory(jQuery); |
| 15 | + root["Bloodhound"] = factory(root["jQuery"]); |
16 | 16 | } |
17 | 17 | })(this, function($) { |
18 | 18 | var _ = function() { |
|
157 | 157 | return { |
158 | 158 | nonword: nonword, |
159 | 159 | whitespace: whitespace, |
| 160 | + ngram: ngram, |
160 | 161 | obj: { |
161 | 162 | nonword: getObjTokenizer(nonword), |
162 | | - whitespace: getObjTokenizer(whitespace) |
| 163 | + whitespace: getObjTokenizer(whitespace), |
| 164 | + ngram: getObjTokenizer(ngram) |
163 | 165 | } |
164 | 166 | }; |
165 | 167 | function whitespace(str) { |
|
170 | 172 | str = _.toStr(str); |
171 | 173 | return str ? str.split(/\W+/) : []; |
172 | 174 | } |
| 175 | + function ngram(str) { |
| 176 | + str = _.toStr(str); |
| 177 | + var tokens = [], word = ""; |
| 178 | + _.each(str.split(""), function(char) { |
| 179 | + if (char.match(/\s+/)) { |
| 180 | + word = ""; |
| 181 | + } else { |
| 182 | + tokens.push(word + char); |
| 183 | + word += char; |
| 184 | + } |
| 185 | + }); |
| 186 | + return tokens; |
| 187 | + } |
173 | 188 | function getObjTokenizer(tokenizer) { |
174 | 189 | return function setKey(keys) { |
175 | 190 | keys = _.isArray(keys) ? keys : [].slice.call(arguments, 0); |
|
935 | 950 | } else if (typeof exports === "object") { |
936 | 951 | module.exports = factory(require("jquery")); |
937 | 952 | } else { |
938 | | - factory(jQuery); |
| 953 | + factory(root["jQuery"]); |
939 | 954 | } |
940 | 955 | })(this, function($) { |
941 | 956 | var _ = function() { |
|
1730 | 1745 | suggestions = suggestions || []; |
1731 | 1746 | if (!canceled && rendered < that.limit) { |
1732 | 1747 | that.cancel = $.noop; |
1733 | | - that._append(query, suggestions.slice(0, that.limit - rendered)); |
1734 | | - rendered += suggestions.length; |
| 1748 | + var idx = Math.abs(rendered - that.limit); |
| 1749 | + rendered += idx; |
| 1750 | + that._append(query, suggestions.slice(0, idx)); |
1735 | 1751 | that.async && that.trigger("asyncReceived", query); |
1736 | 1752 | } |
1737 | 1753 | } |
|
1838 | 1854 | this.$node.on("mouseover", this.selectors.selectable, function() { |
1839 | 1855 | that.setCursor($(this)); |
1840 | 1856 | }); |
| 1857 | + this.$node.on("mouseleave", function() { |
| 1858 | + that._removeCursor(); |
| 1859 | + }); |
1841 | 1860 | _.each(this.datasets, function(dataset) { |
1842 | 1861 | dataset.onSync("asyncRequested", that._propagate, that).onSync("asyncCanceled", that._propagate, that).onSync("asyncReceived", that._propagate, that).onSync("rendered", that._onRendered, that).onSync("cleared", that._onCleared, that); |
1843 | 1862 | }); |
|
0 commit comments