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