!function(a,b){"function"==typeof define&&define.amd?define("bloodhound",["jquery"],function(c){return a.Bloodhound=b(c)}):"object"==typeof exports?module.exports=b(require("jquery")):a.Bloodhound=b(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(c){return b.isUndefined(c)||null===c?"":c+""},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(c){function d(){return String(c)}return a.isFunction(c)?c:d},defer:function(a){setTimeout(a,0)},debounce:function(a,b,c){var d,e;return function(){var h,i,f=this,g=arguments;return h=function(){d=null,c||(e=a.apply(f,g))},i=c&&!d,clearTimeout(d),d=setTimeout(h,b),i&&(e=a.apply(f,g)),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)},noop:function(){}}}(),c="0.11.1",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){return function(d){return d=b.isArray(d)?d:[].slice.call(arguments,0),function(e){var f=[];return b.each(d,function(c){f=f.concat(a(b.toStr(e[c])))}),f}}}return{nonword:c,whitespace:a,obj:{nonword:d(c),whitespace:d(a)}}}(),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(b,c){var f,d=this.list.tail;this.size>=this.maxSize&&(this.list.remove(d),delete this.hash[d.key],this.size--),(f=this.hash[b])?(f.val=c,this.list.moveToFront(f)):(f=new e(b,c),this.list.add(f),this.hash[b]=f,this.size++)},get:function(b){var c=this.hash[b];if(c)return this.list.moveToFront(c),c.val},reset:function(){this.size=0,this.hash={},this.list=new d}}),b.mixin(d.prototype,{add:function(b){this.head&&(b.next=this.head,this.head.prev=b),this.head=b,this.tail=this.tail||b},remove:function(b){b.prev?b.prev.next=b.next:this.head=b.next,b.next?b.next.prev=b.prev:this.tail=b.prev},moveToFront:function(a){this.remove(a),this.add(a)}}),c}(),f=function(){"use strict";function d(a,d){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+b.escapeRegExChars(this.prefix)),this.ls=d||c,!this.ls&&this._noop()}function e(){return(new Date).getTime()}function f(a){return JSON.stringify(b.isUndefined(a)?null:a)}function g(b){return a.parseJSON(b)}function h(a){var b,d,e=[],f=c.length;for(b=0;bc)}}),d}(),g=function(){"use strict";function h(a){a=a||{},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 c=0,d={},f=6,g=new e(10);return h.setMaxPendingRequests=function(b){f=b},h.resetCache=function(){g.reset()},b.mixin(h.prototype,{_fingerprint:function(c){return c=c||{},c.url+c.type+a.param(c.data||{})},_get:function(a,b){function i(a){b(null,a),e._cache.set(g,a)}function j(){b(!0)}function k(){c--,delete d[g],e.onDeckRequestArgs&&(e._get.apply(e,e.onDeckRequestArgs),e.onDeckRequestArgs=null)}var g,h,e=this;g=this._fingerprint(a),this.cancelled||g!==this.lastReq||((h=d[g])?h.done(i).fail(j):cb[d]?d++:(e.push(a[c]),c++,d++);return e}var c="c",d="i";return b.mixin(e.prototype,{bootstrap:function(b){this.datums=b.datums,this.trie=b.trie},add:function(a){var e=this;a=b.isArray(a)?a:[a],b.each(a,function(a){var h,i;e.datums[h=e.identify(a)]=a,i=f(e.datumTokenizer(a)),b.each(i,function(a){var b,f,i;for(b=e.trie,f=a.split("");i=f.shift();)b=b[c][i]||(b[c][i]=g()),b[d].push(h)})})},get:function(c){var d=this;return b.map(c,function(a){return d.datums[a]})},search:function(e){var j,k,g=this;return j=f(this.queryTokenizer(e)),b.each(j,function(a){var b,e,f,h;if(k&&0===k.length)return!1;for(b=g.trie,e=a.split("");b&&(f=e.shift());)b=b[c][f];return b&&0===e.length?(h=b[d].slice(0),void(k=k?i(k,h):h)):(k=[],!1)}),k?b.map(h(k),function(a){return g.datums[a]}):[]},all:function(){var b=[];for(var c in this.datums)b.push(this.datums[c]);return b},reset:function(){this.datums={},this.trie=g()},serialize:function(){return{datums:this.datums,trie:this.trie}}}),e}(),i=function(){"use strict";function c(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 a;return a={data:"data",protocol:"protocol",thumbprint:"thumbprint"},b.mixin(c.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},store:function(c){this.cache&&(this.storage.set(a.data,c,this.ttl),this.storage.set(a.protocol,location.protocol,this.ttl),this.storage.set(a.thumbprint,this.thumbprint,this.ttl))},fromCache:function(){var d,c={};return this.cache?(c.data=this.storage.get(a.data),c.protocol=this.storage.get(a.protocol),c.thumbprint=this.storage.get(a.thumbprint),d=c.thumbprint!==this.thumbprint||c.protocol!==location.protocol,c.data&&!d?c.data:null):null},fromNetwork:function(a){function d(){a(!0)}function e(c){a(null,b.transform(c))}var c,b=this;a&&(c=this.prepare(this._settings()),this.transport(c).fail(d).done(e))},clear:function(){return this.storage.clear(),this}}),c}(),j=function(){"use strict";function a(a){this.url=a.url,this.prepare=a.prepare,this.transform=a.transform,this.transport=new g({cache:a.cache,limiter:a.limiter,transport:a.transport})}return b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},get:function(b,c){function f(a,b){c(a?[]:d.transform(b))}var e,d=this;if(c)return b=b||"",e=this.prepare(b,this._settings()),this.transport.get(e,f)},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 e(a,b){return b.url=c(b.url,a),b}function f(a,b){return b.url=b.url.replace(d,encodeURIComponent(a)),b}function g(a,b){return b}var b,c,d;return b=a.prepare,c=a.replace,d=a.wildcard,b?b:b=c?e:a.wildcard?f:g}function g(a){function f(a){return function(d){return b.debounce(d,a)}}function g(a){return function(d){return b.throttle(d,a)}}var c,d,e;return c=a.limiter,d=a.rateLimitBy,e=a.rateLimitWait,c||(c=/^throttle$/i.test(d)?g(e):f(e)),c}function h(c){return function(e){function g(a){b.defer(function(){f.resolve(a)})}function h(a){b.defer(function(){f.reject(a)})}var f=a.Deferred();return c(e,g,h),f}}return function(f){var g,h;return g={initialize:!0,identify:b.stringify,datumTokenizer:null,queryTokenizer:null,sufficient:5,sorter:null,local:[],prefetch:null,remote:null},f=b.mixin(g,f||{}),!f.datumTokenizer&&a.error("datumTokenizer is required"),!f.queryTokenizer&&a.error("queryTokenizer is required"),h=f.sorter,f.sorter=h?function(a){return a.sort(h)}:b.identity,f.local=b.isFunction(f.local)?f.local():f.local,f.prefetch=d(f.prefetch),f.remote=e(f.remote),f}}(),l=function(){"use strict";function e(a){a=k(a),this.sorter=a.sorter,this.identify=a.identify,this.sufficient=a.sufficient,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 c;return c=window&&window.Bloodhound,e.noConflict=function(){return window&&(window.Bloodhound=c),e},e.tokenizers=d,b.mixin(e.prototype,{__ttAdapter:function(){function c(a,c,d){return b.search(a,c,d)}function d(a,c){return b.search(a,c)}var b=this;return this.remote?c:d},_loadPrefetch:function(){function f(a,b){return a?d.reject():(c.add(b),c.prefetch.store(c.index.serialize()),void d.resolve())}var d,e,c=this;return d=a.Deferred(),this.prefetch?(e=this.prefetch.fromCache())?(this.index.bootstrap(e),d.resolve()):this.prefetch.fromNetwork(f):d.resolve(),d.promise()},_initialize:function(){function d(){b.add(b.local)}var b=this;return this.clear(),(this.initPromise=this._loadPrefetch()).done(d),this.initPromise},initialize:function(b){return!this.initPromise||b?this._initialize():this.initPromise},add:function(b){return this.index.add(b),this},get:function(c){return c=b.isArray(c)?c:[].slice.call(arguments),this.index.get(c)},search:function(c,d,e){function h(a){var c=[];b.each(a,function(a){!b.some(g,function(b){return f.identify(a)===f.identify(b)})&&c.push(a)}),e&&e(c)}var g,f=this;return g=this.sorter(this.index.search(c)),d(this.remote?g.slice():g),this.remote&&g.length',menu:'
'}}function e(a){var c={};return b.each(a,function(a,b){c[b]="."+a}),c}function f(){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 a={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 c}(),d=function(){"use strict";function e(b){b&&b.el||a.error("EventBus initialized without el"),this.$el=a(b.el)}var c,d;return c="typeahead:",d={render:"rendered",cursorchange:"cursorchanged",select:"selected",autocomplete:"autocompleted"},b.mixin(e.prototype,{_trigger:function(b,d){var e;return e=a.Event(c+b),(d=d||[]).unshift(e),this.$el.trigger.apply(this.$el,d),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=d[a])&&this._trigger(b,[].slice.call(arguments,1))}}),e}(),e=function(){"use strict";function c(b,c,d,e){var f;if(!d)return this;for(c=c.split(a),d=e?j(d,e):d,this._callbacks=this._callbacks||{};f=c.shift();)this._callbacks[f]=this._callbacks[f]||{sync:[],async:[]},this._callbacks[f][b].push(d);return this}function d(a,b,d){return c.call(this,"async",a,b,d)}function e(a,b,d){return c.call(this,"sync",a,b,d)}function f(b){var c;if(!this._callbacks)return this;for(b=b.split(a);c=b.shift();)delete this._callbacks[c];return this}function g(c){var d,e,f,g,i;if(!this._callbacks)return this;for(c=c.split(a),f=[].slice.call(arguments,1);(d=c.shift())&&(e=this._callbacks[d]);)g=h(e.sync,this,[d].concat(f)),i=h(e.async,this,[d].concat(f)),g()&&b(i);return this}function h(a,b,c){function d(){for(var d,e=0,f=a.length;!d&&e