/* * typeahead.js 0.10.2 * https://github.com/twitter/typeahead.js * Copyright 2013-2014 Twitter, Inc. and other contributors; Licensed MIT */ (function(b){var r={isMsie:function(){return/(msie|trident)/i.test(navigator.userAgent)?navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2]:false},isBlankString:function(t){return !t||/^\s*$/.test(t)},escapeRegExChars:function(t){return t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isString:function(t){return typeof t==="string"},isNumber:function(t){return typeof t==="number"},isArray:b.isArray,isFunction:b.isFunction,isObject:b.isPlainObject,isUndefined:function(t){return typeof t==="undefined"},bind:b.proxy,each:function(v,t){b.each(v,u);function u(w,x){return t(x,w)}},map:b.map,filter:b.grep,every:function(u,v){var t=true;if(!u){return t}b.each(u,function(w,x){if(!(t=v.call(null,x,w,u))){return false}});return !!t},some:function(u,v){var t=false;if(!u){return t}b.each(u,function(w,x){if(t=v.call(null,x,w,u)){return false}});return !!t},mixin:b.extend,getUniqueId:function(){var t=0;return function(){return t++}}(),templatify:function e(u){return b.isFunction(u)?u:t;function t(){return String(u)}},defer:function(t){setTimeout(t,0)},debounce:function(v,x,u){var w,t;return function(){var B=this,A=arguments,z,y;z=function(){w=null;if(!u){t=v.apply(B,A)}};y=u&&!w;clearTimeout(w);w=setTimeout(z,x);if(y){t=v.apply(B,A)}return t}},throttle:function(y,A){var w,v,z,t,x,u;x=0;u=function(){x=new Date();z=null;t=y.apply(w,v)};return function(){var B=new Date(),C=A-(B-x);w=this;v=arguments;if(C<=0){clearTimeout(z);z=null;x=B;t=y.apply(w,v)}else{if(!z){z=setTimeout(u,C)}}return t}},noop:function(){}};var n="0.10.2";var o=function(u){return{nonword:t,whitespace:v,obj:{nonword:w(t),whitespace:w(v)}};function v(x){return x.split(/\s+/)}function t(x){return x.split(/\W+/)}function w(y){return function x(z){return function A(B){return y(B[z])}}}}();var d=function(){function u(A){this.maxSize=A||100;this.size=0;this.hash={};this.list=new x()}r.mixin(u.prototype,{set:function z(A,D){var C=this.list.tail,B;if(this.size>=this.maxSize){this.list.remove(C);delete this.hash[C.key]}if(B=this.hash[A]){B.val=D;this.list.moveToFront(B)}else{B=new v(A,D);this.list.add(B);this.hash[A]=B;this.size++}},get:function w(A){var B=this.hash[A];if(B){this.list.moveToFront(B);return B.val}}});function x(){this.head=this.tail=null}r.mixin(x.prototype,{add:function y(A){if(this.head){A.next=this.head;this.head.prev=A}this.head=A;this.tail=this.tail||A},remove:function t(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)}});function v(A,B){this.key=A;this.val=B;this.prev=this.next=null}return u}();var p=function(){var t,u;try{t=window.localStorage;t.setItem("~~~","!");t.removeItem("~~~")}catch(y){t=null}function w(A){this.prefix=["__",A,"__"].join("");this.ttlKey="__ttl__";this.keyMatcher=new RegExp("^"+this.prefix)}if(t&&window.JSON){u={_prefix:function(A){return this.prefix+A},_ttlKey:function(A){return this._prefix(A)+this.ttlKey},get:function(A){if(this.isExpired(A)){this.remove(A)}return z(t.getItem(this._prefix(A)))},set:function(B,C,A){if(r.isNumber(A)){t.setItem(this._ttlKey(B),x(v()+A))}else{t.removeItem(this._ttlKey(B))}return t.setItem(this._prefix(B),x(C))},remove:function(A){t.removeItem(this._ttlKey(A));t.removeItem(this._prefix(A));return this},clear:function(){var C,B,D=[],A=t.length;for(C=0;CA?true:false}}}else{u={get:r.noop,set:r.noop,remove:r.noop,clear:r.noop,isExpired:r.noop}}r.mixin(w.prototype,u);return w;function v(){return new Date().getTime()}function x(A){return JSON.stringify(r.isUndefined(A)?null:A)}function z(A){return JSON.parse(A)}}();var q=function(){var v=0,w={},t=6,z=new d(10);function A(B){B=B||{};this._send=B.transport?x(B.transport):b.ajax;this._get=B.rateLimiter?B.rateLimiter(this._get):this._get}A.setMaxPendingRequests=function u(B){t=B};A.resetCache=function y(){z=new d(10)};r.mixin(A.prototype,{_get:function(F,I,C){var H=this,G;if(G=w[F]){G.done(E).fail(D)}else{if(vD[E]){E++}else{H.push(F[C]);C++;E++}}}return H;function G(J,I){return J-I}}}();var g=function(){return{local:v,prefetch:t,remote:u};function v(w){return w.local||null}function t(y){var x,w;w={url:null,thumbprint:"",ttl:24*60*60*1000,filter:null,ajax:{}};if(x=y.prefetch||null){x=r.isString(x)?{url:x}:x;x=r.mixin(w,x);x.thumbprint=n+x.thumbprint;x.ajax.type=x.ajax.type||"GET";x.ajax.dataType=x.ajax.dataType||"json";!x.url&&b.error("prefetch requires url to be set")}return x}function u(A){var y,z;z={url:null,wildcard:"%QUERY",replace:null,rateLimitBy:"debounce",rateLimitWait:300,send:null,filter:null,ajax:{}};if(y=A.remote||null){y=r.isString(y)?{url:y}:y;y=r.mixin(z,y);y.rateLimiter=/^throttle$/i.test(y.rateLimitBy)?x(y.rateLimitWait):w(y.rateLimitWait);y.ajax.type=y.ajax.type||"GET";y.ajax.dataType=y.ajax.dataType||"json";delete y.rateLimitBy;delete y.rateLimitWait;!y.url&&b.error("remote requires url to be set")}return y;function w(B){return function(C){return r.debounce(C,B)}}function x(B){return function(C){return r.throttle(C,B)}}}}();(function(E){var t,z;t=E.Bloodhound;z={data:"data",protocol:"protocol",thumbprint:"thumbprint"};E.Bloodhound=v;function v(L){if(!L||!L.local&&!L.prefetch&&!L.remote){b.error("one of local, prefetch, or remote is required")}this.limit=L.limit||5;this.sorter=C(L.sorter);this.dupDetector=L.dupDetector||B;this.local=g.local(L);this.prefetch=g.prefetch(L);this.remote=g.remote(L);this.cacheKey=this.prefetch?this.prefetch.cacheKey||this.prefetch.url:null;this.index=new j({datumTokenizer:L.datumTokenizer,queryTokenizer:L.queryTokenizer});this.storage=this.cacheKey?new p(this.cacheKey):null}v.noConflict=function K(){E.Bloodhound=t;return v};v.tokenizers=o;r.mixin(v.prototype,{_loadPrefetch:function w(P){var M=this,O,L;if(O=this._readFromStorage(P.thumbprint)){this.index.bootstrap(O);L=b.Deferred().resolve()}else{L=b.ajax(P.url,P.ajax).done(N)}return L;function N(Q){M.clear();M.add(P.filter?P.filter(Q):Q);M._saveToStorage(M.index.serialize(),P.thumbprint,P.ttl)}},_getFromRemote:function y(Q,L){var P=this,N,O;Q=Q||"";O=encodeURIComponent(Q);N=this.remote.replace?this.remote.replace(this.remote.url,Q):this.remote.url.replace(this.remote.wildcard,O);return this.transport.get(N,this.remote.ajax,M);function M(R,S){R?L([]):L(P.remote.filter?P.remote.filter(S):S)}},_saveToStorage:function F(N,M,L){if(this.storage){this.storage.set(z.data,N,L);this.storage.set(z.protocol,location.protocol,L);this.storage.set(z.thumbprint,M,L)}},_readFromStorage:function J(M){var L={},N;if(this.storage){L.data=this.storage.get(z.data);L.protocol=this.storage.get(z.protocol);L.thumbprint=this.storage.get(z.thumbprint)}N=L.thumbprint!==M||L.protocol!==location.protocol;return L.data&&!N?L.data:null},_initialize:function u(){var O=this,N=this.local,L;L=this.prefetch?this._loadPrefetch(this.prefetch):b.Deferred().resolve();N&&L.done(M);this.transport=this.remote?new q(this.remote):null;return this.initPromise=L.promise();function M(){O.add(r.isFunction(N)?N():N)}},initialize:function u(L){return !this.initPromise||L?this._initialize():this.initPromise},add:function A(L){this.index.add(L)},get:function H(P,L){var N=this,O=[],M=false;O=this.index.get(P);O=this.sorter(O).slice(0,this.limit);if(O.length0||!this.transport)&&L&&L(O)}function Q(S){var R=O.slice(0);r.each(S,function(U){var T;T=r.some(R,function(V){return N.dupDetector(U,V)});!T&&R.push(U);return R.length