Skip to content

Commit 588440f

Browse files
author
Jake Harding
committed
0.11.1
1 parent e4d6fbf commit 588440f

File tree

9 files changed

+98
-62
lines changed

9 files changed

+98
-62
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typeahead.js",
3-
"version": "0.11.0",
3+
"version": "0.11.1",
44
"main": "dist/typeahead.bundle.js",
55
"dependencies": {
66
"jquery": ">=1.7"

dist/bloodhound.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* typeahead.js 0.11.0
2+
* typeahead.js 0.11.1
33
* https://github.com/twitter/typeahead.js
44
* Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT
55
*/
@@ -151,7 +151,7 @@
151151
noop: function() {}
152152
};
153153
}();
154-
var VERSION = "0.11.0";
154+
var VERSION = "0.11.1";
155155
var tokenizers = function() {
156156
"use strict";
157157
return {
@@ -171,11 +171,11 @@
171171
return str ? str.split(/\W+/) : [];
172172
}
173173
function getObjTokenizer(tokenizer) {
174-
return function setKey() {
175-
var args = [].slice.call(arguments, 0);
174+
return function setKey(keys) {
175+
keys = _.isArray(keys) ? keys : [].slice.call(arguments, 0);
176176
return function tokenize(o) {
177177
var tokens = [];
178-
_.each(args, function(k) {
178+
_.each(keys, function(k) {
179179
tokens = tokens.concat(tokenizer(_.toStr(o[k])));
180180
});
181181
return tokens;
@@ -266,9 +266,7 @@
266266
this.ttlKey = "__ttl__";
267267
this.keyMatcher = new RegExp("^" + _.escapeRegExChars(this.prefix));
268268
this.ls = override || LOCAL_STORAGE;
269-
if (!this.ls || !window.JSON) {
270-
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
271-
}
269+
!this.ls && this._noop();
272270
}
273271
_.mixin(PersistentStorage.prototype, {
274272
_prefix: function(key) {
@@ -277,6 +275,19 @@
277275
_ttlKey: function(key) {
278276
return this._prefix(key) + this.ttlKey;
279277
},
278+
_noop: function() {
279+
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
280+
},
281+
_safeSet: function(key, val) {
282+
try {
283+
this.ls.setItem(key, val);
284+
} catch (err) {
285+
if (err.name === "QuotaExceededError") {
286+
this.clear();
287+
this._noop();
288+
}
289+
}
290+
},
280291
get: function(key) {
281292
if (this.isExpired(key)) {
282293
this.remove(key);
@@ -285,24 +296,19 @@
285296
},
286297
set: function(key, val, ttl) {
287298
if (_.isNumber(ttl)) {
288-
this.ls.setItem(this._ttlKey(key), encode(now() + ttl));
299+
this._safeSet(this._ttlKey(key), encode(now() + ttl));
289300
} else {
290301
this.ls.removeItem(this._ttlKey(key));
291302
}
292-
return this.ls.setItem(this._prefix(key), encode(val));
303+
return this._safeSet(this._prefix(key), encode(val));
293304
},
294305
remove: function(key) {
295306
this.ls.removeItem(this._ttlKey(key));
296307
this.ls.removeItem(this._prefix(key));
297308
return this;
298309
},
299310
clear: function() {
300-
var i, key, keys = [], len = this.ls.length;
301-
for (i = 0; i < len; i++) {
302-
if ((key = this.ls.key(i)).match(this.keyMatcher)) {
303-
keys.push(key.replace(this.keyMatcher, ""));
304-
}
305-
}
311+
var i, keys = gatherMatchingKeys(this.keyMatcher);
306312
for (i = keys.length; i--; ) {
307313
this.remove(keys[i]);
308314
}
@@ -323,6 +329,15 @@
323329
function decode(val) {
324330
return $.parseJSON(val);
325331
}
332+
function gatherMatchingKeys(keyMatcher) {
333+
var i, key, keys = [], len = LOCAL_STORAGE.length;
334+
for (i = 0; i < len; i++) {
335+
if ((key = LOCAL_STORAGE.key(i)).match(keyMatcher)) {
336+
keys.push(key.replace(keyMatcher, ""));
337+
}
338+
}
339+
return keys;
340+
}
326341
}();
327342
var Transport = function() {
328343
"use strict";
@@ -539,6 +554,7 @@
539554
this.url = o.url;
540555
this.ttl = o.ttl;
541556
this.cache = o.cache;
557+
this.prepare = o.prepare;
542558
this.transform = o.transform;
543559
this.transport = o.transport;
544560
this.thumbprint = o.thumbprint;
@@ -572,11 +588,12 @@
572588
return stored.data && !isExpired ? stored.data : null;
573589
},
574590
fromNetwork: function(cb) {
575-
var that = this;
591+
var that = this, settings;
576592
if (!cb) {
577593
return;
578594
}
579-
this.transport(this._settings()).fail(onError).done(onResponse);
595+
settings = this.prepare(this._settings());
596+
this.transport(settings).fail(onError).done(onResponse);
580597
function onError() {
581598
cb(true);
582599
}
@@ -667,6 +684,7 @@
667684
cache: true,
668685
cacheKey: null,
669686
thumbprint: "",
687+
prepare: _.identity,
670688
transform: _.identity,
671689
transport: null
672690
};
@@ -704,7 +722,7 @@
704722
o = _.mixin(defaults, o);
705723
!o.url && $.error("remote requires url to be set");
706724
o.transform = o.filter || o.transform;
707-
o.prepare = toPrepare(o);
725+
o.prepare = toRemotePrepare(o);
708726
o.limiter = toLimiter(o);
709727
o.transport = o.transport ? callbackToDeferred(o.transport) : $.ajax;
710728
delete o.replace;
@@ -713,7 +731,7 @@
713731
delete o.rateLimitWait;
714732
return o;
715733
}
716-
function toPrepare(o) {
734+
function toRemotePrepare(o) {
717735
var prepare, replace, wildcard;
718736
prepare = o.prepare;
719737
replace = o.replace;

dist/bloodhound.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/typeahead.bundle.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* typeahead.js 0.11.0
2+
* typeahead.js 0.11.1
33
* https://github.com/twitter/typeahead.js
44
* Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT
55
*/
@@ -151,7 +151,7 @@
151151
noop: function() {}
152152
};
153153
}();
154-
var VERSION = "0.11.0";
154+
var VERSION = "0.11.1";
155155
var tokenizers = function() {
156156
"use strict";
157157
return {
@@ -171,11 +171,11 @@
171171
return str ? str.split(/\W+/) : [];
172172
}
173173
function getObjTokenizer(tokenizer) {
174-
return function setKey() {
175-
var args = [].slice.call(arguments, 0);
174+
return function setKey(keys) {
175+
keys = _.isArray(keys) ? keys : [].slice.call(arguments, 0);
176176
return function tokenize(o) {
177177
var tokens = [];
178-
_.each(args, function(k) {
178+
_.each(keys, function(k) {
179179
tokens = tokens.concat(tokenizer(_.toStr(o[k])));
180180
});
181181
return tokens;
@@ -266,9 +266,7 @@
266266
this.ttlKey = "__ttl__";
267267
this.keyMatcher = new RegExp("^" + _.escapeRegExChars(this.prefix));
268268
this.ls = override || LOCAL_STORAGE;
269-
if (!this.ls || !window.JSON) {
270-
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
271-
}
269+
!this.ls && this._noop();
272270
}
273271
_.mixin(PersistentStorage.prototype, {
274272
_prefix: function(key) {
@@ -277,6 +275,19 @@
277275
_ttlKey: function(key) {
278276
return this._prefix(key) + this.ttlKey;
279277
},
278+
_noop: function() {
279+
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
280+
},
281+
_safeSet: function(key, val) {
282+
try {
283+
this.ls.setItem(key, val);
284+
} catch (err) {
285+
if (err.name === "QuotaExceededError") {
286+
this.clear();
287+
this._noop();
288+
}
289+
}
290+
},
280291
get: function(key) {
281292
if (this.isExpired(key)) {
282293
this.remove(key);
@@ -285,24 +296,19 @@
285296
},
286297
set: function(key, val, ttl) {
287298
if (_.isNumber(ttl)) {
288-
this.ls.setItem(this._ttlKey(key), encode(now() + ttl));
299+
this._safeSet(this._ttlKey(key), encode(now() + ttl));
289300
} else {
290301
this.ls.removeItem(this._ttlKey(key));
291302
}
292-
return this.ls.setItem(this._prefix(key), encode(val));
303+
return this._safeSet(this._prefix(key), encode(val));
293304
},
294305
remove: function(key) {
295306
this.ls.removeItem(this._ttlKey(key));
296307
this.ls.removeItem(this._prefix(key));
297308
return this;
298309
},
299310
clear: function() {
300-
var i, key, keys = [], len = this.ls.length;
301-
for (i = 0; i < len; i++) {
302-
if ((key = this.ls.key(i)).match(this.keyMatcher)) {
303-
keys.push(key.replace(this.keyMatcher, ""));
304-
}
305-
}
311+
var i, keys = gatherMatchingKeys(this.keyMatcher);
306312
for (i = keys.length; i--; ) {
307313
this.remove(keys[i]);
308314
}
@@ -323,6 +329,15 @@
323329
function decode(val) {
324330
return $.parseJSON(val);
325331
}
332+
function gatherMatchingKeys(keyMatcher) {
333+
var i, key, keys = [], len = LOCAL_STORAGE.length;
334+
for (i = 0; i < len; i++) {
335+
if ((key = LOCAL_STORAGE.key(i)).match(keyMatcher)) {
336+
keys.push(key.replace(keyMatcher, ""));
337+
}
338+
}
339+
return keys;
340+
}
326341
}();
327342
var Transport = function() {
328343
"use strict";
@@ -539,6 +554,7 @@
539554
this.url = o.url;
540555
this.ttl = o.ttl;
541556
this.cache = o.cache;
557+
this.prepare = o.prepare;
542558
this.transform = o.transform;
543559
this.transport = o.transport;
544560
this.thumbprint = o.thumbprint;
@@ -572,11 +588,12 @@
572588
return stored.data && !isExpired ? stored.data : null;
573589
},
574590
fromNetwork: function(cb) {
575-
var that = this;
591+
var that = this, settings;
576592
if (!cb) {
577593
return;
578594
}
579-
this.transport(this._settings()).fail(onError).done(onResponse);
595+
settings = this.prepare(this._settings());
596+
this.transport(settings).fail(onError).done(onResponse);
580597
function onError() {
581598
cb(true);
582599
}
@@ -667,6 +684,7 @@
667684
cache: true,
668685
cacheKey: null,
669686
thumbprint: "",
687+
prepare: _.identity,
670688
transform: _.identity,
671689
transport: null
672690
};
@@ -704,7 +722,7 @@
704722
o = _.mixin(defaults, o);
705723
!o.url && $.error("remote requires url to be set");
706724
o.transform = o.filter || o.transform;
707-
o.prepare = toPrepare(o);
725+
o.prepare = toRemotePrepare(o);
708726
o.limiter = toLimiter(o);
709727
o.transport = o.transport ? callbackToDeferred(o.transport) : $.ajax;
710728
delete o.replace;
@@ -713,7 +731,7 @@
713731
delete o.rateLimitWait;
714732
return o;
715733
}
716-
function toPrepare(o) {
734+
function toRemotePrepare(o) {
717735
var prepare, replace, wildcard;
718736
prepare = o.prepare;
719737
replace = o.replace;
@@ -1352,7 +1370,7 @@
13521370
}
13531371
}
13541372
Input.normalizeQuery = function(str) {
1355-
return (str || "").replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
1373+
return _.toStr(str).replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
13561374
};
13571375
_.mixin(Input.prototype, EventEmitter, {
13581376
_onBlur: function onBlur() {
@@ -1510,7 +1528,7 @@
15101528
this.$hint.off(".tt");
15111529
this.$input.off(".tt");
15121530
this.$overflowHelper.remove();
1513-
this.$hint = this.$input = this.$overflowHelper = null;
1531+
this.$hint = this.$input = this.$overflowHelper = $("<div>");
15141532
}
15151533
});
15161534
return Input;
@@ -1718,7 +1736,7 @@
17181736
return this.$el.is(":empty");
17191737
},
17201738
destroy: function destroy() {
1721-
this.$el = null;
1739+
this.$el = $("<div>");
17221740
}
17231741
});
17241742
return Dataset;
@@ -1738,7 +1756,7 @@
17381756
suggestion: templates.suggestion || suggestionTemplate
17391757
};
17401758
function suggestionTemplate(context) {
1741-
return "<div><p>" + displayFn(context) + "</p></div>";
1759+
return $("<div>").text(displayFn(context));
17421760
}
17431761
}
17441762
function isValidName(str) {
@@ -1874,7 +1892,7 @@
18741892
},
18751893
destroy: function destroy() {
18761894
this.$node.off(".tt");
1877-
this.$node = null;
1895+
this.$node = $("<div>");
18781896
_.each(this.datasets, destroyDataset);
18791897
function destroyDataset(dataset) {
18801898
dataset.destroy();

dist/typeahead.bundle.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)