Skip to content

Commit

Permalink
0.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Harding committed Apr 27, 2015
1 parent e4d6fbf commit 588440f
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 62 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "typeahead.js",
"version": "0.11.0",
"version": "0.11.1",
"main": "dist/typeahead.bundle.js",
"dependencies": {
"jquery": ">=1.7"
Expand Down
58 changes: 38 additions & 20 deletions dist/bloodhound.js
@@ -1,5 +1,5 @@
/*!
* typeahead.js 0.11.0
* typeahead.js 0.11.1
* https://github.com/twitter/typeahead.js
* Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT
*/
Expand Down Expand Up @@ -151,7 +151,7 @@
noop: function() {}
};
}();
var VERSION = "0.11.0";
var VERSION = "0.11.1";
var tokenizers = function() {
"use strict";
return {
Expand All @@ -171,11 +171,11 @@
return str ? str.split(/\W+/) : [];
}
function getObjTokenizer(tokenizer) {
return function setKey() {
var args = [].slice.call(arguments, 0);
return function setKey(keys) {
keys = _.isArray(keys) ? keys : [].slice.call(arguments, 0);
return function tokenize(o) {
var tokens = [];
_.each(args, function(k) {
_.each(keys, function(k) {
tokens = tokens.concat(tokenizer(_.toStr(o[k])));
});
return tokens;
Expand Down Expand Up @@ -266,9 +266,7 @@
this.ttlKey = "__ttl__";
this.keyMatcher = new RegExp("^" + _.escapeRegExChars(this.prefix));
this.ls = override || LOCAL_STORAGE;
if (!this.ls || !window.JSON) {
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
}
!this.ls && this._noop();
}
_.mixin(PersistentStorage.prototype, {
_prefix: function(key) {
Expand All @@ -277,6 +275,19 @@
_ttlKey: function(key) {
return this._prefix(key) + this.ttlKey;
},
_noop: function() {
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
},
_safeSet: function(key, val) {
try {
this.ls.setItem(key, val);
} catch (err) {
if (err.name === "QuotaExceededError") {
this.clear();
this._noop();
}
}
},
get: function(key) {
if (this.isExpired(key)) {
this.remove(key);
Expand All @@ -285,24 +296,19 @@
},
set: function(key, val, ttl) {
if (_.isNumber(ttl)) {
this.ls.setItem(this._ttlKey(key), encode(now() + ttl));
this._safeSet(this._ttlKey(key), encode(now() + ttl));
} else {
this.ls.removeItem(this._ttlKey(key));
}
return this.ls.setItem(this._prefix(key), encode(val));
return this._safeSet(this._prefix(key), encode(val));
},
remove: function(key) {
this.ls.removeItem(this._ttlKey(key));
this.ls.removeItem(this._prefix(key));
return this;
},
clear: function() {
var i, key, keys = [], len = this.ls.length;
for (i = 0; i < len; i++) {
if ((key = this.ls.key(i)).match(this.keyMatcher)) {
keys.push(key.replace(this.keyMatcher, ""));
}
}
var i, keys = gatherMatchingKeys(this.keyMatcher);
for (i = keys.length; i--; ) {
this.remove(keys[i]);
}
Expand All @@ -323,6 +329,15 @@
function decode(val) {
return $.parseJSON(val);
}
function gatherMatchingKeys(keyMatcher) {
var i, key, keys = [], len = LOCAL_STORAGE.length;
for (i = 0; i < len; i++) {
if ((key = LOCAL_STORAGE.key(i)).match(keyMatcher)) {
keys.push(key.replace(keyMatcher, ""));
}
}
return keys;
}
}();
var Transport = function() {
"use strict";
Expand Down Expand Up @@ -539,6 +554,7 @@
this.url = o.url;
this.ttl = o.ttl;
this.cache = o.cache;
this.prepare = o.prepare;
this.transform = o.transform;
this.transport = o.transport;
this.thumbprint = o.thumbprint;
Expand Down Expand Up @@ -572,11 +588,12 @@
return stored.data && !isExpired ? stored.data : null;
},
fromNetwork: function(cb) {
var that = this;
var that = this, settings;
if (!cb) {
return;
}
this.transport(this._settings()).fail(onError).done(onResponse);
settings = this.prepare(this._settings());
this.transport(settings).fail(onError).done(onResponse);
function onError() {
cb(true);
}
Expand Down Expand Up @@ -667,6 +684,7 @@
cache: true,
cacheKey: null,
thumbprint: "",
prepare: _.identity,
transform: _.identity,
transport: null
};
Expand Down Expand Up @@ -704,7 +722,7 @@
o = _.mixin(defaults, o);
!o.url && $.error("remote requires url to be set");
o.transform = o.filter || o.transform;
o.prepare = toPrepare(o);
o.prepare = toRemotePrepare(o);
o.limiter = toLimiter(o);
o.transport = o.transport ? callbackToDeferred(o.transport) : $.ajax;
delete o.replace;
Expand All @@ -713,7 +731,7 @@
delete o.rateLimitWait;
return o;
}
function toPrepare(o) {
function toRemotePrepare(o) {
var prepare, replace, wildcard;
prepare = o.prepare;
replace = o.replace;
Expand Down
4 changes: 2 additions & 2 deletions dist/bloodhound.min.js

Large diffs are not rendered by default.

68 changes: 43 additions & 25 deletions dist/typeahead.bundle.js
@@ -1,5 +1,5 @@
/*!
* typeahead.js 0.11.0
* typeahead.js 0.11.1
* https://github.com/twitter/typeahead.js
* Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT
*/
Expand Down Expand Up @@ -151,7 +151,7 @@
noop: function() {}
};
}();
var VERSION = "0.11.0";
var VERSION = "0.11.1";
var tokenizers = function() {
"use strict";
return {
Expand All @@ -171,11 +171,11 @@
return str ? str.split(/\W+/) : [];
}
function getObjTokenizer(tokenizer) {
return function setKey() {
var args = [].slice.call(arguments, 0);
return function setKey(keys) {
keys = _.isArray(keys) ? keys : [].slice.call(arguments, 0);
return function tokenize(o) {
var tokens = [];
_.each(args, function(k) {
_.each(keys, function(k) {
tokens = tokens.concat(tokenizer(_.toStr(o[k])));
});
return tokens;
Expand Down Expand Up @@ -266,9 +266,7 @@
this.ttlKey = "__ttl__";
this.keyMatcher = new RegExp("^" + _.escapeRegExChars(this.prefix));
this.ls = override || LOCAL_STORAGE;
if (!this.ls || !window.JSON) {
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
}
!this.ls && this._noop();
}
_.mixin(PersistentStorage.prototype, {
_prefix: function(key) {
Expand All @@ -277,6 +275,19 @@
_ttlKey: function(key) {
return this._prefix(key) + this.ttlKey;
},
_noop: function() {
this.get = this.set = this.remove = this.clear = this.isExpired = _.noop;
},
_safeSet: function(key, val) {
try {
this.ls.setItem(key, val);
} catch (err) {
if (err.name === "QuotaExceededError") {
this.clear();
this._noop();
}
}
},
get: function(key) {
if (this.isExpired(key)) {
this.remove(key);
Expand All @@ -285,24 +296,19 @@
},
set: function(key, val, ttl) {
if (_.isNumber(ttl)) {
this.ls.setItem(this._ttlKey(key), encode(now() + ttl));
this._safeSet(this._ttlKey(key), encode(now() + ttl));
} else {
this.ls.removeItem(this._ttlKey(key));
}
return this.ls.setItem(this._prefix(key), encode(val));
return this._safeSet(this._prefix(key), encode(val));
},
remove: function(key) {
this.ls.removeItem(this._ttlKey(key));
this.ls.removeItem(this._prefix(key));
return this;
},
clear: function() {
var i, key, keys = [], len = this.ls.length;
for (i = 0; i < len; i++) {
if ((key = this.ls.key(i)).match(this.keyMatcher)) {
keys.push(key.replace(this.keyMatcher, ""));
}
}
var i, keys = gatherMatchingKeys(this.keyMatcher);
for (i = keys.length; i--; ) {
this.remove(keys[i]);
}
Expand All @@ -323,6 +329,15 @@
function decode(val) {
return $.parseJSON(val);
}
function gatherMatchingKeys(keyMatcher) {
var i, key, keys = [], len = LOCAL_STORAGE.length;
for (i = 0; i < len; i++) {
if ((key = LOCAL_STORAGE.key(i)).match(keyMatcher)) {
keys.push(key.replace(keyMatcher, ""));
}
}
return keys;
}
}();
var Transport = function() {
"use strict";
Expand Down Expand Up @@ -539,6 +554,7 @@
this.url = o.url;
this.ttl = o.ttl;
this.cache = o.cache;
this.prepare = o.prepare;
this.transform = o.transform;
this.transport = o.transport;
this.thumbprint = o.thumbprint;
Expand Down Expand Up @@ -572,11 +588,12 @@
return stored.data && !isExpired ? stored.data : null;
},
fromNetwork: function(cb) {
var that = this;
var that = this, settings;
if (!cb) {
return;
}
this.transport(this._settings()).fail(onError).done(onResponse);
settings = this.prepare(this._settings());
this.transport(settings).fail(onError).done(onResponse);
function onError() {
cb(true);
}
Expand Down Expand Up @@ -667,6 +684,7 @@
cache: true,
cacheKey: null,
thumbprint: "",
prepare: _.identity,
transform: _.identity,
transport: null
};
Expand Down Expand Up @@ -704,7 +722,7 @@
o = _.mixin(defaults, o);
!o.url && $.error("remote requires url to be set");
o.transform = o.filter || o.transform;
o.prepare = toPrepare(o);
o.prepare = toRemotePrepare(o);
o.limiter = toLimiter(o);
o.transport = o.transport ? callbackToDeferred(o.transport) : $.ajax;
delete o.replace;
Expand All @@ -713,7 +731,7 @@
delete o.rateLimitWait;
return o;
}
function toPrepare(o) {
function toRemotePrepare(o) {
var prepare, replace, wildcard;
prepare = o.prepare;
replace = o.replace;
Expand Down Expand Up @@ -1352,7 +1370,7 @@
}
}
Input.normalizeQuery = function(str) {
return (str || "").replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
return _.toStr(str).replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
};
_.mixin(Input.prototype, EventEmitter, {
_onBlur: function onBlur() {
Expand Down Expand Up @@ -1510,7 +1528,7 @@
this.$hint.off(".tt");
this.$input.off(".tt");
this.$overflowHelper.remove();
this.$hint = this.$input = this.$overflowHelper = null;
this.$hint = this.$input = this.$overflowHelper = $("<div>");
}
});
return Input;
Expand Down Expand Up @@ -1718,7 +1736,7 @@
return this.$el.is(":empty");
},
destroy: function destroy() {
this.$el = null;
this.$el = $("<div>");
}
});
return Dataset;
Expand All @@ -1738,7 +1756,7 @@
suggestion: templates.suggestion || suggestionTemplate
};
function suggestionTemplate(context) {
return "<div><p>" + displayFn(context) + "</p></div>";
return $("<div>").text(displayFn(context));
}
}
function isValidName(str) {
Expand Down Expand Up @@ -1874,7 +1892,7 @@
},
destroy: function destroy() {
this.$node.off(".tt");
this.$node = null;
this.$node = $("<div>");
_.each(this.datasets, destroyDataset);
function destroyDataset(dataset) {
dataset.destroy();
Expand Down
6 changes: 3 additions & 3 deletions dist/typeahead.bundle.min.js

Large diffs are not rendered by default.

0 comments on commit 588440f

Please sign in to comment.