src/myams/resources/js/ext/jquery-typeahead.min.js
changeset 0 f05d7aea098a
child 5 c9c69b13d884
equal deleted inserted replaced
-1:000000000000 0:f05d7aea098a
       
     1 !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);