src/pyams_skin/resources/js/ext/jquery-typeahead.min.js
changeset 0 bb4aabe07487
child 475 79ae32c82e3e
equal deleted inserted replaced
-1:000000000000 0:bb4aabe07487
       
     1 /*
       
     2  * typeahead.js 0.10.0
       
     3  * https://github.com/twitter/typeahead.js
       
     4  * Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT
       
     5  */
       
     6 (function(c){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:c.isArray,isFunction:c.isFunction,isObject:c.isPlainObject,isUndefined:function(t){return typeof t==="undefined"},bind:c.proxy,each:function(v,t){c.each(v,u);function u(w,x){return t(x,w)}},map:c.map,filter:c.grep,every:function(u,v){var t=true;if(!u){return t}c.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}c.each(u,function(w,x){if(t=v.call(null,x,w,u)){return false}});return !!t},mixin:c.extend,getUniqueId:function(){var t=0;return function(){return t++}}(),templatify:function f(u){return c.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 o="0.10.0";var e=function(x,u){function B(C){this.maxSize=C||100;this.size=0;this.hash={};this.list=new A()}r.mixin(B.prototype,{set:function y(C,F){var E=this.list.tail,D;if(this.size>=this.maxSize){this.list.remove(E);delete this.hash[E.key]}if(D=this.hash[C]){D.val=F;this.list.moveToFront(D)}else{D=new w(C,F);this.list.add(D);this.hash[C]=D;this.size++}},get:function t(C){var D=this.hash[C];if(D){this.list.moveToFront(D);return D.val}}});function A(){this.head=this.tail=null}r.mixin(A.prototype,{add:function z(C){if(this.head){C.next=this.head;this.head.prev=C}this.head=C;this.tail=this.tail||C},remove:function v(C){C.prev?C.prev.next=C.next:this.head=C.next;C.next?C.next.prev=C.prev:this.tail=C.prev},moveToFront:function(C){this.remove(C);this.add(C)}});function w(C,D){this.key=C;this.val=D;this.prev=this.next=null}return B}(this);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;C<A;C++){if((B=t.key(C)).match(this.keyMatcher)){D.push(B.replace(this.keyMatcher,""))}}for(C=D.length;C--;){this.remove(D[C])}return this},isExpired:function(B){var A=z(t.getItem(this._ttlKey(B)));return r.isNumber(A)&&v()>A?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 e(10);function A(B){B=B||{};this._send=B.send?x(B.send):c.ajax;this._get=B.rateLimiter?B.rateLimiter(this._get):this._get}A.setMaxPendingRequests=function u(B){t=B};A.resetCache=function y(){z=new e(10)};r.mixin(A.prototype,{_get:function(E,H,C){var G=this,F;if(F=w[E]){F.done(D)}else{if(v<t){v++;w[E]=this._send(E,H).done(D).always(B)}else{this.onDeckRequestArgs=[].slice.call(arguments,0)}}function D(I){C&&C(I);z.set(E,I)}function B(){v--;delete w[E];if(G.onDeckRequestArgs){G._get.apply(G,G.onDeckRequestArgs);G.onDeckRequestArgs=null}}},get:function(C,F,B){var D=this,E;if(r.isFunction(F)){B=F;F={}}if(E=z.get(C)){r.defer(function(){B&&B(E)})}else{this._get(C,F,B)}return !!E}});return A;function x(B){return function C(E,H){var D=c.Deferred();B(E,H,G,F);return D;function G(I){r.defer(function(){D.resolve(I)})}function F(I){r.defer(function(){D.reject(I)})}}}}();var k=function(){function y(B){B=B||{};if(!B.datumTokenizer||!B.queryTokenizer){c.error("datumTokenizer and queryTokenizer are both required")}this.datumTokenizer=B.datumTokenizer;this.queryTokenizer=B.queryTokenizer;this.datums=[];this.trie=v()}r.mixin(y.prototype,{bootstrap:function w(B){this.datums=B.datums;this.trie=B.trie},add:function(C){var B=this;C=r.isArray(C)?C:[C];r.each(C,function(D){var F,E;F=B.datums.push(D)-1;E=t(B.datumTokenizer(D));r.each(E,function(G){var K,J,I,H;K=B.trie;J=G.split("");while(I=J.shift()){K=K.children[I]||(K.children[I]=v());K.ids.push(F)}})})},get:function u(D){var B=this,E,C;E=t(this.queryTokenizer(D));r.each(E,function(F){var J,I,H,G;if(C&&C.length===0){return false}J=B.trie;I=F.split("");while(J&&(H=I.shift())){J=J.children[H]}if(J&&I.length===0){G=J.ids.slice(0);C=C?z(C,G):G}else{C=[];return false}});return C?r.map(A(C),function(F){return B.datums[F]}):[]},serialize:function x(){return{datums:this.datums,trie:this.trie}}});return y;function t(B){B=r.filter(B,function(C){return !!C});B=r.map(B,function(C){return C.toLowerCase()});return B}function v(){return{ids:[],children:{}}}function A(E){var B={},D=[];for(var C=0;C<E.length;C++){if(!B[E[C]]){B[E[C]]=true;D.push(E[C])}}return D}function z(E,C){var B=0,D=0,G=[];E=E.sort(F);C=C.sort(F);while(B<E.length&&D<C.length){if(E[B]<C[D]){B++}else{if(E[B]>C[D]){D++}else{G.push(E[B]);B++;D++}}}return G;function F(I,H){return I-H}}}();var h=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=o+x.thumbprint;x.ajax.method=x.ajax.method||"get";x.ajax.dataType=x.ajax.dataType||"json";!x.url&&c.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.method=y.ajax.method||"get";y.ajax.dataType=y.ajax.dataType||"json";delete y.rateLimitBy;delete y.rateLimitWait;!y.url&&c.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)}}}}();var a=window.Bloodhound=function(){var G;G={data:"data",protocol:"protocol",thumbprint:"thumbprint"};function A(H){if(!H||!H.local&&!H.prefetch&&!H.remote){c.error("one of local, prefetch, or remote is required")}this.limit=H.limit||5;this.sorter=H.sorter||C;this.dupDetector=H.dupDetector||v;this.local=h.local(H);this.prefetch=h.prefetch(H);this.remote=h.remote(H);this.cacheKey=this.prefetch?this.prefetch.cacheKey||this.prefetch.url:null;this.index=new k({datumTokenizer:H.datumTokenizer,queryTokenizer:H.queryTokenizer});this.storage=this.cacheKey?new p(this.cacheKey):null}A.tokenizers={whitespace:function x(H){return H.split(/\s+/)},nonword:function z(H){return H.split(/\W+/)}};r.mixin(A.prototype,{_loadPrefetch:function t(L){var I=this,K,H;if(K=this._readFromStorage(L.thumbprint)){this.index.bootstrap(K);H=c.Deferred().resolve()}else{H=c.ajax(L.url,L.ajax).done(J)}return H;function J(N){var M;M=L.filter?L.filter(N):N;I.add(M);I._saveToStorage(I.index.serialize(),L.thumbprint,L.ttl)}},_getFromRemote:function u(M,H){var L=this,J,K;M=M||"";K=encodeURIComponent(M);J=this.remote.replace?this.remote.replace(this.remote.url,M):this.remote.url.replace(this.remote.wildcard,K);return this.transport.get(J,this.remote.ajax,I);function I(O){var N=L.remote.filter?L.remote.filter(O):O;H(N)}},_saveToStorage:function D(J,I,H){if(this.storage){this.storage.set(G.data,J,H);this.storage.set(G.protocol,location.protocol,H);this.storage.set(G.thumbprint,I,H)}},_readFromStorage:function F(I){var H={};if(this.storage){H.data=this.storage.get(G.data);H.protocol=this.storage.get(G.protocol);H.thumbprint=this.storage.get(G.thumbprint)}isExpired=H.thumbprint!==I||H.protocol!==location.protocol;return H.data&&!isExpired?H.data:null},initialize:function y(){var K=this,I;I=this.prefetch?this._loadPrefetch(this.prefetch):c.Deferred().resolve();this.local&&I.done(J);this.transport=this.remote?new q(this.remote):null;this.initialize=function H(){return I.promise()};return I.promise();function J(){K.add(K.local)}},add:function E(H){this.index.add(H)},get:function w(L,H){var J=this,K,I=false;K=this.index.get(L).sort(this.sorter).slice(0,this.limit);if(K.length<this.limit&&this.transport){I=this._getFromRemote(L,M)}!I&&H&&H(K);function M(O){var N=K.slice(0);r.each(O,function(Q){var P;P=r.some(N,function(R){return J.dupDetector(Q,R)});!P&&N.push(Q);return N.length<J.limit});H&&H(N.sort(J.sorter))}},ttAdapter:function B(){return r.bind(this.get,this)}});return A;function C(){return 0}function v(){return false}}();var j={wrapper:'<span class="twitter-typeahead"></span>',dropdown:'<span class="tt-dropdown-menu"></span>',dataset:'<div class="tt-dataset-%CLASS%"></div>',suggestions:'<span class="tt-suggestions"></span>',suggestion:'<div class="tt-suggestion">%BODY%</div>'};var i={wrapper:{position:"relative",display:"inline-block"},hint:{position:"absolute",top:"0",left:"0",borderColor:"transparent",boxShadow:"none"},input:{position:"relative",verticalAlign:"top",backgroundColor:"transparent"},inputWithNoHint:{position:"relative",verticalAlign:"top"},dropdown:{position:"absolute",top:"100%",left:"0",zIndex:"100",display:"none"},suggestions:{display:"block"},suggestion:{whiteSpace:"nowrap",cursor:"pointer"},suggestionChild:{whiteSpace:"normal"},ltr:{left:"0",right:"auto"},rtl:{left:"auto",right:" 0"}};if(r.isMsie()){r.mixin(i.input,{backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"})}if(r.isMsie()&&r.isMsie()<=7){r.mixin(i.input,{marginTop:"-1px"})}var b=function(){var u="typeahead:";function t(v){if(!v||!v.el){c.error("EventBus initialized without el")}this.$el=c(v.el)}r.mixin(t.prototype,{trigger:function(w){var v=[].slice.call(arguments,1);this.$el.trigger(u+w,v)}});return t}();var g=function(){var v=/\s+/,z=t();return{onSync:A,onAsync:u,off:w,trigger:x};function B(H,F,D,E){var G;if(!D){return this}F=F.split(v);D=E?C(D,E):D;this._callbacks=this._callbacks||{};while(G=F.shift()){this._callbacks[G]=this._callbacks[G]||{sync:[],async:[]};this._callbacks[G][H].push(D)}return this}function u(F,D,E){return B.call(this,"async",F,D,E)}function A(F,D,E){return B.call(this,"sync",F,D,E)}function w(D){var E;if(!this._callbacks){return this}D=D.split(v);while(E=D.shift()){delete this._callbacks[E]}return this}function x(E){var H=this,F,G,D,I,J;if(!this._callbacks){return this}E=E.split(v);D=[].slice.call(arguments,1);while((F=E.shift())&&(G=this._callbacks[F])){I=y(G.sync,this,[F].concat(D));J=y(G.async,this,[F].concat(D));I()&&z(J)}return this}function y(G,F,E){return D;function D(){var I;for(var H=0;!I&&H<G.length;H+=1){I=G[H].apply(F,E)===false}return !I}}function t(){var E,G;if(window.setImmediate){E=function F(H){setImmediate(function(){H()})}}else{E=function D(H){setTimeout(function(){H()},0)}}return E}function C(E,D){return E.bind?E.bind(D):function(){E.apply(D,[].slice.call(arguments,0))}}}();var d=function(w){var v={node:null,pattern:null,tagName:"strong",className:null,wordsOnly:false,caseSensitive:false};return function u(A){var x;A=r.mixin({},v,A);if(!A.node||!A.pattern){return}A.pattern=r.isArray(A.pattern)?A.pattern:[A.pattern];x=t(A.pattern,A.caseSensitive,A.wordsOnly);y(A.node,z);function z(D){var C,B;if(C=x.exec(D.data)){wrapperNode=w.createElement(A.tagName);A.className&&(wrapperNode.className=A.className);B=D.splitText(C.index);B.splitText(C[0].length);wrapperNode.appendChild(B.cloneNode(true));D.parentNode.replaceChild(wrapperNode,B)}return !!C}function y(E,F){var C,D=3;for(var B=0;B<E.childNodes.length;B++){C=E.childNodes[B];if(C.nodeType===D){B+=F(C)?1:0}else{y(C,F)}}}};function t(z,x,C){var B=[],A;for(var y=0;y<z.length;y++){B.push(r.escapeRegExChars(z[y]))}A=C?"\\b("+B.join("|")+")\\b":"("+B.join("|")+")";return x?new RegExp(A):new RegExp(A,"i")}}(window.document);var m=function(){var O;O={9:"tab",27:"esc",37:"left",39:"right",13:"enter",38:"up",40:"down"};function L(X){var V=this,W,S,U,T;X=X||{};if(!X.input){c.error("input is missing")}W=r.bind(this._onBlur,this);S=r.bind(this._onFocus,this);U=r.bind(this._onKeydown,this);T=r.bind(this._onInput,this);this.$hint=c(X.hint);this.$input=c(X.input).on("blur.tt",W).on("focus.tt",S).on("keydown.tt",U);if(this.$hint.length===0){this.setHintValue=this.getHintValue=this.clearHint=r.noop}if(!r.isMsie()){this.$input.on("input.tt",T)}else{this.$input.on("keydown.tt keypress.tt cut.tt paste.tt",function(Y){if(O[Y.which||Y.keyCode]){return}r.defer(r.bind(V._onInput,V,Y))})}this.query=this.$input.val();this.$overflowHelper=E(this.$input)}L.normalizeQuery=function(S){return(S||"").replace(/^\s*/g,"").replace(/\s{2,}/g," ")};r.mixin(L.prototype,g,{_onBlur:function C(S){this.resetInputValue();this.trigger("blurred")},_onFocus:function v(S){this.trigger("focused")},_onKeydown:function Q(S){var T=O[S.which||S.keyCode];this._managePreventDefault(T,S);if(T&&this._shouldTrigger(T,S)){this.trigger(T+"Keyed",S)}},_onInput:function t(S){this._checkInputValue()},_managePreventDefault:function x(W,V){var U,T,S;switch(W){case"tab":T=this.getHintValue();S=this.getInputValue();U=T&&T!==S&&!F(V);break;case"up":case"down":U=!F(V);break;default:U=false}U&&V.preventDefault()},_shouldTrigger:function R(U,T){var S;switch(U){case"tab":S=!F(T);break;default:S=true}return S},_checkInputValue:function z(){var S,T,U;S=this.getInputValue();T=B(S,this.query);U=T?this.query.length!==S.length:false;if(!T){this.trigger("queryChanged",this.query=S)}else{if(U){this.trigger("whitespaceChanged",this.query)}}},focus:function H(){this.$input.focus()},blur:function M(){this.$input.blur()},getQuery:function J(){return this.query},setQuery:function I(S){this.query=S},getInputValue:function w(){return this.$input.val()},setInputValue:function A(T,S){this.$input.val(T);!S&&this._checkInputValue()},getHintValue:function N(){return this.$hint.val()},setHintValue:function y(S){this.$hint.val(S)},resetInputValue:function u(){this.$input.val(this.query)},clearHint:function D(){this.$hint.val("")},getLanguageDirection:function G(){return(this.$input.css("direction")||"ltr").toLowerCase()},hasOverflow:function K(){var S=this.$input.width()-2;this.$overflowHelper.text(this.getInputValue());return this.$overflowHelper.width()>=S},isCursorAtEnd:function(){var T,U,S;T=this.$input.val().length;U=this.$input[0].selectionStart;if(r.isNumber(U)){return U===T}else{if(document.selection){S=document.selection.createRange();S.moveStart("character",-T);return T===S.text.length}}return true},destroy:function P(){this.$hint.off(".tt");this.$input.off(".tt");this.$hint=this.$input=this.$overflowHelper=null}});return L;function E(S){return c('<pre aria-hidden="true"></pre>').css({position:"absolute",visibility:"hidden",whiteSpace:"nowrap",fontFamily:S.css("font-family"),fontSize:S.css("font-size"),fontStyle:S.css("font-style"),fontVariant:S.css("font-variant"),fontWeight:S.css("font-weight"),wordSpacing:S.css("word-spacing"),letterSpacing:S.css("letter-spacing"),textIndent:S.css("text-indent"),textRendering:S.css("text-rendering"),textTransform:S.css("text-transform")}).insertAfter(S)}function B(T,S){return L.normalizeQuery(T)===L.normalizeQuery(S)}function F(S){return S.altKey||S.ctrlKey||S.metaKey||S.shiftKey}}();var s=function(){var u="ttDataset",F="ttValue",A="ttDatum";function t(G){G=G||{};G.templates=G.templates||{};if(!G.source){c.error("missing source")}this.query=null;this.highlight=!!G.highlight;this.name=G.name||r.getUniqueId();this.source=G.source;this.valueKey=G.displayKey||"value";this.templates=w(G.templates,this.valueKey);this.$el=c(j.dataset.replace("%CLASS%",this.name))}t.extractDatasetName=function E(G){return c(G).data(u)};t.extractValue=function B(G){return c(G).data(F)};t.extractDatum=function B(G){return c(G).data(A)};r.mixin(t.prototype,g,{_render:function v(M,G){if(!this.$el){return}var L=this,I;this.$el.empty();I=G&&G.length;if(!I&&this.templates.empty){this.$el.html(H()).prepend(L.templates.header?K():null).append(L.templates.footer?J():null)}else{if(I){this.$el.html(N()).prepend(L.templates.header?K():null).append(L.templates.footer?J():null)}}this.trigger("rendered");function H(){return L.templates.empty({query:M})}function N(){var O;O=c(j.suggestions).css(i.suggestions).append(r.map(G,P));L.highlight&&d({node:O[0],pattern:M});return O;function P(S){var T,R,Q;R=L.templates.suggestion(S);Q=j.suggestion.replace("%BODY%",R);T=c(Q).data(u,L.name).data(F,S[L.valueKey]).data(A,S);T.children().each(function(){c(this).css(i.suggestionChild)});return T}}function K(){return L.templates.header({query:M,isEmpty:!I})}function J(){return L.templates.footer({query:M,isEmpty:!I})}},getRoot:function C(){return this.$el},update:function x(I){var H=this;this.query=I;this.source(I,G);function G(J){I===H.query&&H._render(I,J)}},clear:function z(){this._render(this.query||"")},isEmpty:function y(){return this.$el.is(":empty")},destroy:function D(){this.$el=null}});return t;function w(H,I){return{empty:H.empty&&r.templatify(H.empty),header:H.header&&r.templatify(H.header),footer:H.footer&&r.templatify(H.footer),suggestion:H.suggestion||G};function G(J){return"<p>"+J[I]+"</p>"}}}();var n=function(){function N(Z){var W=this,X,T,U,Y,V;Z=Z||{};if(!Z.menu){c.error("menu is required")}this.isOpen=false;this.isEmpty=true;this.isMouseOverDropdown=false;this.datasets=r.map(Z.datasets,D);X=r.bind(this._onMouseEnter,this);T=r.bind(this._onMouseLeave,this);U=r.bind(this._onSuggestionClick,this);Y=r.bind(this._onSuggestionMouseEnter,this);V=r.bind(this._onSuggestionMouseLeave,this);this.$menu=c(Z.menu).on("mouseenter.tt",X).on("mouseleave.tt",T).on("click.tt",".tt-suggestion",U).on("mouseenter.tt",".tt-suggestion",Y).on("mouseleave.tt",".tt-suggestion",V);r.each(this.datasets,function(aa){W.$menu.append(aa.getRoot());aa.onSync("rendered",W._onRendered,W)})}r.mixin(N.prototype,g,{_onMouseEnter:function F(T){this.isMouseOverDropdown=true},_onMouseLeave:function S(T){this.isMouseOverDropdown=false},_onSuggestionClick:function M(T){this.trigger("suggestionClicked",c(T.currentTarget))},_onSuggestionMouseEnter:function t(T){this._removeCursor();this._setCursor(c(T.currentTarget),true)},_onSuggestionMouseLeave:function H(T){this._removeCursor()},_onRendered:function z(){this.isEmpty=r.every(this.datasets,T);this.isEmpty?this._hide():this.isOpen&&this._show();this.trigger("datasetRendered");function T(U){return U.isEmpty()}},_hide:function(){this.$menu.hide()},_show:function(){this.$menu.css("display","block")},_getSuggestions:function y(){return this.$menu.find(".tt-suggestion")},_getCursor:function w(){return this.$menu.find(".tt-cursor").first()},_setCursor:function P(U,T){U.first().addClass("tt-cursor");!T&&this.trigger("cursorMoved")},_removeCursor:function v(){this._getCursor().removeClass("tt-cursor")},_moveCursor:function u(T){var V,U,X,W;if(!this.isOpen){return}U=this._getCursor();V=this._getSuggestions();this._removeCursor();X=V.index(U)+T;X=(X+1)%(V.length+1)-1;if(X===-1){this.trigger("cursorRemoved");return}else{if(X<-1){X=V.length-1}}this._setCursor(W=V.eq(X));this._ensureVisible(W)},_ensureVisible:function L(W){var T,V,U,X;T=W.position().top;V=T+W.outerHeight(true);U=this.$menu.scrollTop();X=this.$menu.height()+parseInt(this.$menu.css("paddingTop"),10)+parseInt(this.$menu.css("paddingBottom"),10);if(T<0){this.$menu.scrollTop(U+T)}else{if(X<V){this.$menu.scrollTop(U+(V-X))}}},close:function I(){if(this.isOpen){this.isOpen=this.isMouseOverDropdown=false;this._removeCursor();this._hide();this.trigger("closed")}},open:function G(){if(!this.isOpen){this.isOpen=true;!this.isEmpty&&this._show();this.trigger("opened")}},setLanguageDirection:function Q(T){this.$menu.css(T==="ltr"?i.ltr:i.rtl)},moveCursorUp:function A(){this._moveCursor(-1)},moveCursorDown:function R(){this._moveCursor(+1)},getDatumForSuggestion:function C(U){var T=null;if(U.length){T={raw:s.extractDatum(U),value:s.extractValue(U),datasetName:s.extractDatasetName(U)}}return T},getDatumForCursor:function x(){return this.getDatumForSuggestion(this._getCursor().first())},getDatumForTopSuggestion:function K(){return this.getDatumForSuggestion(this._getSuggestions().first())},update:function B(T){r.each(this.datasets,U);function U(V){V.update(T)}},empty:function E(){r.each(this.datasets,T);function T(U){U.clear()}},isVisible:function J(){return this.isOpen&&!this.isEmpty},destroy:function O(){this.$menu.off(".tt");this.$menu=null;r.each(this.datasets,T);function T(U){U.destroy()}}});return N;function D(T){return new s(T)}}();var l=function(){var U="ttAttrs";function C(ab){var aa,ac,Z,Y;ab=ab||{};if(!ab.input){c.error("missing input")}this.autoselect=!!ab.autoselect;this.minLength=r.isNumber(ab.minLength)?ab.minLength:1;this.$node=F(ab.input,ab.withHint);aa=this.$node.find(".tt-dropdown-menu");ac=this.$node.find(".tt-input");Z=this.$node.find(".tt-hint");this.eventBus=ab.eventBus||new b({el:ac});this.dropdown=new n({menu:aa,datasets:ab.datasets}).onSync("suggestionClicked",this._onSuggestionClicked,this).onSync("cursorMoved",this._onCursorMoved,this).onSync("cursorRemoved",this._onCursorRemoved,this).onSync("opened",this._onOpened,this).onSync("closed",this._onClosed,this).onAsync("datasetRendered",this._onDatasetRendered,this);this.input=new m({input:ac,hint:Z}).onSync("focused",this._onFocused,this).onSync("blurred",this._onBlurred,this).onSync("enterKeyed",this._onEnterKeyed,this).onSync("tabKeyed",this._onTabKeyed,this).onSync("escKeyed",this._onEscKeyed,this).onSync("upKeyed",this._onUpKeyed,this).onSync("downKeyed",this._onDownKeyed,this).onSync("leftKeyed",this._onLeftKeyed,this).onSync("rightKeyed",this._onRightKeyed,this).onSync("queryChanged",this._onQueryChanged,this).onSync("whitespaceChanged",this._onWhitespaceChanged,this);aa.on("mousedown.tt",function(ad){if(r.isMsie()&&r.isMsie()<9){ac[0].onbeforedeactivate=function(){window.event.returnValue=false;ac[0].onbeforedeactivate=null}}ad.preventDefault()})}r.mixin(C.prototype,{_onSuggestionClicked:function u(aa,Z){var Y;if(Y=this.dropdown.getDatumForSuggestion(Z)){this._select(Y)}},_onCursorMoved:function P(){var Y=this.dropdown.getDatumForCursor();this.input.clearHint();this.input.setInputValue(Y.value,true);this.eventBus.trigger("cursorchanged",Y.raw,Y.datasetName)},_onCursorRemoved:function x(){this.input.resetInputValue();this._updateHint()},_onDatasetRendered:function L(){this._updateHint()},_onOpened:function v(){this._updateHint();this.eventBus.trigger("opened")},_onClosed:function A(){this.input.clearHint();this.eventBus.trigger("closed")},_onFocused:function N(){this.dropdown.open()},_onBlurred:function O(){!this.dropdown.isMouseOverDropdown&&this.dropdown.close()},_onEnterKeyed:function I(Z,Y){var aa,ab;aa=this.dropdown.getDatumForCursor();ab=this.dropdown.getDatumForTopSuggestion();if(aa){this._select(aa);Y.preventDefault()}else{if(this.autoselect&&ab){this._select(ab);Y.preventDefault()}}},_onTabKeyed:function X(aa,Z){var Y;if(Y=this.dropdown.getDatumForCursor()){this._select(Y);Z.preventDefault()}else{this._autocomplete()}},_onEscKeyed:function S(){this.dropdown.close();this.input.resetInputValue()},_onUpKeyed:function t(){var Y=this.input.getQuery();if(!this.dropdown.isOpen&&Y.length>=this.minLength){this.dropdown.update(Y)}this.dropdown.open();this.dropdown.moveCursorUp()},_onDownKeyed:function y(){var Y=this.input.getQuery();if(!this.dropdown.isOpen&&Y.length>=this.minLength){this.dropdown.update(Y)}this.dropdown.open();this.dropdown.moveCursorDown()},_onLeftKeyed:function W(){this.dir==="rtl"&&this._autocomplete()},_onRightKeyed:function K(){this.dir==="ltr"&&this._autocomplete()},_onQueryChanged:function E(Z,Y){this.input.clearHint();this.dropdown.empty();Y.length>=this.minLength&&this.dropdown.update(Y);this.dropdown.open();this._setLanguageDirection()},_onWhitespaceChanged:function T(){this._updateHint();this.dropdown.open()},_setLanguageDirection:function R(){var Y;if(this.dir!==(Y=this.input.getLanguageDirection())){this.dir=Y;this.$node.css("direction",Y);this.dropdown.setLanguageDirection(Y)}},_updateHint:function M(){var aa,Z,ad,ac,Y,ab;aa=this.dropdown.getDatumForTopSuggestion();if(aa&&this.dropdown.isVisible()&&!this.input.hasOverflow()){Z=this.input.getInputValue();ad=m.normalizeQuery(Z);ac=r.escapeRegExChars(ad);Y=new RegExp("^(?:"+ac+")(.*$)","i");ab=Y.exec(aa.value);this.input.setHintValue(Z+(ab?ab[1]:""))}},_autocomplete:function V(){var aa,Z,Y;aa=this.input.getHintValue();Z=this.input.getQuery();if(aa&&Z!==aa&&this.input.isCursorAtEnd()){Y=this.dropdown.getDatumForTopSuggestion();Y&&this.input.setInputValue(Y.value);this.eventBus.trigger("autocompleted",Y.raw,Y.datasetName)}},_select:function G(Y){this.input.clearHint();this.input.setQuery(Y.value);this.input.setInputValue(Y.value,true);this.dropdown.empty();this._setLanguageDirection();r.defer(r.bind(this.dropdown.close,this.dropdown));this.eventBus.trigger("selected",Y.raw,Y.datasetName)},open:function B(){this.dropdown.open()},close:function D(){this.dropdown.close()},getQuery:function J(){return this.input.getQuery()},setQuery:function H(Y){this.input.setInputValue(Y)},destroy:function Q(){this.input.destroy();this.dropdown.destroy();w(this.$node);this.$node=null}});return C;function F(Y,ad){var ae,aa,ac,Z;ae=c(Y);aa=c(j.wrapper).css(i.wrapper);ac=c(j.dropdown).css(i.dropdown);Z=ae.clone().css(i.hint).css(z(ae));Z.removeData().addClass("tt-hint").removeAttr("id name placeholder").prop("disabled",true).attr({autocomplete:"off",spellcheck:"false"});ae.data(U,{dir:ae.attr("dir"),autocomplete:ae.attr("autocomplete"),spellcheck:ae.attr("spellcheck"),style:ae.attr("style")});ae.addClass("tt-input").attr({autocomplete:"off",spellcheck:false}).css(ad?i.input:i.inputWithNoHint);try{!ae.attr("dir")&&ae.attr("dir","auto")}catch(ab){}return ae.wrap(aa).parent().prepend(ad?Z:null).append(ac)}function z(Y){return{backgroundAttachment:Y.css("background-attachment"),backgroundClip:Y.css("background-clip"),backgroundColor:Y.css("background-color"),backgroundImage:Y.css("background-image"),backgroundOrigin:Y.css("background-origin"),backgroundPosition:Y.css("background-position"),backgroundRepeat:Y.css("background-repeat"),backgroundSize:Y.css("background-size")}}function w(Y){var Z=Y.find(".tt-input");r.each(Z.data(U),function(ab,aa){r.isUndefined(ab)?Z.removeAttr(aa):Z.attr(aa,ab)});Z.detach().removeData(U).removeClass("tt-input").insertAfter(Y);Y.remove()}}();(function(){var u,v;u="ttTypeahead";v={initialize:function t(C){var B=[].slice.call(arguments,1);C=C||{};return this.each(A);function A(){var G=c(this),D,F;r.each(B,function(H){H.highlight=!!C.highlight});F=new l({input:G,eventBus:D=new b({el:G}),withHint:r.isUndefined(C.hint)?true:!!C.hint,minLength:C.minLength,autoselect:C.autoselect,datasets:B});G.data(u,F);function E(H){return function(){r.defer(function(){D.trigger(H)})}}}},open:function w(){return this.each(A);function A(){var C=c(this),B;if(B=C.data(u)){B.open()}}},close:function z(){return this.each(A);function A(){var C=c(this),B;if(B=C.data(u)){B.close()}}},val:function y(B){return r.isString(B)?this.each(C):this.map(A).get();function C(){var E=c(this),D;if(D=E.data(u)){D.setQuery(B)}}function A(){var F=c(this),E,D;if(E=F.data(u)){D=E.getQuery()}return D}},destroy:function x(){return this.each(A);function A(){var C=c(this),B;if(B=C.data(u)){B.destroy();C.removeData(u)}}}};jQuery.fn.typeahead=function(A){if(v[A]){return v[A].apply(this,[].slice.call(arguments,1))}else{return v.initialize.apply(this,arguments)}}})()})(window.jQuery);