Skip to content

Commit 17b4aa3

Browse files
authored
Merge pull request #95 from corejavascript/v1.0.0-beta
Changes for packaging up v1.0.0
2 parents a4015ff + f77755d commit 17b4aa3

10 files changed

+189
-79
lines changed

changelog.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
# Changelog
22

3-
### 0.11.2 TBD, 2015
4-
3+
### 1.0.0-beta November 10, 2016
4+
* Add diacritic-insensitive highlighting [#51](https://github.com/corejavascript/typeahead.js/pull/51)
5+
* Allow for custom setting of maxPendingRequests [#62](https://github.com/corejavascript/typeahead.js/pull/62)
6+
* Fix incorrect event arguments [#65](https://github.com/corejavascript/typeahead.js/pull/65)
7+
* Fix incorrect limit with remote [#52](https://github.com/corejavascript/typeahead.js/pull/52)
8+
* Implement edge ngram tokenizer for Bloodhound [#93](https://github.com/corejavascript/typeahead.js/pull/93)
9+
* Remove requirement to have bower when installing via NPM [#74](https://github.com/corejavascript/typeahead.js/pull/74)
10+
* Fix codestyle issues [#86](https://github.com/corejavascript/typeahead.js/pull/86)
11+
* Add PhantomJS as dev dependency [#87](https://github.com/corejavascript/typeahead.js/pull/87)
12+
* Remove cursor onMouseLeave [#90](https://github.com/corejavascript/typeahead.js/pull/90)
513
* Add matchAnyQueryToken option. [#2](https://github.com/corejavascript/typeahead.js/pull/2)
614
* Update rendered-count after async results have displayed. [#8](https://github.com/corejavascript/typeahead.js/pull/8)
715
* Add default on option to stop propagation when selecting an entry. [#13](https://github.com/corejavascript/typeahead.js/pull/13)
16+
* Fix link to contributing guidelines [#49](https://github.com/corejavascript/typeahead.js/pull/49)
17+
* Set cursor onHover [#28](https://github.com/corejavascript/typeahead.js/pull/28)
18+
* Complete to currently selected suggestion [#27](https://github.com/corejavascript/typeahead.js/pull/27)
19+
* Fix 404 links [#41](https://github.com/corejavascript/typeahead.js/pull/41)
20+
* Fix typos in comments in plugin.js [#37](https://github.com/corejavascript/typeahead.js/pull/37)
21+
* Update travis config to run latest supported node version [#25](https://github.com/corejavascript/typeahead.js/pull/25)
22+
* Update NPM package dependencies [#19](https://github.com/corejavascript/typeahead.js/pull/19)
23+
* Speed up Travis build [#22](https://github.com/corejavascript/typeahead.js/pull/22)
24+
* Fix npm error by adding license link [#18](https://github.com/corejavascript/typeahead.js/pull/18)
25+
* Move globally installed dependency [#16](https://github.com/corejavascript/typeahead.js/pull/16)
26+
827

928
### 0.11.1 April 26, 2015
1029

contributing.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
Contributing to typeahead.js
22
============================
33

4-
*These contributing guidelines were proudly stolen from the
4+
*These contributing guidelines were proudly stolen from the
55
[Flight](https://github.com/flightjs/flight) project*
66

7+
Project Status
8+
--------------
9+
The maintainers of this project welcome Pull Requests but, due to a lack of
10+
time, new major feature requests are unlikely to be taken on.
11+
712
Looking to contribute something to typeahead.js? Here's how you can help.
813

914
Bugs Reports
@@ -25,7 +30,7 @@ Guidelines for bug reports:
2530

2631
4. Please try to be as detailed as possible in your report. Include specific
2732
information about the environment – operating system and version, browser
28-
and version, version of typeahead.js – and steps required to reproduce the
33+
and version, version of typeahead.js – and steps required to reproduce the
2934
issue.
3035

3136
Feature Requests & Contribution Enquiries

dist/bloodhound.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* typeahead.js 0.11.1
2+
* typeahead.js 1.0.0
33
* https://github.com/twitter/typeahead.js
44
* Copyright 2013-2016 Twitter, Inc. and other contributors; Licensed MIT
55
*/
@@ -151,7 +151,7 @@
151151
noop: function() {}
152152
};
153153
}();
154-
var VERSION = "0.11.1";
154+
var VERSION = "1.0.0";
155155
var tokenizers = function() {
156156
"use strict";
157157
return {
@@ -356,17 +356,18 @@
356356
}();
357357
var Transport = function() {
358358
"use strict";
359-
var pendingRequestsCount = 0, pendingRequests = {}, maxPendingRequests = 6, sharedCache = new LruCache(10);
359+
var pendingRequestsCount = 0, pendingRequests = {}, sharedCache = new LruCache(10);
360360
function Transport(o) {
361361
o = o || {};
362+
this.maxPendingRequests = o.maxPendingRequests || 6;
362363
this.cancelled = false;
363364
this.lastReq = null;
364365
this._send = o.transport;
365366
this._get = o.limiter ? o.limiter(this._get) : this._get;
366367
this._cache = o.cache === false ? new LruCache(0) : sharedCache;
367368
}
368369
Transport.setMaxPendingRequests = function setMaxPendingRequests(num) {
369-
maxPendingRequests = num;
370+
this.maxPendingRequests = num;
370371
};
371372
Transport.resetCache = function resetCache() {
372373
sharedCache.reset();
@@ -384,7 +385,7 @@
384385
}
385386
if (jqXhr = pendingRequests[fingerprint]) {
386387
jqXhr.done(done).fail(fail);
387-
} else if (pendingRequestsCount < maxPendingRequests) {
388+
} else if (pendingRequestsCount < this.maxPendingRequests) {
388389
pendingRequestsCount++;
389390
pendingRequests[fingerprint] = this._send(o).done(done).fail(fail).always(always);
390391
} else {
@@ -636,7 +637,8 @@
636637
this.transport = new Transport({
637638
cache: o.cache,
638639
limiter: o.limiter,
639-
transport: o.transport
640+
transport: o.transport,
641+
maxPendingRequests: o.maxPendingRequests
640642
});
641643
}
642644
_.mixin(Remote.prototype, {

dist/bloodhound.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/typeahead.bundle.js

+73-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* typeahead.js 0.11.1
2+
* typeahead.js 1.0.0
33
* https://github.com/twitter/typeahead.js
44
* Copyright 2013-2016 Twitter, Inc. and other contributors; Licensed MIT
55
*/
@@ -151,7 +151,7 @@
151151
noop: function() {}
152152
};
153153
}();
154-
var VERSION = "0.11.1";
154+
var VERSION = "1.0.0";
155155
var tokenizers = function() {
156156
"use strict";
157157
return {
@@ -356,17 +356,18 @@
356356
}();
357357
var Transport = function() {
358358
"use strict";
359-
var pendingRequestsCount = 0, pendingRequests = {}, maxPendingRequests = 6, sharedCache = new LruCache(10);
359+
var pendingRequestsCount = 0, pendingRequests = {}, sharedCache = new LruCache(10);
360360
function Transport(o) {
361361
o = o || {};
362+
this.maxPendingRequests = o.maxPendingRequests || 6;
362363
this.cancelled = false;
363364
this.lastReq = null;
364365
this._send = o.transport;
365366
this._get = o.limiter ? o.limiter(this._get) : this._get;
366367
this._cache = o.cache === false ? new LruCache(0) : sharedCache;
367368
}
368369
Transport.setMaxPendingRequests = function setMaxPendingRequests(num) {
369-
maxPendingRequests = num;
370+
this.maxPendingRequests = num;
370371
};
371372
Transport.resetCache = function resetCache() {
372373
sharedCache.reset();
@@ -384,7 +385,7 @@
384385
}
385386
if (jqXhr = pendingRequests[fingerprint]) {
386387
jqXhr.done(done).fail(fail);
387-
} else if (pendingRequestsCount < maxPendingRequests) {
388+
} else if (pendingRequestsCount < this.maxPendingRequests) {
388389
pendingRequestsCount++;
389390
pendingRequests[fingerprint] = this._send(o).done(done).fail(fail).always(always);
390391
} else {
@@ -636,7 +637,8 @@
636637
this.transport = new Transport({
637638
cache: o.cache,
638639
limiter: o.limiter,
639-
transport: o.transport
640+
transport: o.transport,
641+
maxPendingRequests: o.maxPendingRequests
640642
});
641643
}
642644
_.mixin(Remote.prototype, {
@@ -1202,10 +1204,8 @@
12021204
}
12031205
_.mixin(EventBus.prototype, {
12041206
_trigger: function(type, args) {
1205-
var $e;
1206-
$e = $.Event(namespace + type);
1207-
(args = args || []).unshift($e);
1208-
this.$el.trigger.apply(this.$el, args);
1207+
var $e = $.Event(namespace + type);
1208+
this.$el.trigger.call(this.$el, $e, args || []);
12091209
return $e;
12101210
},
12111211
before: function(type) {
@@ -1322,7 +1322,36 @@
13221322
tagName: "strong",
13231323
className: null,
13241324
wordsOnly: false,
1325-
caseSensitive: false
1325+
caseSensitive: false,
1326+
diacriticInsensitive: false
1327+
};
1328+
var accented = {
1329+
A: "[AaªÀ-Åà-åĀ-ąǍǎȀ-ȃȦȧᴬᵃḀḁẚẠ-ảₐ℀℁℻⒜Ⓐⓐ㍱-㍴㎀-㎄㎈㎉㎩-㎯㏂㏊㏟㏿Aa]",
1330+
B: "[BbᴮᵇḂ-ḇℬ⒝Ⓑⓑ㍴㎅-㎇㏃㏈㏔㏝Bb]",
1331+
C: "[CcÇçĆ-čᶜ℀ℂ℃℅℆ℭⅭⅽ⒞Ⓒⓒ㍶㎈㎉㎝㎠㎤㏄-㏇Cc]",
1332+
D: "[DdĎďDŽ-džDZ-dzᴰᵈḊ-ḓⅅⅆⅮⅾ⒟Ⓓⓓ㋏㍲㍷-㍹㎗㎭-㎯㏅㏈Dd]",
1333+
E: "[EeÈ-Ëè-ëĒ-ěȄ-ȇȨȩᴱᵉḘ-ḛẸ-ẽₑ℡ℯℰⅇ⒠Ⓔⓔ㉐㋍㋎Ee]",
1334+
F: "[FfᶠḞḟ℉ℱ℻⒡Ⓕⓕ㎊-㎌㎙ff-fflFf]",
1335+
G: "[GgĜ-ģǦǧǴǵᴳᵍḠḡℊ⒢Ⓖⓖ㋌㋍㎇㎍-㎏㎓㎬㏆㏉㏒㏿Gg]",
1336+
H: "[HhĤĥȞȟʰᴴḢ-ḫẖℋ-ℎ⒣Ⓗⓗ㋌㍱㎐-㎔㏊㏋㏗Hh]",
1337+
I: "[IiÌ-Ïì-ïĨ-İIJijǏǐȈ-ȋᴵᵢḬḭỈ-ịⁱℐℑℹⅈⅠ-ⅣⅥ-ⅨⅪⅫⅰ-ⅳⅵ-ⅸⅺⅻ⒤Ⓘⓘ㍺㏌㏕fiffiIi]",
1338+
J: "[JjIJ-ĵLJ-njǰʲᴶⅉ⒥ⒿⓙⱼJj]",
1339+
K: "[KkĶķǨǩᴷᵏḰ-ḵK⒦Ⓚⓚ㎄㎅㎉㎏㎑㎘㎞㎢㎦㎪㎸㎾㏀㏆㏍-㏏Kk]",
1340+
L: "[LlĹ-ŀLJ-ljˡᴸḶḷḺ-ḽℒℓ℡Ⅼⅼ⒧Ⓛⓛ㋏㎈㎉㏐-㏓㏕㏖㏿flfflLl]",
1341+
M: "[MmᴹᵐḾ-ṃ℠™ℳⅯⅿ⒨Ⓜⓜ㍷-㍹㎃㎆㎎㎒㎖㎙-㎨㎫㎳㎷㎹㎽㎿㏁㏂㏎㏐㏔-㏖㏘㏙㏞㏟Mm]",
1342+
N: "[NnÑñŃ-ʼnNJ-njǸǹᴺṄ-ṋⁿℕ№⒩Ⓝⓝ㎁㎋㎚㎱㎵㎻㏌㏑Nn]",
1343+
O: "[OoºÒ-Öò-öŌ-őƠơǑǒǪǫȌ-ȏȮȯᴼᵒỌ-ỏₒ℅№ℴ⒪Ⓞⓞ㍵㏇㏒㏖Oo]",
1344+
P: "[PpᴾᵖṔ-ṗℙ⒫Ⓟⓟ㉐㍱㍶㎀㎊㎩-㎬㎰㎴㎺㏋㏗-㏚Pp]",
1345+
Q: "[Qqℚ⒬Ⓠⓠ㏃Qq]",
1346+
R: "[RrŔ-řȐ-ȓʳᴿᵣṘ-ṛṞṟ₨ℛ-ℝ⒭Ⓡⓡ㋍㍴㎭-㎯㏚㏛Rr]",
1347+
S: "[SsŚ-šſȘșˢṠ-ṣ₨℁℠⒮Ⓢⓢ㎧㎨㎮-㎳㏛㏜stSs]",
1348+
T: "[TtŢ-ťȚțᵀᵗṪ-ṱẗ℡™⒯Ⓣⓣ㉐㋏㎔㏏ſtstTt]",
1349+
U: "[UuÙ-Üù-üŨ-ųƯưǓǔȔ-ȗᵁᵘᵤṲ-ṷỤ-ủ℆⒰Ⓤⓤ㍳㍺Uu]",
1350+
V: "[VvᵛᵥṼ-ṿⅣ-Ⅷⅳ-ⅷ⒱Ⓥⓥⱽ㋎㍵㎴-㎹㏜㏞Vv]",
1351+
W: "[WwŴŵʷᵂẀ-ẉẘ⒲Ⓦⓦ㎺-㎿㏝Ww]",
1352+
X: "[XxˣẊ-ẍₓ℻Ⅸ-Ⅻⅸ-ⅻ⒳Ⓧⓧ㏓Xx]",
1353+
Y: "[YyÝýÿŶ-ŸȲȳʸẎẏẙỲ-ỹ⒴Ⓨⓨ㏉Yy]",
1354+
Z: "[ZzŹ-žDZ-dzᶻẐ-ẕℤℨ⒵Ⓩⓩ㎐-㎔Zz]"
13261355
};
13271356
return function hightlight(o) {
13281357
var regex;
@@ -1331,7 +1360,7 @@
13311360
return;
13321361
}
13331362
o.pattern = _.isArray(o.pattern) ? o.pattern : [ o.pattern ];
1334-
regex = getRegex(o.pattern, o.caseSensitive, o.wordsOnly);
1363+
regex = getRegex(o.pattern, o.caseSensitive, o.wordsOnly, o.diacriticInsensitive);
13351364
traverse(o.node, hightlightTextNode);
13361365
function hightlightTextNode(textNode) {
13371366
var match, patternNode, wrapperNode;
@@ -1357,10 +1386,17 @@
13571386
}
13581387
}
13591388
};
1360-
function getRegex(patterns, caseSensitive, wordsOnly) {
1389+
function accent_replacer(chr) {
1390+
return accented[chr.toUpperCase()] || chr;
1391+
}
1392+
function getRegex(patterns, caseSensitive, wordsOnly, diacriticInsensitive) {
13611393
var escapedPatterns = [], regexStr;
13621394
for (var i = 0, len = patterns.length; i < len; i++) {
1363-
escapedPatterns.push(_.escapeRegExChars(patterns[i]));
1395+
var escapedWord = _.escapeRegExChars(patterns[i]);
1396+
if (diacriticInsensitive) {
1397+
escapedWord = escapedWord.replace(/\S/g, accent_replacer);
1398+
}
1399+
escapedPatterns.push(escapedWord);
13641400
}
13651401
regexStr = wordsOnly ? "\\b(" + escapedPatterns.join("|") + ")\\b" : "(" + escapedPatterns.join("|") + ")";
13661402
return caseSensitive ? new RegExp(regexStr) : new RegExp(regexStr, "i");
@@ -1585,6 +1621,7 @@
15851621
"use strict";
15861622
var keys, nameGenerator;
15871623
keys = {
1624+
dataset: "tt-selectable-dataset",
15881625
val: "tt-selectable-display",
15891626
obj: "tt-selectable-object"
15901627
};
@@ -1604,7 +1641,7 @@
16041641
}
16051642
www.mixin(this);
16061643
this.highlight = !!o.highlight;
1607-
this.name = o.name || nameGenerator();
1644+
this.name = _.toStr(o.name || nameGenerator());
16081645
this.limit = o.limit || 5;
16091646
this.displayFn = getDisplayFn(o.display || o.displayKey);
16101647
this.templates = getTemplates(o.templates, this.displayFn);
@@ -1617,6 +1654,7 @@
16171654
var $el = $(el);
16181655
if ($el.data(keys.obj)) {
16191656
return {
1657+
dataset: $el.data(keys.dataset) || "",
16201658
val: $el.data(keys.val) || "",
16211659
obj: $el.data(keys.obj) || null
16221660
};
@@ -1635,7 +1673,7 @@
16351673
} else {
16361674
this._empty();
16371675
}
1638-
this.trigger("rendered", this.name, suggestions, false);
1676+
this.trigger("rendered", suggestions, false, this.name);
16391677
},
16401678
_append: function append(query, suggestions) {
16411679
suggestions = suggestions || [];
@@ -1646,7 +1684,7 @@
16461684
} else if (!this.$lastSuggestion.length && this.templates.notFound) {
16471685
this._renderNotFound(query);
16481686
}
1649-
this.trigger("rendered", this.name, suggestions, true);
1687+
this.trigger("rendered", suggestions, true, this.name);
16501688
},
16511689
_renderSuggestions: function renderSuggestions(query, suggestions) {
16521690
var $fragment;
@@ -1687,7 +1725,7 @@
16871725
_.each(suggestions, function getSuggestionNode(suggestion) {
16881726
var $el, context;
16891727
context = that._injectQuery(query, suggestion);
1690-
$el = $(that.templates.suggestion(context)).data(keys.obj, suggestion).data(keys.val, that.displayFn(suggestion)).addClass(that.classes.suggestion + " " + that.classes.selectable);
1728+
$el = $(that.templates.suggestion(context)).data(keys.dataset, that.name).data(keys.obj, suggestion).data(keys.val, that.displayFn(suggestion)).addClass(that.classes.suggestion + " " + that.classes.selectable);
16911729
fragment.appendChild($el[0]);
16921730
});
16931731
this.highlight && highlight({
@@ -1725,7 +1763,7 @@
17251763
this.cancel = function cancel() {
17261764
canceled = true;
17271765
that.cancel = $.noop;
1728-
that.async && that.trigger("asyncCanceled", query);
1766+
that.async && that.trigger("asyncCanceled", query, that.name);
17291767
};
17301768
this.source(query, sync, async);
17311769
!syncCalled && sync([]);
@@ -1738,7 +1776,7 @@
17381776
rendered = suggestions.length;
17391777
that._overwrite(query, suggestions);
17401778
if (rendered < that.limit && that.async) {
1741-
that.trigger("asyncRequested", query);
1779+
that.trigger("asyncRequested", query, that.name);
17421780
}
17431781
}
17441782
function async(suggestions) {
@@ -1748,7 +1786,7 @@
17481786
var idx = Math.abs(rendered - that.limit);
17491787
rendered += idx;
17501788
that._append(query, suggestions.slice(0, idx));
1751-
that.async && that.trigger("asyncReceived", query);
1789+
that.async && that.trigger("asyncReceived", query, that.name);
17521790
}
17531791
}
17541792
},
@@ -2044,7 +2082,7 @@
20442082
_onDatasetCleared: function onDatasetCleared() {
20452083
this._updateHint();
20462084
},
2047-
_onDatasetRendered: function onDatasetRendered(type, dataset, suggestions, async) {
2085+
_onDatasetRendered: function onDatasetRendered(type, suggestions, async, dataset) {
20482086
this._updateHint();
20492087
this.eventBus.trigger("render", suggestions, async, dataset);
20502088
},
@@ -2068,7 +2106,10 @@
20682106
_onEnterKeyed: function onEnterKeyed(type, $e) {
20692107
var $selectable;
20702108
if ($selectable = this.menu.getActiveSelectable()) {
2071-
this.select($selectable) && $e.preventDefault();
2109+
if (this.select($selectable)) {
2110+
$e.preventDefault();
2111+
$e.stopPropagation();
2112+
}
20722113
}
20732114
},
20742115
_onTabKeyed: function onTabKeyed(type, $e) {
@@ -2195,9 +2236,9 @@
21952236
},
21962237
select: function select($selectable) {
21972238
var data = this.menu.getSelectableData($selectable);
2198-
if (data && !this.eventBus.before("select", data.obj)) {
2239+
if (data && !this.eventBus.before("select", data.obj, data.dataset)) {
21992240
this.input.setQuery(data.val, true);
2200-
this.eventBus.trigger("select", data.obj);
2241+
this.eventBus.trigger("select", data.obj, data.dataset);
22012242
this.close();
22022243
return true;
22032244
}
@@ -2208,29 +2249,30 @@
22082249
query = this.input.getQuery();
22092250
data = this.menu.getSelectableData($selectable);
22102251
isValid = data && query !== data.val;
2211-
if (isValid && !this.eventBus.before("autocomplete", data.obj)) {
2252+
if (isValid && !this.eventBus.before("autocomplete", data.obj, data.dataset)) {
22122253
this.input.setQuery(data.val);
2213-
this.eventBus.trigger("autocomplete", data.obj);
2254+
this.eventBus.trigger("autocomplete", data.obj, data.dataset);
22142255
return true;
22152256
}
22162257
return false;
22172258
},
22182259
moveCursor: function moveCursor(delta) {
2219-
var query, $candidate, data, payload, cancelMove;
2260+
var query, $candidate, data, suggestion, datasetName, cancelMove;
22202261
query = this.input.getQuery();
22212262
$candidate = this.menu.selectableRelativeToCursor(delta);
22222263
data = this.menu.getSelectableData($candidate);
2223-
payload = data ? data.obj : null;
2264+
suggestion = data ? data.obj : null;
2265+
datasetName = data ? data.dataset : null;
22242266
cancelMove = this._minLengthMet() && this.menu.update(query);
2225-
if (!cancelMove && !this.eventBus.before("cursorchange", payload)) {
2267+
if (!cancelMove && !this.eventBus.before("cursorchange", suggestion, datasetName)) {
22262268
this.menu.setCursor($candidate);
22272269
if (data) {
22282270
this.input.setInputValue(data.val);
22292271
} else {
22302272
this.input.resetInputValue();
22312273
this._updateHint();
22322274
}
2233-
this.eventBus.trigger("cursorchange", payload);
2275+
this.eventBus.trigger("cursorchange", suggestion, datasetName);
22342276
return true;
22352277
}
22362278
return false;

0 commit comments

Comments
 (0)