diff --git a/Gruntfile.js b/Gruntfile.js index e90abec60f..a4a1ac6417 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,42 +2,40 @@ var semver = require('semver'), f = require('util').format, files = { common: [ - 'src/common/utils.js' + 'src/common/utils.js' ], bloodhound: [ - 'src/bloodhound/version.js', - 'src/bloodhound/tokenizers.js', - 'src/bloodhound/lru_cache.js', - 'src/bloodhound/persistent_storage.js', - 'src/bloodhound/transport.js', - 'src/bloodhound/search_index.js', - 'src/bloodhound/prefetch.js', - 'src/bloodhound/remote.js', - 'src/bloodhound/options_parser.js', - 'src/bloodhound/bloodhound.js' + 'src/bloodhound/version.js', + 'src/bloodhound/tokenizers.js', + 'src/bloodhound/lru_cache.js', + 'src/bloodhound/persistent_storage.js', + 'src/bloodhound/transport.js', + 'src/bloodhound/search_index.js', + 'src/bloodhound/prefetch.js', + 'src/bloodhound/remote.js', + 'src/bloodhound/options_parser.js', + 'src/bloodhound/bloodhound.js' ], typeahead: [ - 'src/typeahead/www.js', - 'src/typeahead/event_bus.js', - 'src/typeahead/event_emitter.js', - 'src/typeahead/highlight.js', - 'src/typeahead/input.js', - 'src/typeahead/dataset.js', - 'src/typeahead/menu.js', - 'src/typeahead/status.js', - 'src/typeahead/default_menu.js', - 'src/typeahead/typeahead.js', - 'src/typeahead/plugin.js' + 'src/typeahead/www.js', + 'src/typeahead/event_bus.js', + 'src/typeahead/event_emitter.js', + 'src/typeahead/highlight.js', + 'src/typeahead/input.js', + 'src/typeahead/dataset.js', + 'src/typeahead/menu.js', + 'src/typeahead/status.js', + 'src/typeahead/default_menu.js', + 'src/typeahead/typeahead.js', + 'src/typeahead/plugin.js' ] }; module.exports = function(grunt) { grunt.initConfig({ version: grunt.file.readJSON('package.json').version, - tempDir: 'dist_temp', buildDir: 'dist', - banner: [ '/*!', ' * typeahead.js <%= version %>', @@ -45,12 +43,10 @@ module.exports = function(grunt) { ' * Copyright 2013-<%= grunt.template.today("yyyy") %> Twitter, Inc. and other contributors; Licensed MIT', ' */\n\n' ].join('\n'), - uglify: { options: { banner: '<%= banner %>' }, - concatBloodhound: { options: { mangle: false, @@ -71,7 +67,6 @@ module.exports = function(grunt) { src: files.common.concat(files.typeahead), dest: '<%= tempDir %>/typeahead.jquery.js' }, - bloodhound: { options: { mangle: false, @@ -131,16 +126,15 @@ module.exports = function(grunt) { dest: '<%= buildDir %>/typeahead.bundle.min.js' } }, - umd: { bloodhound: { src: '<%= tempDir %>/bloodhound.js', objectToExport: 'Bloodhound', deps: { - default: ['$'], - amd: ['jquery'], - cjs: ['jquery'], - global: ['jQuery'] + default: ['Promise'], + amd: ['Promise'], + cjs: ['Promise'], + global: ['Promise'] } }, typeahead: { @@ -153,7 +147,6 @@ module.exports = function(grunt) { } } }, - replace: { version: { options: { @@ -175,7 +168,6 @@ module.exports = function(grunt) { ] } }, - jshint: { options: { jshintrc: '.jshintrc' @@ -184,14 +176,12 @@ module.exports = function(grunt) { test: ['test/**/*_spec.js', 'test/integration/test.js'], gruntfile: ['Gruntfile.js'] }, - watch: { js: { files: 'src/**/*', tasks: 'build' } }, - exec: { npm_publish: 'npm publish', git_is_clean: 'test -z "$(git status --porcelain)"', @@ -220,22 +210,18 @@ module.exports = function(grunt) { 'rm -rf typeahead.js' ].join(' && ') }, - clean: { dist: 'dist' }, - connect: { server: { options: { port: 8888, keepalive: true } } }, - concurrent: { options: { logConcurrentOutput: true }, dev: ['server', 'watch'] }, - step: { options: { option: false @@ -245,7 +231,6 @@ module.exports = function(grunt) { grunt.registerTask('release', '#shipit', function(version) { var curVersion = grunt.config.get('version'); - version = semver.inc(curVersion, version) || version; if (!semver.valid(version) || semver.lte(version, curVersion)) { diff --git a/data/countries.json b/data/countries.json new file mode 100644 index 0000000000..8ab66c8515 --- /dev/null +++ b/data/countries.json @@ -0,0 +1 @@ +["Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Angola","Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Åland","Azerbaijan","Bosnia and Herzegovina","Barbados","Bangladesh","Belgium","Burkina Faso","Bulgaria","Bahrain","Burundi","Benin","Saint Barthélemy","Bermuda","Brunei","Bolivia","Bonaire","Brazil","Bahamas","Bhutan","Bouvet Island","Botswana","Belarus","Belize","Canada","Cocos [Keeling] Islands","Congo","Central African Republic","Republic of the Congo","Switzerland","Ivory Coast","Cook Islands","Chile","Cameroon","China","Colombia","Costa Rica","Cuba","Cape Verde","Curacao","Christmas Island","Cyprus","Czechia","Germany","Djibouti","Denmark","Dominica","Dominican Republic","Algeria","Ecuador","Estonia","Egypt","Western Sahara","Eritrea","Spain","Ethiopia","Finland","Fiji","Falkland Islands","Micronesia","Faroe Islands","France","Gabon","United Kingdom","Grenada","Georgia","French Guiana","Guernsey","Ghana","Gibraltar","Greenland","Gambia","Guinea","Guadeloupe","Equatorial Guinea","Greece","South Georgia and the South Sandwich Islands","Guatemala","Guam","Guinea-Bissau","Guyana","Hong Kong","Heard Island and McDonald Islands","Honduras","Croatia","Haiti","Hungary","Indonesia","Ireland","Israel","Isle of Man","India","British Indian Ocean Territory","Iraq","Iran","Iceland","Italy","Jersey","Jamaica","Jordan","Japan","Kenya","Kyrgyzstan","Cambodia","Kiribati","Comoros","Saint Kitts and Nevis","North Korea","South Korea","Kuwait","Cayman Islands","Kazakhstan","Laos","Lebanon","Saint Lucia","Liechtenstein","Sri Lanka","Liberia","Lesotho","Lithuania","Luxembourg","Latvia","Libya","Morocco","Monaco","Moldova","Montenegro","Saint Martin","Madagascar","Marshall Islands","Macedonia","Mali","Myanmar [Burma]","Mongolia","Macao","Northern Mariana Islands","Martinique","Mauritania","Montserrat","Malta","Mauritius","Maldives","Malawi","Mexico","Malaysia","Mozambique","Namibia","New Caledonia","Niger","Norfolk Island","Nigeria","Nicaragua","Netherlands","Norway","Nepal","Nauru","Niue","New Zealand","Oman","Panama","Peru","French Polynesia","Papua New Guinea","Philippines","Pakistan","Poland","Saint Pierre and Miquelon","Pitcairn Islands","Puerto Rico","Palestine","Portugal","Palau","Paraguay","Qatar","Réunion","Romania","Serbia","Russia","Rwanda","Saudi Arabia","Solomon Islands","Seychelles","Sudan","Sweden","Singapore","Saint Helena","Slovenia","Svalbard and Jan Mayen","Slovakia","Sierra Leone","San Marino","Senegal","Somalia","Suriname","South Sudan","São Tomé and Príncipe","El Salvador","Sint Maarten","Syria","Swaziland","Turks and Caicos Islands","Chad","French Southern Territories","Togo","Thailand","Tajikistan","Tokelau","East Timor","Turkmenistan","Tunisia","Tonga","Turkey","Trinidad and Tobago","Tuvalu","Taiwan","Tanzania","Ukraine","Uganda","U.S. Minor Outlying Islands","United States","Uruguay","Uzbekistan","Vatican City","Saint Vincent and the Grenadines","Venezuela","British Virgin Islands","U.S. Virgin Islands","Vietnam","Vanuatu","Wallis and Futuna","Samoa","Kosovo","Yemen","Mayotte","South Africa","Zambia","Zimbabwe"] diff --git a/data/films/post_1960.json b/data/films/post_1960.json new file mode 100644 index 0000000000..e5d1d6b5c3 --- /dev/null +++ b/data/films/post_1960.json @@ -0,0 +1,452 @@ +[ + { + "year": "1961", + "value": "West Side Story", + "tokens": [ + "West", + "Side", + "Story" + ] + }, + { + "year": "1962", + "value": "Lawrence of Arabia", + "tokens": [ + "Lawrence", + "of", + "Arabia" + ] + }, + { + "year": "1963", + "value": "Tom Jones", + "tokens": [ + "Tom", + "Jones" + ] + }, + { + "year": "1964", + "value": "My Fair Lady", + "tokens": [ + "My", + "Fair", + "Lady" + ] + }, + { + "year": "1965", + "value": "The Sound of Music", + "tokens": [ + "The", + "Sound", + "of", + "Music" + ] + }, + { + "year": "1966", + "value": "A Man for All Seasons", + "tokens": [ + "A", + "Man", + "for", + "All", + "Seasons" + ] + }, + { + "year": "1967", + "value": "In the Heat of the Night", + "tokens": [ + "In", + "the", + "Heat", + "of", + "the", + "Night" + ] + }, + { + "year": "1968", + "value": "Oliver!", + "tokens": [ + "Oliver!" + ] + }, + { + "year": "1969", + "value": "Midnight Cowboy", + "tokens": [ + "Midnight", + "Cowboy" + ] + }, + { + "year": "1970", + "value": "Patton", + "tokens": [ + "Patton" + ] + }, + { + "year": "1971", + "value": "The French Connection", + "tokens": [ + "The", + "French", + "Connection" + ] + }, + { + "year": "1972", + "value": "The Godfather", + "tokens": [ + "The", + "Godfather" + ] + }, + { + "year": "1973", + "value": "The Sting", + "tokens": [ + "The", + "Sting" + ] + }, + { + "year": "1974", + "value": "The Godfather Part II", + "tokens": [ + "The", + "Godfather", + "Part", + "II" + ] + }, + { + "year": "1975", + "value": "One Flew over the Cuckoo's Nest", + "tokens": [ + "One", + "Flew", + "over", + "the", + "Cuckoo's", + "Nest" + ] + }, + { + "year": "1976", + "value": "Rocky", + "tokens": [ + "Rocky" + ] + }, + { + "year": "1977", + "value": "Annie Hall", + "tokens": [ + "Annie", + "Hall" + ] + }, + { + "year": "1978", + "value": "The Deer Hunter", + "tokens": [ + "The", + "Deer", + "Hunter" + ] + }, + { + "year": "1979", + "value": "Kramer vs. Kramer", + "tokens": [ + "Kramer", + "vs.", + "Kramer" + ] + }, + { + "year": "1980", + "value": "Ordinary People", + "tokens": [ + "Ordinary", + "People" + ] + }, + { + "year": "1981", + "value": "Chariots of Fire", + "tokens": [ + "Chariots", + "of", + "Fire" + ] + }, + { + "year": "1982", + "value": "Gandhi", + "tokens": [ + "Gandhi" + ] + }, + { + "year": "1983", + "value": "Terms of Endearment", + "tokens": [ + "Terms", + "of", + "Endearment" + ] + }, + { + "year": "1984", + "value": "Amadeus", + "tokens": [ + "Amadeus" + ] + }, + { + "year": "1985", + "value": "Out of Africa", + "tokens": [ + "Out", + "of", + "Africa" + ] + }, + { + "year": "1986", + "value": "Platoon", + "tokens": [ + "Platoon" + ] + }, + { + "year": "1987", + "value": "The Last Emperor", + "tokens": [ + "The", + "Last", + "Emperor" + ] + }, + { + "year": "1988", + "value": "Rain Man", + "tokens": [ + "Rain", + "Man" + ] + }, + { + "year": "1989", + "value": "Driving Miss Daisy", + "tokens": [ + "Driving", + "Miss", + "Daisy" + ] + }, + { + "year": "1990", + "value": "Dances With Wolves", + "tokens": [ + "Dances", + "With", + "Wolves" + ] + }, + { + "year": "1991", + "value": "The Silence of the Lambs", + "tokens": [ + "The", + "Silence", + "of", + "the", + "Lambs" + ] + }, + { + "year": "1992", + "value": "Unforgiven", + "tokens": [ + "Unforgiven" + ] + }, + { + "year": "1993", + "value": "Schindler’s List", + "tokens": [ + "Schindler’s", + "List" + ] + }, + { + "year": "1994", + "value": "Forrest Gump", + "tokens": [ + "Forrest", + "Gump" + ] + }, + { + "year": "1995", + "value": "Braveheart", + "tokens": [ + "Braveheart" + ] + }, + { + "year": "1996", + "value": "The English Patient", + "tokens": [ + "The", + "English", + "Patient" + ] + }, + { + "year": "1997", + "value": "Titanic", + "tokens": [ + "Titanic" + ] + }, + { + "year": "1998", + "value": "Shakespeare in Love", + "tokens": [ + "Shakespeare", + "in", + "Love" + ] + }, + { + "year": "1999", + "value": "American Beauty", + "tokens": [ + "American", + "Beauty" + ] + }, + { + "year": "2000", + "value": "Gladiator", + "tokens": [ + "Gladiator" + ] + }, + { + "year": "2001", + "value": "A Beautiful Mind", + "tokens": [ + "A", + "Beautiful", + "Mind" + ] + }, + { + "year": "2002", + "value": "Chicago", + "tokens": [ + "Chicago" + ] + }, + { + "year": "2003", + "value": "The Lord of the Rings: The Return of the King", + "tokens": [ + "The", + "Lord", + "of", + "the", + "Rings:", + "The", + "Return", + "of", + "the", + "King" + ] + }, + { + "year": "2004", + "value": "Million Dollar Baby", + "tokens": [ + "Million", + "Dollar", + "Baby" + ] + }, + { + "year": "2005", + "value": "Crash", + "tokens": [ + "Crash" + ] + }, + { + "year": "2006", + "value": "The Departed", + "tokens": [ + "The", + "Departed" + ] + }, + { + "year": "2007", + "value": "No Country for Old Men", + "tokens": [ + "No", + "Country", + "for", + "Old", + "Men" + ] + }, + { + "year": "2008", + "value": "Slumdog Millionaire", + "tokens": [ + "Slumdog", + "Millionaire" + ] + }, + { + "year": "2009", + "value": "The Hurt Locker", + "tokens": [ + "The", + "Hurt", + "Locker" + ] + }, + { + "year": "2010", + "value": "The King's Speech", + "tokens": [ + "The", + "King's", + "Speech" + ] + }, + { + "year": "2011", + "value": "The Artist", + "tokens": [ + "The", + "Artist" + ] + }, + { + "year": "2012", + "value": "Argo", + "tokens": [ + "Argo" + ] + } +] diff --git a/data/nba.json b/data/nba.json new file mode 100644 index 0000000000..2a8491a3d7 --- /dev/null +++ b/data/nba.json @@ -0,0 +1 @@ +[{ "team": "Boston Celtics" },{ "team": "Dallas Mavericks" },{ "team": "Brooklyn Nets" },{ "team": "Houston Rockets" },{ "team": "New York Knicks" },{ "team": "Memphis Grizzlies" },{ "team": "Philadelphia 76ers" },{ "team": "New Orleans Hornets" },{ "team": "Toronto Raptors" },{ "team": "San Antonio Spurs" },{ "team": "Chicago Bulls" },{ "team": "Denver Nuggets" },{ "team": "Cleveland Cavaliers" },{ "team": "Minnesota Timberwolves" },{ "team": "Detroit Pistons" },{ "team": "Portland Trail Blazers" },{ "team": "Indiana Pacers" },{ "team": "Oklahoma City Thunder" },{ "team": "Milwaukee Bucks" },{ "team": "Utah Jazz" },{ "team": "Atlanta Hawks" },{ "team": "Golden State Warriors" },{ "team": "Charlotte Bobcats" },{ "team": "Los Angeles Clippers" },{ "team": "Miami Heat" },{ "team": "Los Angeles Lakers" },{ "team": "Orlando Magic" },{ "team": "Phoenix Suns" },{ "team": "Washington Wizards" },{ "team": "Sacramento Kings" }] diff --git a/data/nfl.json b/data/nfl.json new file mode 100644 index 0000000000..9429e5df13 --- /dev/null +++ b/data/nfl.json @@ -0,0 +1,34 @@ +[ +{ "team": "San Francisco 49ers" }, +{ "team": "Chicago Bears" }, +{ "team": "Cincinnati Bengals" }, +{ "team": "Buffalo Bills" }, +{ "team": "Denver Broncos" }, +{ "team": "Cleveland Browns" }, +{ "team": "Tampa Bay Buccaneers" }, +{ "team": "Arizona Cardinals" }, +{ "team": "San Diego Chargers" }, +{ "team": "Kansas City Chiefs" }, +{ "team": "Indianapolis Colts" }, +{ "team": "Dallas Cowboys" }, +{ "team": "Miami Dolphins" }, +{ "team": "Philadelphia Eagles" }, +{ "team": "Atlanta Falcons" }, +{ "team": "New York Giants" }, +{ "team": "Jacksonville Jaguars" }, +{ "team": "New York Jets" }, +{ "team": "Detroit Lions" }, +{ "team": "Green Bay Packers" }, +{ "team": "Carolina Panthers" }, +{ "team": "New England Patriots" }, +{ "team": "Oakland Raiders" }, +{ "team": "St.Louis Rams" }, +{ "team": "Baltimore Ravens" }, +{ "team": "Washington Redskins" }, +{ "team": "New Orlean Saints" }, +{ "team": "Seattle Seahawks" }, +{ "team": "Pittsburgh Steelers" }, +{ "team": "Houston Texans" }, +{ "team": "Tennesse Titans" }, +{ "team": "Minnesota Viking" } +] diff --git a/data/nhl.json b/data/nhl.json new file mode 100644 index 0000000000..c98903a407 --- /dev/null +++ b/data/nhl.json @@ -0,0 +1 @@ +[{ "team": "New Jersey Devils" },{ "team": "New York Islanders" },{ "team": "New York Rangers" },{ "team": "Philadelphia Flyers" },{ "team": "Pittsburgh Penguins" },{ "team": "Chicago Blackhawks" },{ "team": "Columbus Blue Jackets" },{ "team": "Detroit Red Wings" },{ "team": "Nashville Predators" },{ "team": "St. Louis Blues" },{ "team": "Boston Bruins" },{ "team": "Buffalo Sabres" },{ "team": "Montreal Canadiens" },{ "team": "Ottawa Senators" },{ "team": "Toronto Maple Leafs" },{ "team": "Calgary Flames" },{ "team": "Colorado Avalanche" },{ "team": "Edmonton Oilers" },{ "team": "Minnesota Wild" },{ "team": "Vancouver Canucks" },{ "team": "Carolina Hurricanes" },{ "team": "Florida Panthers" },{ "team": "Tampa Bay Lightning" },{ "team": "Washington Capitals" },{ "team": "Winnipeg Jets" },{ "team": "Anaheim Ducks" },{ "team": "Dallas Stars" },{ "team": "Los Angeles Kings" },{ "team": "Phoenix Coyotes" },{ "team": "San Jose Sharks" }] diff --git a/dist/bloodhound.js b/dist/bloodhound.js index 3cb1c4e5fa..c72172f0cf 100644 --- a/dist/bloodhound.js +++ b/dist/bloodhound.js @@ -1,20 +1,21 @@ /*! - * typeahead.js 1.2.0 + * typeahead.js 1.2.1 * https://github.com/twitter/typeahead.js * Copyright 2013-2017 Twitter, Inc. and other contributors; Licensed MIT */ + (function(root, factory) { if (typeof define === "function" && define.amd) { - define([ "jquery" ], function(a0) { + define([ "Promise" ], function(a0) { return root["Bloodhound"] = factory(a0); }); - } else if (typeof exports === "object") { - module.exports = factory(require("jquery")); + } else if (typeof module === "object" && module.exports) { + module.exports = factory(require("Promise")); } else { - root["Bloodhound"] = factory(root["jQuery"]); + root["Bloodhound"] = factory(root["Promise"]); } -})(this, function($) { +})(this, function(Promise) { var _ = function() { "use strict"; return { @@ -33,36 +34,105 @@ isNumber: function(obj) { return typeof obj === "number"; }, - isArray: $.isArray, - isFunction: $.isFunction, - isObject: $.isPlainObject, + isFunction: function(obj) { + return typeof obj === "function"; + }, + isObject: function(obj) { + var proto, Ctor, hasOwn = {}.hasOwnProperty; + if (!obj || {}.toString.call(obj) !== "[object Object]") { + return false; + } + proto = Object.getPrototypeOf(obj); + if (!proto) { + return true; + } + Ctor = hasOwn.call(proto, "constructor") && proto.constructor; + return typeof Ctor === "function" && hasOwn.toString.call(Ctor) === hasOwn.toString.call(Object); + }, isUndefined: function(obj) { return typeof obj === "undefined"; }, isElement: function(obj) { return !!(obj && obj.nodeType === 1); }, - isJQuery: function(obj) { - return obj instanceof $; - }, toStr: function toStr(s) { return _.isUndefined(s) || s === null ? "" : s + ""; }, - bind: $.proxy, + bind: function(fn, context) { + var tmp, args, proxy; + if (typeof context === "string") { + tmp = fn[context]; + context = fn; + fn = tmp; + } + if (!this.isFunction(fn)) { + return undefined; + } + args = [].slice.call(arguments, 2); + proxy = function() { + return fn.apply(context || this, args.concat([].slice.call(arguments))); + }; + proxy.guid = fn.guid = fn.guid || this.guid(); + return proxy; + }, each: function(collection, cb) { - $.each(collection, reverseArgs); - function reverseArgs(index, value) { + (function(obj, callback) { + var length, i = 0; + if (Array.isArray(obj)) { + length = obj.length; + for (;i < length; i++) { + if (callback.call(obj[i], i, obj[i]) === false) { + break; + } + } + } else { + for (i in obj) { + if (callback.call(obj[i], i, obj[i]) === false) { + break; + } + } + } + return obj; + })(collection, function(index, value) { return cb(value, index); + }); + }, + map: function(elems, callback, arg) { + var length, value, i = 0, ret = []; + if (Array.isArray(elems)) { + length = elems.length; + for (;i < length; i++) { + value = callback(elems[i], i, arg); + if (value != null) { + ret.push(value); + } + } + } else { + for (i in elems) { + value = callback(elems[i], i, arg); + if (value != null) { + ret.push(value); + } + } + } + return [].concat.apply([], ret); + }, + filter: function(elems, callback, invert) { + var callbackInverse, matches = [], i = 0, length = elems.length, callbackExpect = !invert; + for (;i < length; i++) { + callbackInverse = !callback(elems[i], i); + if (callbackInverse !== callbackExpect) { + matches.push(elems[i]); + } } + return matches; }, - map: $.map, - filter: $.grep, every: function(obj, test) { var result = true; if (!obj) { return result; } - $.each(obj, function(key, val) { + this.each(obj, function(val, key) { if (!(result = test.call(null, val, key, obj))) { return false; } @@ -74,19 +144,56 @@ if (!obj) { return result; } - $.each(obj, function(key, val) { + this.each(obj, function(val, key) { if (result = test.call(null, val, key, obj)) { return false; } }); return !!result; }, - mixin: $.extend, + mixin: function() { + var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = false; + if (typeof target === "boolean") { + deep = target; + target = arguments[i] || {}; + i++; + } + if (typeof target !== "object" && !this.isFunction(target)) { + target = {}; + } + if (i === length) { + target = this; + i--; + } + for (;i < length; i++) { + if ((options = arguments[i]) != null) { + for (name in options) { + src = target[name]; + copy = options[name]; + if (target === copy) { + continue; + } + if (deep && copy && (this.isObject(copy) || (copyIsArray = Array.isArray(copy)))) { + if (copyIsArray) { + copyIsArray = false; + clone = src && Array.isArray(src) ? src : []; + } else { + clone = src && this.isObject(src) ? src : {}; + } + target[name] = this.extend(deep, clone, copy); + } else if (copy !== undefined) { + target[name] = copy; + } + } + } + } + return target; + }, identity: function(x) { return x; }, clone: function(obj) { - return $.extend(true, {}, obj); + return this.extend(true, {}, obj); }, getIdGenerator: function() { var counter = 0; @@ -95,7 +202,7 @@ }; }, templatify: function templatify(obj) { - return $.isFunction(obj) ? obj : template; + return this.isFunction(obj) ? obj : template; function template() { return String(obj); } @@ -158,7 +265,7 @@ noop: function() {} }; }(); - var VERSION = "1.2.0"; + var VERSION = "1.2.1"; var tokenizers = function() { "use strict"; return { @@ -194,7 +301,7 @@ } function getObjTokenizer(tokenizer) { return function setKey(keys) { - keys = _.isArray(keys) ? keys : [].slice.call(arguments, 0); + keys = Array.isArray(keys) ? keys : [].slice.call(arguments, 0); return function tokenize(o) { var tokens = []; _.each(keys, function(k) { @@ -211,7 +318,7 @@ this.maxSize = _.isNumber(maxSize) ? maxSize : 100; this.reset(); if (this.maxSize <= 0) { - this.set = this.get = $.noop; + this.set = this.get = _.noop; } } _.mixin(LruCache.prototype, { @@ -349,7 +456,7 @@ return JSON.stringify(_.isUndefined(val) ? null : val); } function decode(val) { - return $.parseJSON(val); + return JSON.parse(val); } function gatherMatchingKeys(keyMatcher) { var i, key, keys = [], len = LOCAL_STORAGE.length; @@ -382,7 +489,7 @@ _.mixin(Transport.prototype, { _fingerprint: function fingerprint(o) { o = o || {}; - return o.url + o.type + $.param(o.data || {}); + return o.url + o.type + _.param(o.data || {}); }, _get: function(o, cb) { var that = this, fingerprint, jqXhr; @@ -391,10 +498,10 @@ return; } if (jqXhr = pendingRequests[fingerprint]) { - jqXhr.done(done).fail(fail); + jqXhr.then(done).catch(fail); } else if (pendingRequestsCount < this.maxPendingRequests) { pendingRequestsCount++; - pendingRequests[fingerprint] = this._send(o).done(done).fail(fail).always(always); + pendingRequests[fingerprint] = this._send(o).then(done).catch(fail).then(always); } else { this.onDeckRequestArgs = [].slice.call(arguments, 0); } @@ -416,7 +523,7 @@ }, get: function(o, cb) { var resp, fingerprint; - cb = cb || $.noop; + cb = cb || _.noop; o = _.isString(o) ? { url: o } : o || {}; @@ -441,7 +548,7 @@ function SearchIndex(o) { o = o || {}; if (!o.datumTokenizer || !o.queryTokenizer) { - $.error("datumTokenizer and queryTokenizer are both required"); + throw new Error("datumTokenizer and queryTokenizer are both required"); } this.identify = o.identify || _.stringify; this.datumTokenizer = o.datumTokenizer; @@ -456,7 +563,7 @@ }, add: function(data) { var that = this; - data = _.isArray(data) ? data : [ data ]; + data = Array.isArray(data) ? data : [ data ]; _.each(data, function(datum) { var id, tokens; that.datums[id = that.identify(datum)] = datum; @@ -619,9 +726,9 @@ return; } settings = this.prepare(this._settings()); - this.transport(settings).fail(onError).done(onResponse); - function onError() { - cb(true); + this.transport(settings).then(onResponse).catch(onError); + function onError(e) { + cb(e); } function onResponse(resp) { cb(null, that.transform(resp)); @@ -692,8 +799,12 @@ remote: null }; o = _.mixin(defaults, o || {}); - !o.datumTokenizer && $.error("datumTokenizer is required"); - !o.queryTokenizer && $.error("queryTokenizer is required"); + if (!o.datumTokenizer) { + throw new Error("datumTokenizer is required"); + } + if (!o.queryTokenizer) { + throw new Error("queryTokenizer is required"); + } sorter = o.sorter; o.sorter = sorter ? function(x) { return x.sort(sorter); @@ -722,11 +833,13 @@ url: o } : o; o = _.mixin(defaults, o); - !o.url && $.error("prefetch requires url to be set"); + if (!o.url) { + throw new Error("prefetch requires url to be set"); + } o.transform = o.filter || o.transform; o.cacheKey = o.cacheKey || o.url; o.thumbprint = VERSION + o.thumbprint; - o.transport = o.transport ? callbackToDeferred(o.transport) : $.ajax; + o.transport = o.transport ? callbackToPromise(o.transport) : _.ajax; return o; } function parseRemote(o) { @@ -750,11 +863,13 @@ url: o } : o; o = _.mixin(defaults, o); - !o.url && $.error("remote requires url to be set"); + if (!o.url) { + throw new Error("remote requires url to be set"); + } o.transform = o.filter || o.transform; o.prepare = toRemotePrepare(o); o.limiter = toLimiter(o); - o.transport = o.transport ? callbackToDeferred(o.transport) : $.ajax; + o.transport = o.transport ? callbackToPromise(o.transport) : _.ajax; delete o.replace; delete o.wildcard; delete o.rateLimitBy; @@ -809,22 +924,18 @@ }; } } - function callbackToDeferred(fn) { - return function wrapper(o) { - var deferred = $.Deferred(); - fn(o, onSuccess, onError); - return deferred; - function onSuccess(resp) { + function callbackToPromise(fn) { + return new Promise(function(resolve, reject) { + fn(o, function(resp) { _.defer(function() { - deferred.resolve(resp); + resolve(resp); }); - } - function onError(err) { + }, function(err) { _.defer(function() { - deferred.reject(err); + reject(err); }); - } - }; + }); + }); } }(); var Bloodhound = function() { @@ -864,34 +975,35 @@ } }, _loadPrefetch: function loadPrefetch() { - var that = this, deferred, serialized; - deferred = $.Deferred(); - if (!this.prefetch) { - deferred.resolve(); - } else if (serialized = this.prefetch.fromCache()) { - this.index.bootstrap(serialized); - deferred.resolve(); - } else { - this.prefetch.fromNetwork(done); - } - return deferred.promise(); - function done(err, data) { - if (err) { - return deferred.reject(); + var that = this, serialized; + return new Promise(function(resolve, reject) { + if (!that.prefetch) { + resolve(); + } else if (serialized = that.prefetch.fromCache()) { + that.index.bootstrap(serialized); + resolve(); + } else { + that.prefetch.fromNetwork(function(err, data) { + if (err) { + reject(err); + return; + } + that.add(data); + that.prefetch.store(that.index.serialize()); + resolve(); + }); } - that.add(data); - that.prefetch.store(that.index.serialize()); - deferred.resolve(); - } + }); }, _initialize: function initialize() { - var that = this, deferred; + var that = this; this.clear(); - (this.initPromise = this._loadPrefetch()).done(addLocalToIndex); - return this.initPromise; - function addLocalToIndex() { + this.initPromise = this._loadPrefetch().then(function() { that.add(that.local); - } + }).catch(function(e) { + console.error(e.message); + }); + return this.initPromise; }, initialize: function initialize(force) { return !this.initPromise || force ? this._initialize() : this.initPromise; @@ -901,7 +1013,7 @@ return this; }, get: function get(ids) { - ids = _.isArray(ids) ? ids : [].slice.call(arguments); + ids = Array.isArray(ids) ? ids : [].slice.call(arguments); return this.index.get(ids); }, search: function search(query, sync, async) { diff --git a/dist/bloodhound.min.js b/dist/bloodhound.min.js index d83a6e53c8..2fe2993420 100644 --- a/dist/bloodhound.min.js +++ b/dist/bloodhound.min.js @@ -1,7 +1,8 @@ /*! - * typeahead.js 1.2.0 + * typeahead.js 1.2.1 * https://github.com/twitter/typeahead.js * Copyright 2013-2017 Twitter, Inc. and other contributors; Licensed MIT */ -!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){return a.Bloodhound=b(c)}):"object"==typeof exports?module.exports=b(require("jquery")):a.Bloodhound=b(a.jQuery)}(this,function(a){var b=function(){"use strict";return{isMsie:function(){return!!/(msie|trident)/i.test(navigator.userAgent)&&navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2]},isBlankString:function(a){return!a||/^\s*$/.test(a)},escapeRegExChars:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isString:function(a){return"string"==typeof a},isNumber:function(a){return"number"==typeof a},isArray:a.isArray,isFunction:a.isFunction,isObject:a.isPlainObject,isUndefined:function(a){return"undefined"==typeof a},isElement:function(a){return!(!a||1!==a.nodeType)},isJQuery:function(b){return b instanceof a},toStr:function(a){return b.isUndefined(a)||null===a?"":a+""},bind:a.proxy,each:function(b,c){function d(a,b){return c(b,a)}a.each(b,d)},map:a.map,filter:a.grep,every:function(b,c){var d=!0;return b?(a.each(b,function(a,e){if(!(d=c.call(null,e,a,b)))return!1}),!!d):d},some:function(b,c){var d=!1;return b?(a.each(b,function(a,e){if(d=c.call(null,e,a,b))return!1}),!!d):d},mixin:a.extend,identity:function(a){return a},clone:function(b){return a.extend(!0,{},b)},getIdGenerator:function(){var a=0;return function(){return a++}},templatify:function(b){function c(){return String(b)}return a.isFunction(b)?b:c},defer:function(a){setTimeout(a,0)},debounce:function(a,b,c){var d,e;return function(){var f,g,h=this,i=arguments;return f=function(){d=null,c||(e=a.apply(h,i))},g=c&&!d,clearTimeout(d),d=setTimeout(f,b),g&&(e=a.apply(h,i)),e}},throttle:function(a,b){var c,d,e,f,g,h;return g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)},function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,j<=0?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},stringify:function(a){return b.isString(a)?a:JSON.stringify(a)},guid:function(){function a(a){var b=(Math.random().toString(16)+"000000000").substr(2,8);return a?"-"+b.substr(0,4)+"-"+b.substr(4,4):b}return"tt-"+a()+a(!0)+a(!0)+a()},noop:function(){}}}(),c="1.2.0",d=function(){"use strict";function a(a){return a=b.toStr(a),a?a.split(/\s+/):[]}function c(a){return a=b.toStr(a),a?a.split(/\W+/):[]}function d(a){a=b.toStr(a);var c=[],d="";return b.each(a.split(""),function(a){a.match(/\s+/)?d="":(c.push(d+a),d+=a)}),c}function e(a){return function(c){return c=b.isArray(c)?c:[].slice.call(arguments,0),function(d){var e=[];return b.each(c,function(c){e=e.concat(a(b.toStr(d[c])))}),e}}}return{nonword:c,whitespace:a,ngram:d,obj:{nonword:e(c),whitespace:e(a),ngram:e(d)}}}(),e=function(){"use strict";function c(c){this.maxSize=b.isNumber(c)?c:100,this.reset(),this.maxSize<=0&&(this.set=this.get=a.noop)}function d(){this.head=this.tail=null}function e(a,b){this.key=a,this.val=b,this.prev=this.next=null}return b.mixin(c.prototype,{set:function(a,b){var c,d=this.list.tail;this.size>=this.maxSize&&(this.list.remove(d),delete this.hash[d.key],this.size--),(c=this.hash[a])?(c.val=b,this.list.moveToFront(c)):(c=new e(a,b),this.list.add(c),this.hash[a]=c,this.size++)},get:function(a){var b=this.hash[a];if(b)return this.list.moveToFront(b),b.val},reset:function(){this.size=0,this.hash={},this.list=new d}}),b.mixin(d.prototype,{add:function(a){this.head&&(a.next=this.head,this.head.prev=a),this.head=a,this.tail=this.tail||a},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev},moveToFront:function(a){this.remove(a),this.add(a)}}),c}(),f=function(){"use strict";function c(a,c){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+b.escapeRegExChars(this.prefix)),this.ls=c||h,!this.ls&&this._noop()}function d(){return(new Date).getTime()}function e(a){return JSON.stringify(b.isUndefined(a)?null:a)}function f(b){return a.parseJSON(b)}function g(a){var b,c,d=[],e=h.length;for(b=0;bc)}}),c}(),g=function(){"use strict";function c(a){a=a||{},this.maxPendingRequests=a.maxPendingRequests||6,this.cancelled=!1,this.lastReq=null,this._send=a.transport,this._get=a.limiter?a.limiter(this._get):this._get,this._cache=a.cache===!1?new e(0):g}var d=0,f={},g=new e(10);return c.setMaxPendingRequests=function(a){this.maxPendingRequests=a},c.resetCache=function(){g.reset()},b.mixin(c.prototype,{_fingerprint:function(b){return b=b||{},b.url+b.type+a.param(b.data||{})},_get:function(a,b){function c(a){b(null,a),j._cache.set(h,a)}function e(){b(!0)}function g(){d--,delete f[h],j.onDeckRequestArgs&&(j._get.apply(j,j.onDeckRequestArgs),j.onDeckRequestArgs=null)}var h,i,j=this;h=this._fingerprint(a),this.cancelled||h!==this.lastReq||((i=f[h])?i.done(c).fail(e):db[d]?d++:(e.push(a[c]),c++,d++);return e}var h="c",i="i";return b.mixin(c.prototype,{bootstrap:function(a){this.datums=a.datums,this.trie=a.trie},add:function(a){var c=this;a=b.isArray(a)?a:[a],b.each(a,function(a){var f,g;c.datums[f=c.identify(a)]=a,g=d(c.datumTokenizer(a)),b.each(g,function(a){var b,d,g;for(b=c.trie,d=a.split("");g=d.shift();)b=b[h][g]||(b[h][g]=e()),b[i].push(f)})})},get:function(a){var c=this;return b.map(a,function(a){return c.datums[a]})},search:function(a){var c,e,j=this;return c=d(this.queryTokenizer(a)),b.each(c,function(a){var b,c,d,f;if(e&&0===e.length&&!j.matchAnyQueryToken)return!1;for(b=j.trie,c=a.split("");b&&(d=c.shift());)b=b[h][d];if(b&&0===c.length)f=b[i].slice(0),e=e?g(e,f):f;else if(!j.matchAnyQueryToken)return e=[],!1}),e?b.map(f(e),function(a){return j.datums[a]}):[]},all:function(){var a=[];for(var b in this.datums)a.push(this.datums[b]);return a},reset:function(){this.datums={},this.trie=e()},serialize:function(){return{datums:this.datums,trie:this.trie}}}),c}(),i=function(){"use strict";function a(a){this.url=a.url,this.ttl=a.ttl,this.cache=a.cache,this.prepare=a.prepare,this.transform=a.transform,this.transport=a.transport,this.thumbprint=a.thumbprint,this.storage=new f(a.cacheKey)}var c;return c={data:"data",protocol:"protocol",thumbprint:"thumbprint"},b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},store:function(a){this.cache&&(this.storage.set(c.data,a,this.ttl),this.storage.set(c.protocol,location.protocol,this.ttl),this.storage.set(c.thumbprint,this.thumbprint,this.ttl))},fromCache:function(){var a,b={};return this.cache?(b.data=this.storage.get(c.data),b.protocol=this.storage.get(c.protocol),b.thumbprint=this.storage.get(c.thumbprint),a=b.thumbprint!==this.thumbprint||b.protocol!==location.protocol,b.data&&!a?b.data:null):null},fromNetwork:function(a){function b(){a(!0)}function c(b){a(null,e.transform(b))}var d,e=this;a&&(d=this.prepare(this._settings()),this.transport(d).fail(b).done(c))},clear:function(){return this.storage.clear(),this}}),a}(),j=function(){"use strict";function a(a){this.url=a.url,this.prepare=a.prepare,this.transform=a.transform,this.indexResponse=a.indexResponse,this.transport=new g({cache:a.cache,limiter:a.limiter,transport:a.transport,maxPendingRequests:a.maxPendingRequests})}return b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},get:function(a,b){function c(a,c){b(a?[]:e.transform(c))}var d,e=this;if(b)return a=a||"",d=this.prepare(a,this._settings()),this.transport.get(d,c)},cancelLastRequest:function(){this.transport.cancel()}}),a}(),k=function(){"use strict";function d(d){var e;return d?(e={url:null,ttl:864e5,cache:!0,cacheKey:null,thumbprint:"",prepare:b.identity,transform:b.identity,transport:null},d=b.isString(d)?{url:d}:d,d=b.mixin(e,d),!d.url&&a.error("prefetch requires url to be set"),d.transform=d.filter||d.transform,d.cacheKey=d.cacheKey||d.url,d.thumbprint=c+d.thumbprint,d.transport=d.transport?h(d.transport):a.ajax,d):null}function e(c){var d;if(c)return d={url:null,cache:!0,prepare:null,replace:null,wildcard:null,limiter:null,rateLimitBy:"debounce",rateLimitWait:300,transform:b.identity,transport:null},c=b.isString(c)?{url:c}:c,c=b.mixin(d,c),!c.url&&a.error("remote requires url to be set"),c.transform=c.filter||c.transform,c.prepare=f(c),c.limiter=g(c),c.transport=c.transport?h(c.transport):a.ajax,delete c.replace,delete c.wildcard,delete c.rateLimitBy,delete c.rateLimitWait,c}function f(a){function b(a,b){return b.url=f(b.url,a),b}function c(a,b){return b.url=b.url.replace(g,encodeURIComponent(a)),b}function d(a,b){return b}var e,f,g;return e=a.prepare,f=a.replace,g=a.wildcard,e?e:e=f?b:a.wildcard?c:d}function g(a){function c(a){return function(c){return b.debounce(c,a)}}function d(a){return function(c){return b.throttle(c,a)}}var e,f,g;return e=a.limiter,f=a.rateLimitBy,g=a.rateLimitWait,e||(e=/^throttle$/i.test(f)?d(g):c(g)),e}function h(c){return function(d){function e(a){b.defer(function(){g.resolve(a)})}function f(a){b.defer(function(){g.reject(a)})}var g=a.Deferred();return c(d,e,f),g}}return function(c){var f,g;return f={initialize:!0,identify:b.stringify,datumTokenizer:null,queryTokenizer:null,matchAnyQueryToken:!1,sufficient:5,indexRemote:!1,sorter:null,local:[],prefetch:null,remote:null},c=b.mixin(f,c||{}),!c.datumTokenizer&&a.error("datumTokenizer is required"),!c.queryTokenizer&&a.error("queryTokenizer is required"),g=c.sorter,c.sorter=g?function(a){return a.sort(g)}:b.identity,c.local=b.isFunction(c.local)?c.local():c.local,c.prefetch=d(c.prefetch),c.remote=e(c.remote),c}}(),l=function(){"use strict";function c(a){a=k(a),this.sorter=a.sorter,this.identify=a.identify,this.sufficient=a.sufficient,this.indexRemote=a.indexRemote,this.local=a.local,this.remote=a.remote?new j(a.remote):null,this.prefetch=a.prefetch?new i(a.prefetch):null,this.index=new h({identify:this.identify,datumTokenizer:a.datumTokenizer,queryTokenizer:a.queryTokenizer}),a.initialize!==!1&&this.initialize()}var e;return e=window&&window.Bloodhound,c.noConflict=function(){return window&&(window.Bloodhound=e),c},c.tokenizers=d,b.mixin(c.prototype,{__ttAdapter:function(){function a(a,b,d){return c.search(a,b,d)}function b(a,b){return c.search(a,b)}var c=this;return this.remote?a:b},_loadPrefetch:function(){function b(a,b){return a?c.reject():(e.add(b),e.prefetch.store(e.index.serialize()),void c.resolve())}var c,d,e=this;return c=a.Deferred(),this.prefetch?(d=this.prefetch.fromCache())?(this.index.bootstrap(d),c.resolve()):this.prefetch.fromNetwork(b):c.resolve(),c.promise()},_initialize:function(){function a(){b.add(b.local)}var b=this;return this.clear(),(this.initPromise=this._loadPrefetch()).done(a),this.initPromise},initialize:function(a){return!this.initPromise||a?this._initialize():this.initPromise},add:function(a){return this.index.add(a),this},get:function(a){return a=b.isArray(a)?a:[].slice.call(arguments),this.index.get(a)},search:function(a,c,d){function e(a){var c=[];b.each(a,function(a){!b.some(f,function(b){return g.identify(a)===g.identify(b)})&&c.push(a)}),g.indexRemote&&g.add(c),d(c)}var f,g=this;return c=c||b.noop,d=d||b.noop,f=this.sorter(this.index.search(a)),c(this.remote?f.slice():f),this.remote&&f.length=this.maxSize&&(this.list.remove(e),delete this.hash[e.key],this.size--),(c=this.hash[a])?(c.val=b,this.list.moveToFront(c)):(c=new d(a,b),this.list.add(c),this.hash[a]=c,this.size++)},get:function(a){var b=this.hash[a];if(b)return this.list.moveToFront(b),b.val},reset:function(){this.size=0,this.hash={},this.list=new c}}),b.mixin(c.prototype,{add:function(a){this.head&&(a.next=this.head,this.head.prev=a),this.head=a,this.tail=this.tail||a},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev},moveToFront:function(a){this.remove(a),this.add(a)}}),a}(),f=function(){"use strict";function a(a,c){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+b.escapeRegExChars(this.prefix)),this.ls=c||g,!this.ls&&this._noop()}function c(){return(new Date).getTime()}function d(a){return JSON.stringify(b.isUndefined(a)?null:a)}function e(a){return JSON.parse(a)}function f(a){var b,c,d=[],e=g.length;for(b=0;bd)}}),a}(),g=function(){"use strict";function a(a){a=a||{},this.maxPendingRequests=a.maxPendingRequests||6,this.cancelled=!1,this.lastReq=null,this._send=a.transport,this._get=a.limiter?a.limiter(this._get):this._get,this._cache=!1===a.cache?new e(0):f}var c=0,d={},f=new e(10);return a.setMaxPendingRequests=function(a){this.maxPendingRequests=a},a.resetCache=function(){f.reset()},b.mixin(a.prototype,{_fingerprint:function(a){return a=a||{},a.url+a.type+b.param(a.data||{})},_get:function(a,b){function e(a){b(null,a),j._cache.set(h,a)}function f(){b(!0)}function g(){c--,delete d[h],j.onDeckRequestArgs&&(j._get.apply(j,j.onDeckRequestArgs),j.onDeckRequestArgs=null)}var h,i,j=this;h=this._fingerprint(a),this.cancelled||h!==this.lastReq||((i=d[h])?i.then(e).catch(f):cb[d]?d++:(e.push(a[c]),c++,d++);return e}var g="c",h="i";return b.mixin(a.prototype,{bootstrap:function(a){this.datums=a.datums,this.trie=a.trie},add:function(a){var e=this;a=Array.isArray(a)?a:[a],b.each(a,function(a){var f,i;e.datums[f=e.identify(a)]=a,i=c(e.datumTokenizer(a)),b.each(i,function(a){var b,c,i;for(b=e.trie,c=a.split("");i=c.shift();)b=b[g][i]||(b[g][i]=d()),b[h].push(f)})})},get:function(a){var c=this;return b.map(a,function(a){return c.datums[a]})},search:function(a){var d,i,j=this;return d=c(this.queryTokenizer(a)),b.each(d,function(a){var b,c,d,e;if(i&&0===i.length&&!j.matchAnyQueryToken)return!1;for(b=j.trie,c=a.split("");b&&(d=c.shift());)b=b[g][d];if(b&&0===c.length)e=b[h].slice(0),i=i?f(i,e):e;else if(!j.matchAnyQueryToken)return i=[],!1}),i?b.map(e(i),function(a){return j.datums[a]}):[]},all:function(){var a=[];for(var b in this.datums)a.push(this.datums[b]);return a},reset:function(){this.datums={},this.trie=d()},serialize:function(){return{datums:this.datums,trie:this.trie}}}),a}(),i=function(){"use strict";function a(a){this.url=a.url,this.ttl=a.ttl,this.cache=a.cache,this.prepare=a.prepare,this.transform=a.transform,this.transport=a.transport,this.thumbprint=a.thumbprint,this.storage=new f(a.cacheKey)}var c;return c={data:"data",protocol:"protocol",thumbprint:"thumbprint"},b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},store:function(a){this.cache&&(this.storage.set(c.data,a,this.ttl),this.storage.set(c.protocol,location.protocol,this.ttl),this.storage.set(c.thumbprint,this.thumbprint,this.ttl))},fromCache:function(){var a,b={};return this.cache?(b.data=this.storage.get(c.data),b.protocol=this.storage.get(c.protocol),b.thumbprint=this.storage.get(c.thumbprint),a=b.thumbprint!==this.thumbprint||b.protocol!==location.protocol,b.data&&!a?b.data:null):null},fromNetwork:function(a){function b(b){a(b)}function c(b){a(null,e.transform(b))}var d,e=this;a&&(d=this.prepare(this._settings()),this.transport(d).then(c).catch(b))},clear:function(){return this.storage.clear(),this}}),a}(),j=function(){"use strict";function a(a){this.url=a.url,this.prepare=a.prepare,this.transform=a.transform,this.indexResponse=a.indexResponse,this.transport=new g({cache:a.cache,limiter:a.limiter,transport:a.transport,maxPendingRequests:a.maxPendingRequests})}return b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},get:function(a,b){function c(a,c){b(a?[]:e.transform(c))}var d,e=this;if(b)return a=a||"",d=this.prepare(a,this._settings()),this.transport.get(d,c)},cancelLastRequest:function(){this.transport.cancel()}}),a}(),k=function(){"use strict";function d(a){var d;if(!a)return null;if(d={url:null,ttl:864e5,cache:!0,cacheKey:null,thumbprint:"",prepare:b.identity,transform:b.identity,transport:null},a=b.isString(a)?{url:a}:a,a=b.mixin(d,a),!a.url)throw new Error("prefetch requires url to be set");return a.transform=a.filter||a.transform,a.cacheKey=a.cacheKey||a.url,a.thumbprint=c+a.thumbprint,a.transport=a.transport?h(a.transport):b.ajax,a}function e(a){var c;if(a){if(c={url:null,cache:!0,prepare:null,replace:null,wildcard:null,limiter:null,rateLimitBy:"debounce",rateLimitWait:300,transform:b.identity,transport:null},a=b.isString(a)?{url:a}:a,a=b.mixin(c,a),!a.url)throw new Error("remote requires url to be set");return a.transform=a.filter||a.transform,a.prepare=f(a),a.limiter=g(a),a.transport=a.transport?h(a.transport):b.ajax,delete a.replace,delete a.wildcard,delete a.rateLimitBy,delete a.rateLimitWait,a}}function f(a){function b(a,b){return b.url=f(b.url,a),b}function c(a,b){return b.url=b.url.replace(g,encodeURIComponent(a)),b}function d(a,b){return b}var e,f,g;return e=a.prepare,f=a.replace,g=a.wildcard,e||(e=f?b:a.wildcard?c:d)}function g(a){var c,d,e;return c=a.limiter,d=a.rateLimitBy,e=a.rateLimitWait,c||(c=/^throttle$/i.test(d)?function(a){return function(c){return b.throttle(c,a)}}(e):function(a){return function(c){return b.debounce(c,a)}}(e)),c}function h(c){return new a(function(a,d){c(o,function(c){b.defer(function(){a(c)})},function(a){b.defer(function(){d(a)})})})}return function(a){var c,f;if(c={initialize:!0,identify:b.stringify,datumTokenizer:null,queryTokenizer:null,matchAnyQueryToken:!1,sufficient:5,indexRemote:!1,sorter:null,local:[],prefetch:null,remote:null},a=b.mixin(c,a||{}),!a.datumTokenizer)throw new Error("datumTokenizer is required");if(!a.queryTokenizer)throw new Error("queryTokenizer is required");return f=a.sorter,a.sorter=f?function(a){return a.sort(f)}:b.identity,a.local=b.isFunction(a.local)?a.local():a.local,a.prefetch=d(a.prefetch),a.remote=e(a.remote),a}}();return function(){"use strict";function c(a){a=k(a),this.sorter=a.sorter,this.identify=a.identify,this.sufficient=a.sufficient,this.indexRemote=a.indexRemote,this.local=a.local,this.remote=a.remote?new j(a.remote):null,this.prefetch=a.prefetch?new i(a.prefetch):null,this.index=new h({identify:this.identify,datumTokenizer:a.datumTokenizer,queryTokenizer:a.queryTokenizer}),!1!==a.initialize&&this.initialize()}var e;return e=window&&window.Bloodhound,c.noConflict=function(){return window&&(window.Bloodhound=e),c},c.tokenizers=d,b.mixin(c.prototype,{__ttAdapter:function(){function a(a,b,d){return c.search(a,b,d)}function b(a,b){return c.search(a,b)}var c=this;return this.remote?a:b},_loadPrefetch:function(){var b,c=this;return new a(function(a,d){c.prefetch?(b=c.prefetch.fromCache())?(c.index.bootstrap(b),a()):c.prefetch.fromNetwork(function(b,e){if(b)return void d(b);c.add(e),c.prefetch.store(c.index.serialize()),a()}):a()})},_initialize:function(){var a=this;return this.clear(),this.initPromise=this._loadPrefetch().then(function(){a.add(a.local)}).catch(function(a){console.error(a.message)}),this.initPromise},initialize:function(a){return!this.initPromise||a?this._initialize():this.initPromise},add:function(a){return this.index.add(a),this},get:function(a){return a=Array.isArray(a)?a:[].slice.call(arguments),this.index.get(a)},search:function(a,c,d){function e(a){var c=[];b.each(a,function(a){!b.some(f,function(b){return g.identify(a)===g.identify(b)})&&c.push(a)}),g.indexRemote&&g.add(c),d(c)}var f,g=this;return c=c||b.noop,d=d||b.noop,f=this.sorter(this.index.search(a)),c(this.remote?f.slice():f),this.remote&&f.length=this.maxSize&&(this.list.remove(d),delete this.hash[d.key],this.size--),(c=this.hash[a])?(c.val=b,this.list.moveToFront(c)):(c=new e(a,b),this.list.add(c),this.hash[a]=c,this.size++)},get:function(a){var b=this.hash[a];if(b)return this.list.moveToFront(b),b.val},reset:function(){this.size=0,this.hash={},this.list=new d}}),b.mixin(d.prototype,{add:function(a){this.head&&(a.next=this.head,this.head.prev=a),this.head=a,this.tail=this.tail||a},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev},moveToFront:function(a){this.remove(a),this.add(a)}}),c}(),f=function(){"use strict";function c(a,c){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+b.escapeRegExChars(this.prefix)),this.ls=c||h,!this.ls&&this._noop()}function d(){return(new Date).getTime()}function e(a){return JSON.stringify(b.isUndefined(a)?null:a)}function f(b){return a.parseJSON(b)}function g(a){var b,c,d=[],e=h.length;for(b=0;bc)}}),c}(),g=function(){"use strict";function c(a){a=a||{},this.maxPendingRequests=a.maxPendingRequests||6,this.cancelled=!1,this.lastReq=null,this._send=a.transport,this._get=a.limiter?a.limiter(this._get):this._get,this._cache=a.cache===!1?new e(0):g}var d=0,f={},g=new e(10);return c.setMaxPendingRequests=function(a){this.maxPendingRequests=a},c.resetCache=function(){g.reset()},b.mixin(c.prototype,{_fingerprint:function(b){return b=b||{},b.url+b.type+a.param(b.data||{})},_get:function(a,b){function c(a){b(null,a),j._cache.set(h,a)}function e(){b(!0)}function g(){d--,delete f[h],j.onDeckRequestArgs&&(j._get.apply(j,j.onDeckRequestArgs),j.onDeckRequestArgs=null)}var h,i,j=this;h=this._fingerprint(a),this.cancelled||h!==this.lastReq||((i=f[h])?i.done(c).fail(e):db[d]?d++:(e.push(a[c]),c++,d++);return e}var h="c",i="i";return b.mixin(c.prototype,{bootstrap:function(a){this.datums=a.datums,this.trie=a.trie},add:function(a){var c=this;a=b.isArray(a)?a:[a],b.each(a,function(a){var f,g;c.datums[f=c.identify(a)]=a,g=d(c.datumTokenizer(a)),b.each(g,function(a){var b,d,g;for(b=c.trie,d=a.split("");g=d.shift();)b=b[h][g]||(b[h][g]=e()),b[i].push(f)})})},get:function(a){var c=this;return b.map(a,function(a){return c.datums[a]})},search:function(a){var c,e,j=this;return c=d(this.queryTokenizer(a)),b.each(c,function(a){var b,c,d,f;if(e&&0===e.length&&!j.matchAnyQueryToken)return!1;for(b=j.trie,c=a.split("");b&&(d=c.shift());)b=b[h][d];if(b&&0===c.length)f=b[i].slice(0),e=e?g(e,f):f;else if(!j.matchAnyQueryToken)return e=[],!1}),e?b.map(f(e),function(a){return j.datums[a]}):[]},all:function(){var a=[];for(var b in this.datums)a.push(this.datums[b]);return a},reset:function(){this.datums={},this.trie=e()},serialize:function(){return{datums:this.datums,trie:this.trie}}}),c}(),i=function(){"use strict";function a(a){this.url=a.url,this.ttl=a.ttl,this.cache=a.cache,this.prepare=a.prepare,this.transform=a.transform,this.transport=a.transport,this.thumbprint=a.thumbprint,this.storage=new f(a.cacheKey)}var c;return c={data:"data",protocol:"protocol",thumbprint:"thumbprint"},b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},store:function(a){this.cache&&(this.storage.set(c.data,a,this.ttl),this.storage.set(c.protocol,location.protocol,this.ttl),this.storage.set(c.thumbprint,this.thumbprint,this.ttl))},fromCache:function(){var a,b={};return this.cache?(b.data=this.storage.get(c.data),b.protocol=this.storage.get(c.protocol),b.thumbprint=this.storage.get(c.thumbprint),a=b.thumbprint!==this.thumbprint||b.protocol!==location.protocol,b.data&&!a?b.data:null):null},fromNetwork:function(a){function b(){a(!0)}function c(b){a(null,e.transform(b))}var d,e=this;a&&(d=this.prepare(this._settings()),this.transport(d).fail(b).done(c))},clear:function(){return this.storage.clear(),this}}),a}(),j=function(){"use strict";function a(a){this.url=a.url,this.prepare=a.prepare,this.transform=a.transform,this.indexResponse=a.indexResponse,this.transport=new g({cache:a.cache,limiter:a.limiter,transport:a.transport,maxPendingRequests:a.maxPendingRequests})}return b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},get:function(a,b){function c(a,c){b(a?[]:e.transform(c))}var d,e=this;if(b)return a=a||"",d=this.prepare(a,this._settings()),this.transport.get(d,c)},cancelLastRequest:function(){this.transport.cancel()}}),a}(),k=function(){"use strict";function d(d){var e;return d?(e={url:null,ttl:864e5,cache:!0,cacheKey:null,thumbprint:"",prepare:b.identity,transform:b.identity,transport:null},d=b.isString(d)?{url:d}:d,d=b.mixin(e,d),!d.url&&a.error("prefetch requires url to be set"),d.transform=d.filter||d.transform,d.cacheKey=d.cacheKey||d.url,d.thumbprint=c+d.thumbprint,d.transport=d.transport?h(d.transport):a.ajax,d):null}function e(c){var d;if(c)return d={url:null,cache:!0,prepare:null,replace:null,wildcard:null,limiter:null,rateLimitBy:"debounce",rateLimitWait:300,transform:b.identity,transport:null},c=b.isString(c)?{url:c}:c,c=b.mixin(d,c),!c.url&&a.error("remote requires url to be set"),c.transform=c.filter||c.transform,c.prepare=f(c),c.limiter=g(c),c.transport=c.transport?h(c.transport):a.ajax,delete c.replace,delete c.wildcard,delete c.rateLimitBy,delete c.rateLimitWait,c}function f(a){function b(a,b){return b.url=f(b.url,a),b}function c(a,b){return b.url=b.url.replace(g,encodeURIComponent(a)),b}function d(a,b){return b}var e,f,g;return e=a.prepare,f=a.replace,g=a.wildcard,e?e:e=f?b:a.wildcard?c:d}function g(a){function c(a){return function(c){return b.debounce(c,a)}}function d(a){return function(c){return b.throttle(c,a)}}var e,f,g;return e=a.limiter,f=a.rateLimitBy,g=a.rateLimitWait,e||(e=/^throttle$/i.test(f)?d(g):c(g)),e}function h(c){return function(d){function e(a){b.defer(function(){g.resolve(a)})}function f(a){b.defer(function(){g.reject(a)})}var g=a.Deferred();return c(d,e,f),g}}return function(c){var f,g;return f={initialize:!0,identify:b.stringify,datumTokenizer:null,queryTokenizer:null,matchAnyQueryToken:!1,sufficient:5,indexRemote:!1,sorter:null,local:[],prefetch:null,remote:null},c=b.mixin(f,c||{}),!c.datumTokenizer&&a.error("datumTokenizer is required"),!c.queryTokenizer&&a.error("queryTokenizer is required"),g=c.sorter,c.sorter=g?function(a){return a.sort(g)}:b.identity,c.local=b.isFunction(c.local)?c.local():c.local,c.prefetch=d(c.prefetch),c.remote=e(c.remote),c}}(),l=function(){"use strict";function c(a){a=k(a),this.sorter=a.sorter,this.identify=a.identify,this.sufficient=a.sufficient,this.indexRemote=a.indexRemote,this.local=a.local,this.remote=a.remote?new j(a.remote):null,this.prefetch=a.prefetch?new i(a.prefetch):null,this.index=new h({identify:this.identify,datumTokenizer:a.datumTokenizer,queryTokenizer:a.queryTokenizer}),a.initialize!==!1&&this.initialize()}var e;return e=window&&window.Bloodhound,c.noConflict=function(){return window&&(window.Bloodhound=e),c},c.tokenizers=d,b.mixin(c.prototype,{__ttAdapter:function(){function a(a,b,d){return c.search(a,b,d)}function b(a,b){return c.search(a,b)}var c=this;return this.remote?a:b},_loadPrefetch:function(){function b(a,b){return a?c.reject():(e.add(b),e.prefetch.store(e.index.serialize()),void c.resolve())}var c,d,e=this;return c=a.Deferred(),this.prefetch?(d=this.prefetch.fromCache())?(this.index.bootstrap(d),c.resolve()):this.prefetch.fromNetwork(b):c.resolve(),c.promise()},_initialize:function(){function a(){b.add(b.local)}var b=this;return this.clear(),(this.initPromise=this._loadPrefetch()).done(a),this.initPromise},initialize:function(a){return!this.initPromise||a?this._initialize():this.initPromise},add:function(a){return this.index.add(a),this},get:function(a){return a=b.isArray(a)?a:[].slice.call(arguments),this.index.get(a)},search:function(a,c,d){function e(a){var c=[];b.each(a,function(a){!b.some(f,function(b){return g.identify(a)===g.identify(b)})&&c.push(a)}),g.indexRemote&&g.add(c),d(c)}var f,g=this;return c=c||b.noop,d=d||b.noop,f=this.sorter(this.index.search(a)),c(this.remote?f.slice():f),this.remote&&f.length',menu:'
'}}function d(a){var c={};return b.each(a,function(a,b){c[b]="."+a}),c}function e(){var a={wrapper:{position:"relative",display:"inline-block"},hint:{position:"absolute",top:"0",left:"0",borderColor:"transparent",boxShadow:"none",opacity:"1"},input:{position:"relative",verticalAlign:"top",backgroundColor:"transparent"},inputWithNoHint:{position:"relative",verticalAlign:"top"},menu:{position:"absolute",top:"100%",left:"0",zIndex:"100",display:"none"},ltr:{left:"0",right:"auto"},rtl:{left:"auto",right:" 0"}};return b.isMsie()&&b.mixin(a.input,{backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"}),a}var f={wrapper:"twitter-typeahead",input:"tt-input",hint:"tt-hint",menu:"tt-menu",dataset:"tt-dataset",suggestion:"tt-suggestion",selectable:"tt-selectable",empty:"tt-empty",open:"tt-open",cursor:"tt-cursor",highlight:"tt-highlight"};return a}(),d=function(){"use strict";function c(b){b&&b.el||a.error("EventBus initialized without el"),this.$el=a(b.el)}var d,e;return d="typeahead:",e={render:"rendered",cursorchange:"cursorchanged",select:"selected",autocomplete:"autocompleted"},b.mixin(c.prototype,{_trigger:function(b,c){var e=a.Event(d+b);return this.$el.trigger.call(this.$el,e,c||[]),e},before:function(a){var b,c;return b=[].slice.call(arguments,1),c=this._trigger("before"+a,b),c.isDefaultPrevented()},trigger:function(a){var b;this._trigger(a,[].slice.call(arguments,1)),(b=e[a])&&this._trigger(b,[].slice.call(arguments,1))}}),c}(),e=function(){"use strict";function a(a,b,c,d){var e;if(!c)return this;for(b=b.split(i),c=d?h(c,d):c,this._callbacks=this._callbacks||{};e=b.shift();)this._callbacks[e]=this._callbacks[e]||{sync:[],async:[]},this._callbacks[e][a].push(c);return this}function b(b,c,d){return a.call(this,"async",b,c,d)}function c(b,c,d){return a.call(this,"sync",b,c,d)}function d(a){var b;if(!this._callbacks)return this;for(a=a.split(i);b=a.shift();)delete this._callbacks[b];return this}function e(a){var b,c,d,e,g;if(!this._callbacks)return this;for(a=a.split(i),d=[].slice.call(arguments,1);(b=a.shift())&&(c=this._callbacks[b]);)e=f(c.sync,this,[b].concat(d)),g=f(c.async,this,[b].concat(d)),e()&&j(g);return this}function f(a,b,c){function d(){for(var d,e=0,f=a.length;!d&&e