algoliasearch-rails 1.7.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +7 -1
- data/README.md +12 -8
- data/VERSION +1 -1
- data/algoliasearch-rails.gemspec +9 -7
- data/lib/algoliasearch/tasks/algoliasearch.rake +1 -15
- data/vendor/assets/javascripts/algolia/algoliasearch.js +12 -56
- data/vendor/assets/javascripts/algolia/algoliasearch.min.js +2 -2
- data/vendor/assets/javascripts/algolia/bloodhound.js +651 -0
- data/vendor/assets/javascripts/algolia/typeahead.bundle.js +1658 -0
- data/vendor/assets/javascripts/algolia/typeahead.bundle.min.js +7 -0
- data/vendor/assets/javascripts/algolia/typeahead.jquery.js +1130 -0
- metadata +8 -6
- data/vendor/assets/javascripts/algolia/typeahead.js +0 -1183
- data/vendor/assets/javascripts/algolia/typeahead.min.js +0 -7
| @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            /*!
         | 
| 2 | 
            +
             * typeahead.js 0.10.1
         | 
| 3 | 
            +
             * https://github.com/twitter/typeahead.js
         | 
| 4 | 
            +
             * Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT
         | 
| 5 | 
            +
             */
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            !function(a){var b={isMsie:function(){return/(msie|trident)/i.test(navigator.userAgent)?navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2]:!1},isBlankString:function(a){return!a||/^\s*$/.test(a)},escapeRegExChars:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isString:function(a){return"string"==typeof a},isNumber:function(a){return"number"==typeof a},isArray:a.isArray,isFunction:a.isFunction,isObject:a.isPlainObject,isUndefined:function(a){return"undefined"==typeof a},bind:a.proxy,each:function(b,c){function d(a,b){return c(b,a)}a.each(b,d)},map:a.map,filter:a.grep,every:function(b,c){var d=!0;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?void 0:!1}),!!d):d},some:function(b,c){var d=!1;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?!1:void 0}),!!d):d},mixin:a.extend,getUniqueId:function(){var a=0;return function(){return a++}}(),templatify:function(b){function c(){return String(b)}return a.isFunction(b)?b:c},defer:function(a){setTimeout(a,0)},debounce:function(a,b,c){var d,e;return function(){var f,g,h=this,i=arguments;return f=function(){d=null,c||(e=a.apply(h,i))},g=c&&!d,clearTimeout(d),d=setTimeout(f,b),g&&(e=a.apply(h,i)),e}},throttle:function(a,b){var c,d,e,f,g,h;return g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)},function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},noop:function(){}},c="0.10.1",d=function(){function a(a){this.maxSize=a||100,this.size=0,this.hash={},this.list=new c}function c(){this.head=this.tail=null}function d(a,b){this.key=a,this.val=b,this.prev=this.next=null}return b.mixin(a.prototype,{set:function(a,b){var c,e=this.list.tail;this.size>=this.maxSize&&(this.list.remove(e),delete this.hash[e.key]),(c=this.hash[a])?(c.val=b,this.list.moveToFront(c)):(c=new d(a,b),this.list.add(c),this.hash[a]=c,this.size++)},get:function(a){var b=this.hash[a];return b?(this.list.moveToFront(b),b.val):void 0}}),b.mixin(c.prototype,{add:function(a){this.head&&(a.next=this.head,this.head.prev=a),this.head=a,this.tail=this.tail||a},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev},moveToFront:function(a){this.remove(a),this.add(a)}}),a}(this),e=function(){function a(a){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+this.prefix)}function c(){return(new Date).getTime()}function d(a){return JSON.stringify(b.isUndefined(a)?null:a)}function e(a){return JSON.parse(a)}var f,g;try{f=window.localStorage,f.setItem("~~~","!"),f.removeItem("~~~")}catch(h){f=null}return g=f&&window.JSON?{_prefix:function(a){return this.prefix+a},_ttlKey:function(a){return this._prefix(a)+this.ttlKey},get:function(a){return this.isExpired(a)&&this.remove(a),e(f.getItem(this._prefix(a)))},set:function(a,e,g){return b.isNumber(g)?f.setItem(this._ttlKey(a),d(c()+g)):f.removeItem(this._ttlKey(a)),f.setItem(this._prefix(a),d(e))},remove:function(a){return f.removeItem(this._ttlKey(a)),f.removeItem(this._prefix(a)),this},clear:function(){var a,b,c=[],d=f.length;for(a=0;d>a;a++)(b=f.key(a)).match(this.keyMatcher)&&c.push(b.replace(this.keyMatcher,""));for(a=c.length;a--;)this.remove(c[a]);return this},isExpired:function(a){var d=e(f.getItem(this._ttlKey(a)));return b.isNumber(d)&&c()>d?!0:!1}}:{get:b.noop,set:b.noop,remove:b.noop,clear:b.noop,isExpired:b.noop},b.mixin(a.prototype,g),a}(),f=function(){function c(b){b=b||{},this._send=b.transport?e(b.transport):a.ajax,this._get=b.rateLimiter?b.rateLimiter(this._get):this._get}function e(c){return function(d,e){function f(a){b.defer(function(){h.resolve(a)})}function g(a){b.defer(function(){h.reject(a)})}var h=a.Deferred();return c(d,e,f,g),h}}var f=0,g={},h=6,i=new d(10);return c.setMaxPendingRequests=function(a){h=a},c.resetCache=function(){i=new d(10)},b.mixin(c.prototype,{_get:function(a,b,c){function d(b){c&&c(b),i.set(a,b)}function e(){f--,delete g[a],k.onDeckRequestArgs&&(k._get.apply(k,k.onDeckRequestArgs),k.onDeckRequestArgs=null)}var j,k=this;(j=g[a])?j.done(d):h>f?(f++,g[a]=this._send(a,b).done(d).always(e)):this.onDeckRequestArgs=[].slice.call(arguments,0)},get:function(a,c,d){var e;return b.isFunction(c)&&(d=c,c={}),(e=i.get(a))?b.defer(function(){d&&d(e)}):this._get(a,c,d),!!e}}),c}(),g=function(){function c(b){b=b||{},b.datumTokenizer&&b.queryTokenizer||a.error("datumTokenizer and queryTokenizer are both required"),this.datumTokenizer=b.datumTokenizer,this.queryTokenizer=b.queryTokenizer,this.datums=[],this.trie=e()}function d(a){return a=b.filter(a,function(a){return!!a}),a=b.map(a,function(a){return a.toLowerCase()})}function e(){return{ids:[],children:{}}}function f(a){for(var b={},c=[],d=0;d<a.length;d++)b[a[d]]||(b[a[d]]=!0,c.push(a[d]));return c}function g(a,b){function c(a,b){return a-b}var d=0,e=0,f=[];for(a=a.sort(c),b=b.sort(c);d<a.length&&e<b.length;)a[d]<b[e]?d++:a[d]>b[e]?e++:(f.push(a[d]),d++,e++);return f}return b.mixin(c.prototype,{bootstrap:function(a){this.datums=a.datums,this.trie=a.trie},add:function(a){var c=this;a=b.isArray(a)?a:[a],b.each(a,function(a){var f,g;f=c.datums.push(a)-1,g=d(c.datumTokenizer(a)),b.each(g,function(a){var b,d,g;for(b=c.trie,d=a.split("");g=d.shift();)b=b.children[g]||(b.children[g]=e()),b.ids.push(f)})})},get:function(a){var c,e,h=this;return c=d(this.queryTokenizer(a)),b.each(c,function(a){var b,c,d,f;if(e&&0===e.length)return!1;for(b=h.trie,c=a.split("");b&&(d=c.shift());)b=b.children[d];return b&&0===c.length?(f=b.ids.slice(0),void(e=e?g(e,f):f)):(e=[],!1)}),e?b.map(f(e),function(a){return h.datums[a]}):[]},serialize:function(){return{datums:this.datums,trie:this.trie}}}),c}(),h=function(){function d(a){var c=a.local||null;return b.isFunction(c)&&(c=c.call(null)),c}function e(d){var e,f;return f={url:null,thumbprint:"",ttl:864e5,filter:null,ajax:{}},(e=d.prefetch||null)&&(e=b.isString(e)?{url:e}:e,e=b.mixin(f,e),e.thumbprint=c+e.thumbprint,e.ajax.type=e.ajax.type||"GET",e.ajax.dataType=e.ajax.dataType||"json",!e.url&&a.error("prefetch requires url to be set")),e}function f(c){function d(a){return function(c){return b.debounce(c,a)}}function e(a){return function(c){return b.throttle(c,a)}}var f,g;return g={url:null,wildcard:"%QUERY",replace:null,rateLimitBy:"debounce",rateLimitWait:300,send:null,filter:null,ajax:{}},(f=c.remote||null)&&(f=b.isString(f)?{url:f}:f,f=b.mixin(g,f),f.rateLimiter=/^throttle$/i.test(f.rateLimitBy)?e(f.rateLimitWait):d(f.rateLimitWait),f.ajax.type=f.ajax.type||"GET",f.ajax.dataType=f.ajax.dataType||"json",delete f.rateLimitBy,delete f.rateLimitWait,!f.url&&a.error("remote requires url to be set")),f}return{local:d,prefetch:e,remote:f}}(),i=(window.Bloodhound=function(){function c(b){b&&(b.local||b.prefetch||b.remote)||a.error("one of local, prefetch, or remote is required"),this.limit=b.limit||5,this.sorter=d(b.sorter),this.dupDetector=b.dupDetector||i,this.local=h.local(b),this.prefetch=h.prefetch(b),this.remote=h.remote(b),this.cacheKey=this.prefetch?this.prefetch.cacheKey||this.prefetch.url:null,this.index=new g({datumTokenizer:b.datumTokenizer,queryTokenizer:b.queryTokenizer}),this.storage=this.cacheKey?new e(this.cacheKey):null}function d(a){function c(b){return b.sort(a)}function d(a){return a}return b.isFunction(a)?c:d}function i(){return!1}var j;return j={data:"data",protocol:"protocol",thumbprint:"thumbprint"},c.tokenizers={whitespace:function(a){return a.split(/\s+/)},nonword:function(a){return a.split(/\W+/)}},b.mixin(c.prototype,{_loadPrefetch:function(b){function c(a){var c;c=b.filter?b.filter(a):a,f.add(c),f._saveToStorage(f.index.serialize(),b.thumbprint,b.ttl)}var d,e,f=this;return(d=this._readFromStorage(b.thumbprint))?(this.index.bootstrap(d),e=a.Deferred().resolve()):e=a.ajax(b.url,b.ajax).done(c),e},_getFromRemote:function(a,b){function c(a){var c=f.remote.filter?f.remote.filter(a):a;b(c)}var d,e,f=this;return a=a||"",e=encodeURIComponent(a),d=this.remote.replace?this.remote.replace(this.remote.url,a):this.remote.url.replace(this.remote.wildcard,e),this.transport.get(d,this.remote.ajax,c)},_saveToStorage:function(a,b,c){this.storage&&(this.storage.set(j.data,a,c),this.storage.set(j.protocol,location.protocol,c),this.storage.set(j.thumbprint,b,c))},_readFromStorage:function(a){var b,c={};return this.storage&&(c.data=this.storage.get(j.data),c.protocol=this.storage.get(j.protocol),c.thumbprint=this.storage.get(j.thumbprint)),b=c.thumbprint!==a||c.protocol!==location.protocol,c.data&&!b?c.data:null},initialize:function(){function b(){d.add(d.local)}var c,d=this;return c=this.prefetch?this._loadPrefetch(this.prefetch):a.Deferred().resolve(),this.local&&c.done(b),this.transport=this.remote?new f(this.remote):null,this.initialize=function(){return c.promise()},c.promise()},add:function(a){this.index.add(a)},get:function(a,c){function d(a){var d=e.slice(0);b.each(a,function(a){var c;return c=b.some(d,function(b){return f.dupDetector(a,b)}),!c&&d.push(a),d.length<f.limit}),c&&c(f.sorter(d))}var e,f=this,g=!1;e=this.index.get(a),e=this.sorter(e).slice(0,this.limit),e.length<this.limit&&this.transport&&(g=this._getFromRemote(a,d)),!g&&c&&c(e)},ttAdapter:function(){return b.bind(this.get,this)}}),c}(),{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>'}),j={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"}};b.isMsie()&&b.mixin(j.input,{backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"}),b.isMsie()&&b.isMsie()<=7&&b.mixin(j.input,{marginTop:"-1px"});var k=function(){function c(b){b&&b.el||a.error("EventBus initialized without el"),this.$el=a(b.el)}var d="typeahead:";return b.mixin(c.prototype,{trigger:function(a){var b=[].slice.call(arguments,1);this.$el.trigger(d+a,b)}}),c}(),l=function(){function a(a,b,c,d){var e;if(!c)return this;for(b=b.split(i),c=d?h(c,d):c,this._callbacks=this._callbacks||{};e=b.shift();)this._callbacks[e]=this._callbacks[e]||{sync:[],async:[]},this._callbacks[e][a].push(c);return this}function b(b,c,d){return a.call(this,"async",b,c,d)}function c(b,c,d){return a.call(this,"sync",b,c,d)}function d(a){var b;if(!this._callbacks)return this;for(a=a.split(i);b=a.shift();)delete this._callbacks[b];return this}function e(a){var b,c,d,e,g;if(!this._callbacks)return this;for(a=a.split(i),d=[].slice.call(arguments,1);(b=a.shift())&&(c=this._callbacks[b]);)e=f(c.sync,this,[b].concat(d)),g=f(c.async,this,[b].concat(d)),e()&&j(g);return this}function f(a,b,c){function d(){for(var d,e=0;!d&&e<a.length;e+=1)d=a[e].apply(b,c)===!1;return!d}return d}function g(){var a;return a=window.setImmediate?function(a){setImmediate(function(){a()})}:function(a){setTimeout(function(){a()},0)}}function h(a,b){return a.bind?a.bind(b):function(){a.apply(b,[].slice.call(arguments,0))}}var i=/\s+/,j=g();return{onSync:c,onAsync:b,off:d,trigger:e}}(),m=function(a){function c(a,c,d){for(var e,f=[],g=0;g<a.length;g++)f.push(b.escapeRegExChars(a[g]));return e=d?"\\b("+f.join("|")+")\\b":"("+f.join("|")+")",c?new RegExp(e):new RegExp(e,"i")}var d={node:null,pattern:null,tagName:"strong",className:null,wordsOnly:!1,caseSensitive:!1};return function(e){function f(b){var c,d;return(c=h.exec(b.data))&&(wrapperNode=a.createElement(e.tagName),e.className&&(wrapperNode.className=e.className),d=b.splitText(c.index),d.splitText(c[0].length),wrapperNode.appendChild(d.cloneNode(!0)),b.parentNode.replaceChild(wrapperNode,d)),!!c}function g(a,b){for(var c,d=3,e=0;e<a.childNodes.length;e++)c=a.childNodes[e],c.nodeType===d?e+=b(c)?1:0:g(c,b)}var h;e=b.mixin({},d,e),e.node&&e.pattern&&(e.pattern=b.isArray(e.pattern)?e.pattern:[e.pattern],h=c(e.pattern,e.caseSensitive,e.wordsOnly),g(e.node,f))}}(window.document),n=function(){function c(c){var e,f,h,i,j=this;c=c||{},c.input||a.error("input is missing"),e=b.bind(this._onBlur,this),f=b.bind(this._onFocus,this),h=b.bind(this._onKeydown,this),i=b.bind(this._onInput,this),this.$hint=a(c.hint),this.$input=a(c.input).on("blur.tt",e).on("focus.tt",f).on("keydown.tt",h),0===this.$hint.length&&(this.setHintValue=this.getHintValue=this.clearHint=b.noop),b.isMsie()?this.$input.on("keydown.tt keypress.tt cut.tt paste.tt",function(a){g[a.which||a.keyCode]||b.defer(b.bind(j._onInput,j,a))}):this.$input.on("input.tt",i),this.query=this.$input.val(),this.$overflowHelper=d(this.$input)}function d(b){return a('<pre aria-hidden="true"></pre>').css({position:"absolute",visibility:"hidden",whiteSpace:"nowrap",fontFamily:b.css("font-family"),fontSize:b.css("font-size"),fontStyle:b.css("font-style"),fontVariant:b.css("font-variant"),fontWeight:b.css("font-weight"),wordSpacing:b.css("word-spacing"),letterSpacing:b.css("letter-spacing"),textIndent:b.css("text-indent"),textRendering:b.css("text-rendering"),textTransform:b.css("text-transform")}).insertAfter(b)}function e(a,b){return c.normalizeQuery(a)===c.normalizeQuery(b)}function f(a){return a.altKey||a.ctrlKey||a.metaKey||a.shiftKey}var g;return g={9:"tab",27:"esc",37:"left",39:"right",13:"enter",38:"up",40:"down"},c.normalizeQuery=function(a){return(a||"").replace(/^\s*/g,"").replace(/\s{2,}/g," ")},b.mixin(c.prototype,l,{_onBlur:function(){this.resetInputValue(),this.trigger("blurred")},_onFocus:function(){this.trigger("focused")},_onKeydown:function(a){var b=g[a.which||a.keyCode];this._managePreventDefault(b,a),b&&this._shouldTrigger(b,a)&&this.trigger(b+"Keyed",a)},_onInput:function(){this._checkInputValue()},_managePreventDefault:function(a,b){var c,d,e;switch(a){case"tab":d=this.getHintValue(),e=this.getInputValue(),c=d&&d!==e&&!f(b);break;case"up":case"down":c=!f(b);break;default:c=!1}c&&b.preventDefault()},_shouldTrigger:function(a,b){var c;switch(a){case"tab":c=!f(b);break;default:c=!0}return c},_checkInputValue:function(){var a,b,c;a=this.getInputValue(),b=e(a,this.query),c=b?this.query.length!==a.length:!1,b?c&&this.trigger("whitespaceChanged",this.query):this.trigger("queryChanged",this.query=a)},focus:function(){this.$input.focus()},blur:function(){this.$input.blur()},getQuery:function(){return this.query},setQuery:function(a){this.query=a},getInputValue:function(){return this.$input.val()},setInputValue:function(a,b){this.$input.val(a),!b&&this._checkInputValue()},getHintValue:function(){return this.$hint.val()},setHintValue:function(a){this.$hint.val(a)},resetInputValue:function(){this.$input.val(this.query)},clearHint:function(){this.$hint.val("")},getLanguageDirection:function(){return(this.$input.css("direction")||"ltr").toLowerCase()},hasOverflow:function(){var a=this.$input.width()-2;return this.$overflowHelper.text(this.getInputValue()),this.$overflowHelper.width()>=a},isCursorAtEnd:function(){var a,c,d;return a=this.$input.val().length,c=this.$input[0].selectionStart,b.isNumber(c)?c===a:document.selection?(d=document.selection.createRange(),d.moveStart("character",-a),a===d.text.length):!0},destroy:function(){this.$hint.off(".tt"),this.$input.off(".tt"),this.$hint=this.$input=this.$overflowHelper=null}}),c}(),o=function(){function c(c){c=c||{},c.templates=c.templates||{},c.source||a.error("missing source"),c.name&&!f(c.name)&&a.error("invalid dataset name: "+c.name),this.query=null,this.highlight=!!c.highlight,this.name=c.name||b.getUniqueId(),this.source=c.source,this.displayFn=d(c.display||c.displayKey),this.templates=e(c.templates,this.displayFn),this.$el=a(i.dataset.replace("%CLASS%",this.name))}function d(a){function c(b){return b[a]}return a=a||"value",b.isFunction(a)?a:c}function e(a,c){function d(a){return"<p>"+c(a)+"</p>"}return{empty:a.empty&&b.templatify(a.empty),header:a.header&&b.templatify(a.header),footer:a.footer&&b.templatify(a.footer),suggestion:a.suggestion||d}}function f(a){return/^[_a-zA-Z0-9-]+$/.test(a)}var g="ttDataset",h="ttValue",k="ttDatum";return c.extractDatasetName=function(b){return a(b).data(g)},c.extractValue=function(b){return a(b).data(h)},c.extractDatum=function(b){return a(b).data(k)},b.mixin(c.prototype,l,{_render:function(c,d){function e(){return p.templates.empty({query:c,isEmpty:!0})}function f(){function e(b){var c,d,e;return d=p.templates.suggestion(b),e=i.suggestion.replace("%BODY%",d),c=a(e).data(g,p.name).data(h,p.displayFn(b)).data(k,b),c.children().each(function(){a(this).css(j.suggestionChild)}),c}var f,l;return f=a(i.suggestions).css(j.suggestions),l=b.map(d,e),f.append.apply(f,l),p.highlight&&m({node:f[0],pattern:c}),f}function l(){return p.templates.header({query:c,isEmpty:!o})}function n(){return p.templates.footer({query:c,isEmpty:!o})}if(this.$el){var o,p=this;this.$el.empty(),o=d&&d.length,!o&&this.templates.empty?this.$el.html(e()).prepend(p.templates.header?l():null).append(p.templates.footer?n():null):o&&this.$el.html(f()).prepend(p.templates.header?l():null).append(p.templates.footer?n():null),this.trigger("rendered")}},getRoot:function(){return this.$el},update:function(a){function b(b){a===c.query&&c._render(a,b)}var c=this;this.query=a,this.source(a,b)},clear:function(){this._render(this.query||"")},isEmpty:function(){return this.$el.is(":empty")},destroy:function(){this.$el=null}}),c}(),p=function(){function c(c){var e,f,g,h=this;c=c||{},c.menu||a.error("menu is required"),this.isOpen=!1,this.isEmpty=!0,this.datasets=b.map(c.datasets,d),e=b.bind(this._onSuggestionClick,this),f=b.bind(this._onSuggestionMouseEnter,this),g=b.bind(this._onSuggestionMouseLeave,this),this.$menu=a(c.menu).on("click.tt",".tt-suggestion",e).on("mouseenter.tt",".tt-suggestion",f).on("mouseleave.tt",".tt-suggestion",g),b.each(this.datasets,function(a){h.$menu.append(a.getRoot()),a.onSync("rendered",h._onRendered,h)})}function d(a){return new o(a)}return b.mixin(c.prototype,l,{_onSuggestionClick:function(b){this.trigger("suggestionClicked",a(b.currentTarget))},_onSuggestionMouseEnter:function(b){this._removeCursor(),this._setCursor(a(b.currentTarget),!0)},_onSuggestionMouseLeave:function(){this._removeCursor()},_onRendered:function(){function a(a){return a.isEmpty()}this.isEmpty=b.every(this.datasets,a),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(a,b){a.first().addClass("tt-cursor"),!b&&this.trigger("cursorMoved")},_removeCursor:function(){this._getCursor().removeClass("tt-cursor")},_moveCursor:function(a){var b,c,d,e;if(this.isOpen){if(c=this._getCursor(),b=this._getSuggestions(),this._removeCursor(),d=b.index(c)+a,d=(d+1)%(b.length+1)-1,-1===d)return void this.trigger("cursorRemoved");-1>d&&(d=b.length-1),this._setCursor(e=b.eq(d)),this._ensureVisible(e)}},_ensureVisible:function(a){var b,c,d,e;b=a.position().top,c=b+a.outerHeight(!0),d=this.$menu.scrollTop(),e=this.$menu.height()+parseInt(this.$menu.css("paddingTop"),10)+parseInt(this.$menu.css("paddingBottom"),10),0>b?this.$menu.scrollTop(d+b):c>e&&this.$menu.scrollTop(d+(c-e))},close:function(){this.isOpen&&(this.isOpen=!1,this._removeCursor(),this._hide(),this.trigger("closed"))},open:function(){this.isOpen||(this.isOpen=!0,!this.isEmpty&&this._show(),this.trigger("opened"))},setLanguageDirection:function(a){this.$menu.css("ltr"===a?j.ltr:j.rtl)},moveCursorUp:function(){this._moveCursor(-1)},moveCursorDown:function(){this._moveCursor(1)},getDatumForSuggestion:function(a){var b=null;return a.length&&(b={raw:o.extractDatum(a),value:o.extractValue(a),datasetName:o.extractDatasetName(a)}),b},getDatumForCursor:function(){return this.getDatumForSuggestion(this._getCursor().first())},getDatumForTopSuggestion:function(){return this.getDatumForSuggestion(this._getSuggestions().first())},update:function(a){function c(b){b.update(a)}b.each(this.datasets,c)},empty:function(){function a(a){a.clear()}b.each(this.datasets,a),this.isEmpty=!0},isVisible:function(){return this.isOpen&&!this.isEmpty},destroy:function(){function a(a){a.destroy()}this.$menu.off(".tt"),this.$menu=null,b.each(this.datasets,a)}}),c}(),q=function(){function c(c){var e,f,g;c=c||{},c.input||a.error("missing input"),this.autoselect=!!c.autoselect,this.minLength=b.isNumber(c.minLength)?c.minLength:1,this.$node=d(c.input,c.withHint),e=this.$node.find(".tt-dropdown-menu"),f=this.$node.find(".tt-input"),g=this.$node.find(".tt-hint"),this.eventBus=c.eventBus||new k({el:f}),this.dropdown=new p({menu:e,datasets:c.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 n({input:f,hint:g}).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),e.on("mousedown.tt",function(a){b.isMsie()&&b.isMsie()<9&&(f[0].onbeforedeactivate=function(){window.event.returnValue=!1,f[0].onbeforedeactivate=null}),a.preventDefault()})}function d(b,c){var d,f,h,k;d=a(b),f=a(i.wrapper).css(j.wrapper),h=a(i.dropdown).css(j.dropdown),k=d.clone().css(j.hint).css(e(d)),k.val("").removeData().addClass("tt-hint").removeAttr("id name placeholder").prop("disabled",!0).attr({autocomplete:"off",spellcheck:"false"}),d.data(g,{dir:d.attr("dir"),autocomplete:d.attr("autocomplete"),spellcheck:d.attr("spellcheck"),style:d.attr("style")}),d.addClass("tt-input").attr({autocomplete:"off",spellcheck:!1}).css(c?j.input:j.inputWithNoHint);try{!d.attr("dir")&&d.attr("dir","auto")}catch(l){}return d.wrap(f).parent().prepend(c?k:null).append(h)}function e(a){return{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")}}function f(a){var c=a.find(".tt-input");b.each(c.data(g),function(a,d){b.isUndefined(a)?c.removeAttr(d):c.attr(d,a)}),c.detach().removeData(g).removeClass("tt-input").insertAfter(a),a.remove()}var g="ttAttrs";return b.mixin(c.prototype,{_onSuggestionClicked:function(a,b){var c;(c=this.dropdown.getDatumForSuggestion(b))&&this._select(c)},_onCursorMoved:function(){var a=this.dropdown.getDatumForCursor();this.input.clearHint(),this.input.setInputValue(a.value,!0),this.eventBus.trigger("cursorchanged",a.raw,a.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.empty(),this.dropdown.open()},_onBlurred:function(){this.dropdown.close()},_onEnterKeyed:function(a,b){var c,d;c=this.dropdown.getDatumForCursor(),d=this.dropdown.getDatumForTopSuggestion(),c?(this._select(c),b.preventDefault()):this.autoselect&&d&&(this._select(d),b.preventDefault())},_onTabKeyed:function(a,b){var c;(c=this.dropdown.getDatumForCursor())?(this._select(c),b.preventDefault()):this._autocomplete()},_onEscKeyed:function(){this.dropdown.close(),this.input.resetInputValue()},_onUpKeyed:function(){var a=this.input.getQuery();!this.dropdown.isOpen&&a.length>=this.minLength&&this.dropdown.update(a),this.dropdown.open(),this.dropdown.moveCursorUp()},_onDownKeyed:function(){var a=this.input.getQuery();!this.dropdown.isOpen&&a.length>=this.minLength&&this.dropdown.update(a),this.dropdown.open(),this.dropdown.moveCursorDown()},_onLeftKeyed:function(){"rtl"===this.dir&&this._autocomplete()},_onRightKeyed:function(){"ltr"===this.dir&&this._autocomplete()},_onQueryChanged:function(a,b){this.input.clearHint(),this.dropdown.empty(),b.length>=this.minLength&&this.dropdown.update(b),this.dropdown.open(),this._setLanguageDirection()},_onWhitespaceChanged:function(){this._updateHint(),this.dropdown.open()},_setLanguageDirection:function(){var a;this.dir!==(a=this.input.getLanguageDirection())&&(this.dir=a,this.$node.css("direction",a),this.dropdown.setLanguageDirection(a))},_updateHint:function(){var a,c,d,e,f,g;a=this.dropdown.getDatumForTopSuggestion(),a&&this.dropdown.isVisible()&&!this.input.hasOverflow()&&(c=this.input.getInputValue(),d=n.normalizeQuery(c),e=b.escapeRegExChars(d),f=new RegExp("^(?:"+e+")(.*$)","i"),g=f.exec(a.value),this.input.setHintValue(c+(g?g[1]:"")))},_autocomplete:function(){var a,b,c;a=this.input.getHintValue(),b=this.input.getQuery(),a&&b!==a&&this.input.isCursorAtEnd()&&(c=this.dropdown.getDatumForTopSuggestion(),c&&this.input.setInputValue(c.value),this.eventBus.trigger("autocompleted",c.raw,c.datasetName))},_select:function(a){this.input.clearHint(),this.input.setQuery(a.value),this.input.setInputValue(a.value,!0),this._setLanguageDirection(),this.eventBus.trigger("selected",a.raw,a.datasetName),this.dropdown.close(),b.defer(b.bind(this.dropdown.empty,this.dropdown))},open:function(){this.dropdown.open()},close:function(){this.dropdown.close()},getQuery:function(){return this.input.getQuery()},setQuery:function(a){this.input.setInputValue(a)},destroy:function(){this.input.destroy(),this.dropdown.destroy(),f(this.$node),this.$node=null}}),c}();!function(){var c,d,e;c=a.fn.typeahead,d="ttTypeahead",e={initialize:function(c,e){function f(){var f,g,h=a(this);b.each(e,function(a){a.highlight=!!c.highlight}),g=new q({input:h,eventBus:f=new k({el:h}),withHint:b.isUndefined(c.hint)?!0:!!c.hint,minLength:c.minLength,autoselect:c.autoselect,datasets:e}),h.data(d,g)}return e=b.isArray(e)?e:[].slice.call(arguments,1),c=c||{},this.each(f)},open:function(){function b(){var b,c=a(this);(b=c.data(d))&&b.open()}return this.each(b)},close:function(){function b(){var b,c=a(this);(b=c.data(d))&&b.close()}return this.each(b)},val:function(b){function c(){var c,e=a(this);(c=e.data(d))&&c.setQuery(b)}function e(a){var b,c;return(b=a.data(d))&&(c=b.getQuery()),c}return arguments.length?this.each(c):e(this.first())},destroy:function(){function b(){var b,c=a(this);(b=c.data(d))&&(b.destroy(),c.removeData(d))}return this.each(b)}},a.fn.typeahead=function(a){return e[a]?e[a].apply(this,[].slice.call(arguments,1)):e.initialize.apply(this,arguments)},a.fn.typeahead.noConflict=function(){return a.fn.typeahead=c,this}}()}(window.jQuery);
         | 
| @@ -0,0 +1,1130 @@ | |
| 1 | 
            +
            /*!
         | 
| 2 | 
            +
             * typeahead.js 0.10.1
         | 
| 3 | 
            +
             * https://github.com/twitter/typeahead.js
         | 
| 4 | 
            +
             * Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT
         | 
| 5 | 
            +
             */
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            (function($) {
         | 
| 8 | 
            +
                var _ = {
         | 
| 9 | 
            +
                    isMsie: function() {
         | 
| 10 | 
            +
                        return /(msie|trident)/i.test(navigator.userAgent) ? navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2] : false;
         | 
| 11 | 
            +
                    },
         | 
| 12 | 
            +
                    isBlankString: function(str) {
         | 
| 13 | 
            +
                        return !str || /^\s*$/.test(str);
         | 
| 14 | 
            +
                    },
         | 
| 15 | 
            +
                    escapeRegExChars: function(str) {
         | 
| 16 | 
            +
                        return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
         | 
| 17 | 
            +
                    },
         | 
| 18 | 
            +
                    isString: function(obj) {
         | 
| 19 | 
            +
                        return typeof obj === "string";
         | 
| 20 | 
            +
                    },
         | 
| 21 | 
            +
                    isNumber: function(obj) {
         | 
| 22 | 
            +
                        return typeof obj === "number";
         | 
| 23 | 
            +
                    },
         | 
| 24 | 
            +
                    isArray: $.isArray,
         | 
| 25 | 
            +
                    isFunction: $.isFunction,
         | 
| 26 | 
            +
                    isObject: $.isPlainObject,
         | 
| 27 | 
            +
                    isUndefined: function(obj) {
         | 
| 28 | 
            +
                        return typeof obj === "undefined";
         | 
| 29 | 
            +
                    },
         | 
| 30 | 
            +
                    bind: $.proxy,
         | 
| 31 | 
            +
                    each: function(collection, cb) {
         | 
| 32 | 
            +
                        $.each(collection, reverseArgs);
         | 
| 33 | 
            +
                        function reverseArgs(index, value) {
         | 
| 34 | 
            +
                            return cb(value, index);
         | 
| 35 | 
            +
                        }
         | 
| 36 | 
            +
                    },
         | 
| 37 | 
            +
                    map: $.map,
         | 
| 38 | 
            +
                    filter: $.grep,
         | 
| 39 | 
            +
                    every: function(obj, test) {
         | 
| 40 | 
            +
                        var result = true;
         | 
| 41 | 
            +
                        if (!obj) {
         | 
| 42 | 
            +
                            return result;
         | 
| 43 | 
            +
                        }
         | 
| 44 | 
            +
                        $.each(obj, function(key, val) {
         | 
| 45 | 
            +
                            if (!(result = test.call(null, val, key, obj))) {
         | 
| 46 | 
            +
                                return false;
         | 
| 47 | 
            +
                            }
         | 
| 48 | 
            +
                        });
         | 
| 49 | 
            +
                        return !!result;
         | 
| 50 | 
            +
                    },
         | 
| 51 | 
            +
                    some: function(obj, test) {
         | 
| 52 | 
            +
                        var result = false;
         | 
| 53 | 
            +
                        if (!obj) {
         | 
| 54 | 
            +
                            return result;
         | 
| 55 | 
            +
                        }
         | 
| 56 | 
            +
                        $.each(obj, function(key, val) {
         | 
| 57 | 
            +
                            if (result = test.call(null, val, key, obj)) {
         | 
| 58 | 
            +
                                return false;
         | 
| 59 | 
            +
                            }
         | 
| 60 | 
            +
                        });
         | 
| 61 | 
            +
                        return !!result;
         | 
| 62 | 
            +
                    },
         | 
| 63 | 
            +
                    mixin: $.extend,
         | 
| 64 | 
            +
                    getUniqueId: function() {
         | 
| 65 | 
            +
                        var counter = 0;
         | 
| 66 | 
            +
                        return function() {
         | 
| 67 | 
            +
                            return counter++;
         | 
| 68 | 
            +
                        };
         | 
| 69 | 
            +
                    }(),
         | 
| 70 | 
            +
                    templatify: function templatify(obj) {
         | 
| 71 | 
            +
                        return $.isFunction(obj) ? obj : template;
         | 
| 72 | 
            +
                        function template() {
         | 
| 73 | 
            +
                            return String(obj);
         | 
| 74 | 
            +
                        }
         | 
| 75 | 
            +
                    },
         | 
| 76 | 
            +
                    defer: function(fn) {
         | 
| 77 | 
            +
                        setTimeout(fn, 0);
         | 
| 78 | 
            +
                    },
         | 
| 79 | 
            +
                    debounce: function(func, wait, immediate) {
         | 
| 80 | 
            +
                        var timeout, result;
         | 
| 81 | 
            +
                        return function() {
         | 
| 82 | 
            +
                            var context = this, args = arguments, later, callNow;
         | 
| 83 | 
            +
                            later = function() {
         | 
| 84 | 
            +
                                timeout = null;
         | 
| 85 | 
            +
                                if (!immediate) {
         | 
| 86 | 
            +
                                    result = func.apply(context, args);
         | 
| 87 | 
            +
                                }
         | 
| 88 | 
            +
                            };
         | 
| 89 | 
            +
                            callNow = immediate && !timeout;
         | 
| 90 | 
            +
                            clearTimeout(timeout);
         | 
| 91 | 
            +
                            timeout = setTimeout(later, wait);
         | 
| 92 | 
            +
                            if (callNow) {
         | 
| 93 | 
            +
                                result = func.apply(context, args);
         | 
| 94 | 
            +
                            }
         | 
| 95 | 
            +
                            return result;
         | 
| 96 | 
            +
                        };
         | 
| 97 | 
            +
                    },
         | 
| 98 | 
            +
                    throttle: function(func, wait) {
         | 
| 99 | 
            +
                        var context, args, timeout, result, previous, later;
         | 
| 100 | 
            +
                        previous = 0;
         | 
| 101 | 
            +
                        later = function() {
         | 
| 102 | 
            +
                            previous = new Date();
         | 
| 103 | 
            +
                            timeout = null;
         | 
| 104 | 
            +
                            result = func.apply(context, args);
         | 
| 105 | 
            +
                        };
         | 
| 106 | 
            +
                        return function() {
         | 
| 107 | 
            +
                            var now = new Date(), remaining = wait - (now - previous);
         | 
| 108 | 
            +
                            context = this;
         | 
| 109 | 
            +
                            args = arguments;
         | 
| 110 | 
            +
                            if (remaining <= 0) {
         | 
| 111 | 
            +
                                clearTimeout(timeout);
         | 
| 112 | 
            +
                                timeout = null;
         | 
| 113 | 
            +
                                previous = now;
         | 
| 114 | 
            +
                                result = func.apply(context, args);
         | 
| 115 | 
            +
                            } else if (!timeout) {
         | 
| 116 | 
            +
                                timeout = setTimeout(later, remaining);
         | 
| 117 | 
            +
                            }
         | 
| 118 | 
            +
                            return result;
         | 
| 119 | 
            +
                        };
         | 
| 120 | 
            +
                    },
         | 
| 121 | 
            +
                    noop: function() {}
         | 
| 122 | 
            +
                };
         | 
| 123 | 
            +
                var html = {
         | 
| 124 | 
            +
                    wrapper: '<span class="twitter-typeahead"></span>',
         | 
| 125 | 
            +
                    dropdown: '<span class="tt-dropdown-menu"></span>',
         | 
| 126 | 
            +
                    dataset: '<div class="tt-dataset-%CLASS%"></div>',
         | 
| 127 | 
            +
                    suggestions: '<span class="tt-suggestions"></span>',
         | 
| 128 | 
            +
                    suggestion: '<div class="tt-suggestion">%BODY%</div>'
         | 
| 129 | 
            +
                };
         | 
| 130 | 
            +
                var css = {
         | 
| 131 | 
            +
                    wrapper: {
         | 
| 132 | 
            +
                        position: "relative",
         | 
| 133 | 
            +
                        display: "inline-block"
         | 
| 134 | 
            +
                    },
         | 
| 135 | 
            +
                    hint: {
         | 
| 136 | 
            +
                        position: "absolute",
         | 
| 137 | 
            +
                        top: "0",
         | 
| 138 | 
            +
                        left: "0",
         | 
| 139 | 
            +
                        borderColor: "transparent",
         | 
| 140 | 
            +
                        boxShadow: "none"
         | 
| 141 | 
            +
                    },
         | 
| 142 | 
            +
                    input: {
         | 
| 143 | 
            +
                        position: "relative",
         | 
| 144 | 
            +
                        verticalAlign: "top",
         | 
| 145 | 
            +
                        backgroundColor: "transparent"
         | 
| 146 | 
            +
                    },
         | 
| 147 | 
            +
                    inputWithNoHint: {
         | 
| 148 | 
            +
                        position: "relative",
         | 
| 149 | 
            +
                        verticalAlign: "top"
         | 
| 150 | 
            +
                    },
         | 
| 151 | 
            +
                    dropdown: {
         | 
| 152 | 
            +
                        position: "absolute",
         | 
| 153 | 
            +
                        top: "100%",
         | 
| 154 | 
            +
                        left: "0",
         | 
| 155 | 
            +
                        zIndex: "100",
         | 
| 156 | 
            +
                        display: "none"
         | 
| 157 | 
            +
                    },
         | 
| 158 | 
            +
                    suggestions: {
         | 
| 159 | 
            +
                        display: "block"
         | 
| 160 | 
            +
                    },
         | 
| 161 | 
            +
                    suggestion: {
         | 
| 162 | 
            +
                        whiteSpace: "nowrap",
         | 
| 163 | 
            +
                        cursor: "pointer"
         | 
| 164 | 
            +
                    },
         | 
| 165 | 
            +
                    suggestionChild: {
         | 
| 166 | 
            +
                        whiteSpace: "normal"
         | 
| 167 | 
            +
                    },
         | 
| 168 | 
            +
                    ltr: {
         | 
| 169 | 
            +
                        left: "0",
         | 
| 170 | 
            +
                        right: "auto"
         | 
| 171 | 
            +
                    },
         | 
| 172 | 
            +
                    rtl: {
         | 
| 173 | 
            +
                        left: "auto",
         | 
| 174 | 
            +
                        right: " 0"
         | 
| 175 | 
            +
                    }
         | 
| 176 | 
            +
                };
         | 
| 177 | 
            +
                if (_.isMsie()) {
         | 
| 178 | 
            +
                    _.mixin(css.input, {
         | 
| 179 | 
            +
                        backgroundImage: "url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"
         | 
| 180 | 
            +
                    });
         | 
| 181 | 
            +
                }
         | 
| 182 | 
            +
                if (_.isMsie() && _.isMsie() <= 7) {
         | 
| 183 | 
            +
                    _.mixin(css.input, {
         | 
| 184 | 
            +
                        marginTop: "-1px"
         | 
| 185 | 
            +
                    });
         | 
| 186 | 
            +
                }
         | 
| 187 | 
            +
                var EventBus = function() {
         | 
| 188 | 
            +
                    var namespace = "typeahead:";
         | 
| 189 | 
            +
                    function EventBus(o) {
         | 
| 190 | 
            +
                        if (!o || !o.el) {
         | 
| 191 | 
            +
                            $.error("EventBus initialized without el");
         | 
| 192 | 
            +
                        }
         | 
| 193 | 
            +
                        this.$el = $(o.el);
         | 
| 194 | 
            +
                    }
         | 
| 195 | 
            +
                    _.mixin(EventBus.prototype, {
         | 
| 196 | 
            +
                        trigger: function(type) {
         | 
| 197 | 
            +
                            var args = [].slice.call(arguments, 1);
         | 
| 198 | 
            +
                            this.$el.trigger(namespace + type, args);
         | 
| 199 | 
            +
                        }
         | 
| 200 | 
            +
                    });
         | 
| 201 | 
            +
                    return EventBus;
         | 
| 202 | 
            +
                }();
         | 
| 203 | 
            +
                var EventEmitter = function() {
         | 
| 204 | 
            +
                    var splitter = /\s+/, nextTick = getNextTick();
         | 
| 205 | 
            +
                    return {
         | 
| 206 | 
            +
                        onSync: onSync,
         | 
| 207 | 
            +
                        onAsync: onAsync,
         | 
| 208 | 
            +
                        off: off,
         | 
| 209 | 
            +
                        trigger: trigger
         | 
| 210 | 
            +
                    };
         | 
| 211 | 
            +
                    function on(method, types, cb, context) {
         | 
| 212 | 
            +
                        var type;
         | 
| 213 | 
            +
                        if (!cb) {
         | 
| 214 | 
            +
                            return this;
         | 
| 215 | 
            +
                        }
         | 
| 216 | 
            +
                        types = types.split(splitter);
         | 
| 217 | 
            +
                        cb = context ? bindContext(cb, context) : cb;
         | 
| 218 | 
            +
                        this._callbacks = this._callbacks || {};
         | 
| 219 | 
            +
                        while (type = types.shift()) {
         | 
| 220 | 
            +
                            this._callbacks[type] = this._callbacks[type] || {
         | 
| 221 | 
            +
                                sync: [],
         | 
| 222 | 
            +
                                async: []
         | 
| 223 | 
            +
                            };
         | 
| 224 | 
            +
                            this._callbacks[type][method].push(cb);
         | 
| 225 | 
            +
                        }
         | 
| 226 | 
            +
                        return this;
         | 
| 227 | 
            +
                    }
         | 
| 228 | 
            +
                    function onAsync(types, cb, context) {
         | 
| 229 | 
            +
                        return on.call(this, "async", types, cb, context);
         | 
| 230 | 
            +
                    }
         | 
| 231 | 
            +
                    function onSync(types, cb, context) {
         | 
| 232 | 
            +
                        return on.call(this, "sync", types, cb, context);
         | 
| 233 | 
            +
                    }
         | 
| 234 | 
            +
                    function off(types) {
         | 
| 235 | 
            +
                        var type;
         | 
| 236 | 
            +
                        if (!this._callbacks) {
         | 
| 237 | 
            +
                            return this;
         | 
| 238 | 
            +
                        }
         | 
| 239 | 
            +
                        types = types.split(splitter);
         | 
| 240 | 
            +
                        while (type = types.shift()) {
         | 
| 241 | 
            +
                            delete this._callbacks[type];
         | 
| 242 | 
            +
                        }
         | 
| 243 | 
            +
                        return this;
         | 
| 244 | 
            +
                    }
         | 
| 245 | 
            +
                    function trigger(types) {
         | 
| 246 | 
            +
                        var that = this, type, callbacks, args, syncFlush, asyncFlush;
         | 
| 247 | 
            +
                        if (!this._callbacks) {
         | 
| 248 | 
            +
                            return this;
         | 
| 249 | 
            +
                        }
         | 
| 250 | 
            +
                        types = types.split(splitter);
         | 
| 251 | 
            +
                        args = [].slice.call(arguments, 1);
         | 
| 252 | 
            +
                        while ((type = types.shift()) && (callbacks = this._callbacks[type])) {
         | 
| 253 | 
            +
                            syncFlush = getFlush(callbacks.sync, this, [ type ].concat(args));
         | 
| 254 | 
            +
                            asyncFlush = getFlush(callbacks.async, this, [ type ].concat(args));
         | 
| 255 | 
            +
                            syncFlush() && nextTick(asyncFlush);
         | 
| 256 | 
            +
                        }
         | 
| 257 | 
            +
                        return this;
         | 
| 258 | 
            +
                    }
         | 
| 259 | 
            +
                    function getFlush(callbacks, context, args) {
         | 
| 260 | 
            +
                        return flush;
         | 
| 261 | 
            +
                        function flush() {
         | 
| 262 | 
            +
                            var cancelled;
         | 
| 263 | 
            +
                            for (var i = 0; !cancelled && i < callbacks.length; i += 1) {
         | 
| 264 | 
            +
                                cancelled = callbacks[i].apply(context, args) === false;
         | 
| 265 | 
            +
                            }
         | 
| 266 | 
            +
                            return !cancelled;
         | 
| 267 | 
            +
                        }
         | 
| 268 | 
            +
                    }
         | 
| 269 | 
            +
                    function getNextTick() {
         | 
| 270 | 
            +
                        var nextTickFn, messageChannel;
         | 
| 271 | 
            +
                        if (window.setImmediate) {
         | 
| 272 | 
            +
                            nextTickFn = function nextTickSetImmediate(fn) {
         | 
| 273 | 
            +
                                setImmediate(function() {
         | 
| 274 | 
            +
                                    fn();
         | 
| 275 | 
            +
                                });
         | 
| 276 | 
            +
                            };
         | 
| 277 | 
            +
                        } else {
         | 
| 278 | 
            +
                            nextTickFn = function nextTickSetTimeout(fn) {
         | 
| 279 | 
            +
                                setTimeout(function() {
         | 
| 280 | 
            +
                                    fn();
         | 
| 281 | 
            +
                                }, 0);
         | 
| 282 | 
            +
                            };
         | 
| 283 | 
            +
                        }
         | 
| 284 | 
            +
                        return nextTickFn;
         | 
| 285 | 
            +
                    }
         | 
| 286 | 
            +
                    function bindContext(fn, context) {
         | 
| 287 | 
            +
                        return fn.bind ? fn.bind(context) : function() {
         | 
| 288 | 
            +
                            fn.apply(context, [].slice.call(arguments, 0));
         | 
| 289 | 
            +
                        };
         | 
| 290 | 
            +
                    }
         | 
| 291 | 
            +
                }();
         | 
| 292 | 
            +
                var highlight = function(doc) {
         | 
| 293 | 
            +
                    var defaults = {
         | 
| 294 | 
            +
                        node: null,
         | 
| 295 | 
            +
                        pattern: null,
         | 
| 296 | 
            +
                        tagName: "strong",
         | 
| 297 | 
            +
                        className: null,
         | 
| 298 | 
            +
                        wordsOnly: false,
         | 
| 299 | 
            +
                        caseSensitive: false
         | 
| 300 | 
            +
                    };
         | 
| 301 | 
            +
                    return function hightlight(o) {
         | 
| 302 | 
            +
                        var regex;
         | 
| 303 | 
            +
                        o = _.mixin({}, defaults, o);
         | 
| 304 | 
            +
                        if (!o.node || !o.pattern) {
         | 
| 305 | 
            +
                            return;
         | 
| 306 | 
            +
                        }
         | 
| 307 | 
            +
                        o.pattern = _.isArray(o.pattern) ? o.pattern : [ o.pattern ];
         | 
| 308 | 
            +
                        regex = getRegex(o.pattern, o.caseSensitive, o.wordsOnly);
         | 
| 309 | 
            +
                        traverse(o.node, hightlightTextNode);
         | 
| 310 | 
            +
                        function hightlightTextNode(textNode) {
         | 
| 311 | 
            +
                            var match, patternNode;
         | 
| 312 | 
            +
                            if (match = regex.exec(textNode.data)) {
         | 
| 313 | 
            +
                                wrapperNode = doc.createElement(o.tagName);
         | 
| 314 | 
            +
                                o.className && (wrapperNode.className = o.className);
         | 
| 315 | 
            +
                                patternNode = textNode.splitText(match.index);
         | 
| 316 | 
            +
                                patternNode.splitText(match[0].length);
         | 
| 317 | 
            +
                                wrapperNode.appendChild(patternNode.cloneNode(true));
         | 
| 318 | 
            +
                                textNode.parentNode.replaceChild(wrapperNode, patternNode);
         | 
| 319 | 
            +
                            }
         | 
| 320 | 
            +
                            return !!match;
         | 
| 321 | 
            +
                        }
         | 
| 322 | 
            +
                        function traverse(el, hightlightTextNode) {
         | 
| 323 | 
            +
                            var childNode, TEXT_NODE_TYPE = 3;
         | 
| 324 | 
            +
                            for (var i = 0; i < el.childNodes.length; i++) {
         | 
| 325 | 
            +
                                childNode = el.childNodes[i];
         | 
| 326 | 
            +
                                if (childNode.nodeType === TEXT_NODE_TYPE) {
         | 
| 327 | 
            +
                                    i += hightlightTextNode(childNode) ? 1 : 0;
         | 
| 328 | 
            +
                                } else {
         | 
| 329 | 
            +
                                    traverse(childNode, hightlightTextNode);
         | 
| 330 | 
            +
                                }
         | 
| 331 | 
            +
                            }
         | 
| 332 | 
            +
                        }
         | 
| 333 | 
            +
                    };
         | 
| 334 | 
            +
                    function getRegex(patterns, caseSensitive, wordsOnly) {
         | 
| 335 | 
            +
                        var escapedPatterns = [], regexStr;
         | 
| 336 | 
            +
                        for (var i = 0; i < patterns.length; i++) {
         | 
| 337 | 
            +
                            escapedPatterns.push(_.escapeRegExChars(patterns[i]));
         | 
| 338 | 
            +
                        }
         | 
| 339 | 
            +
                        regexStr = wordsOnly ? "\\b(" + escapedPatterns.join("|") + ")\\b" : "(" + escapedPatterns.join("|") + ")";
         | 
| 340 | 
            +
                        return caseSensitive ? new RegExp(regexStr) : new RegExp(regexStr, "i");
         | 
| 341 | 
            +
                    }
         | 
| 342 | 
            +
                }(window.document);
         | 
| 343 | 
            +
                var Input = function() {
         | 
| 344 | 
            +
                    var specialKeyCodeMap;
         | 
| 345 | 
            +
                    specialKeyCodeMap = {
         | 
| 346 | 
            +
                        9: "tab",
         | 
| 347 | 
            +
                        27: "esc",
         | 
| 348 | 
            +
                        37: "left",
         | 
| 349 | 
            +
                        39: "right",
         | 
| 350 | 
            +
                        13: "enter",
         | 
| 351 | 
            +
                        38: "up",
         | 
| 352 | 
            +
                        40: "down"
         | 
| 353 | 
            +
                    };
         | 
| 354 | 
            +
                    function Input(o) {
         | 
| 355 | 
            +
                        var that = this, onBlur, onFocus, onKeydown, onInput;
         | 
| 356 | 
            +
                        o = o || {};
         | 
| 357 | 
            +
                        if (!o.input) {
         | 
| 358 | 
            +
                            $.error("input is missing");
         | 
| 359 | 
            +
                        }
         | 
| 360 | 
            +
                        onBlur = _.bind(this._onBlur, this);
         | 
| 361 | 
            +
                        onFocus = _.bind(this._onFocus, this);
         | 
| 362 | 
            +
                        onKeydown = _.bind(this._onKeydown, this);
         | 
| 363 | 
            +
                        onInput = _.bind(this._onInput, this);
         | 
| 364 | 
            +
                        this.$hint = $(o.hint);
         | 
| 365 | 
            +
                        this.$input = $(o.input).on("blur.tt", onBlur).on("focus.tt", onFocus).on("keydown.tt", onKeydown);
         | 
| 366 | 
            +
                        if (this.$hint.length === 0) {
         | 
| 367 | 
            +
                            this.setHintValue = this.getHintValue = this.clearHint = _.noop;
         | 
| 368 | 
            +
                        }
         | 
| 369 | 
            +
                        if (!_.isMsie()) {
         | 
| 370 | 
            +
                            this.$input.on("input.tt", onInput);
         | 
| 371 | 
            +
                        } else {
         | 
| 372 | 
            +
                            this.$input.on("keydown.tt keypress.tt cut.tt paste.tt", function($e) {
         | 
| 373 | 
            +
                                if (specialKeyCodeMap[$e.which || $e.keyCode]) {
         | 
| 374 | 
            +
                                    return;
         | 
| 375 | 
            +
                                }
         | 
| 376 | 
            +
                                _.defer(_.bind(that._onInput, that, $e));
         | 
| 377 | 
            +
                            });
         | 
| 378 | 
            +
                        }
         | 
| 379 | 
            +
                        this.query = this.$input.val();
         | 
| 380 | 
            +
                        this.$overflowHelper = buildOverflowHelper(this.$input);
         | 
| 381 | 
            +
                    }
         | 
| 382 | 
            +
                    Input.normalizeQuery = function(str) {
         | 
| 383 | 
            +
                        return (str || "").replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
         | 
| 384 | 
            +
                    };
         | 
| 385 | 
            +
                    _.mixin(Input.prototype, EventEmitter, {
         | 
| 386 | 
            +
                        _onBlur: function onBlur($e) {
         | 
| 387 | 
            +
                            this.resetInputValue();
         | 
| 388 | 
            +
                            this.trigger("blurred");
         | 
| 389 | 
            +
                        },
         | 
| 390 | 
            +
                        _onFocus: function onFocus($e) {
         | 
| 391 | 
            +
                            this.trigger("focused");
         | 
| 392 | 
            +
                        },
         | 
| 393 | 
            +
                        _onKeydown: function onKeydown($e) {
         | 
| 394 | 
            +
                            var keyName = specialKeyCodeMap[$e.which || $e.keyCode];
         | 
| 395 | 
            +
                            this._managePreventDefault(keyName, $e);
         | 
| 396 | 
            +
                            if (keyName && this._shouldTrigger(keyName, $e)) {
         | 
| 397 | 
            +
                                this.trigger(keyName + "Keyed", $e);
         | 
| 398 | 
            +
                            }
         | 
| 399 | 
            +
                        },
         | 
| 400 | 
            +
                        _onInput: function onInput($e) {
         | 
| 401 | 
            +
                            this._checkInputValue();
         | 
| 402 | 
            +
                        },
         | 
| 403 | 
            +
                        _managePreventDefault: function managePreventDefault(keyName, $e) {
         | 
| 404 | 
            +
                            var preventDefault, hintValue, inputValue;
         | 
| 405 | 
            +
                            switch (keyName) {
         | 
| 406 | 
            +
                              case "tab":
         | 
| 407 | 
            +
                                hintValue = this.getHintValue();
         | 
| 408 | 
            +
                                inputValue = this.getInputValue();
         | 
| 409 | 
            +
                                preventDefault = hintValue && hintValue !== inputValue && !withModifier($e);
         | 
| 410 | 
            +
                                break;
         | 
| 411 | 
            +
             | 
| 412 | 
            +
                              case "up":
         | 
| 413 | 
            +
                              case "down":
         | 
| 414 | 
            +
                                preventDefault = !withModifier($e);
         | 
| 415 | 
            +
                                break;
         | 
| 416 | 
            +
             | 
| 417 | 
            +
                              default:
         | 
| 418 | 
            +
                                preventDefault = false;
         | 
| 419 | 
            +
                            }
         | 
| 420 | 
            +
                            preventDefault && $e.preventDefault();
         | 
| 421 | 
            +
                        },
         | 
| 422 | 
            +
                        _shouldTrigger: function shouldTrigger(keyName, $e) {
         | 
| 423 | 
            +
                            var trigger;
         | 
| 424 | 
            +
                            switch (keyName) {
         | 
| 425 | 
            +
                              case "tab":
         | 
| 426 | 
            +
                                trigger = !withModifier($e);
         | 
| 427 | 
            +
                                break;
         | 
| 428 | 
            +
             | 
| 429 | 
            +
                              default:
         | 
| 430 | 
            +
                                trigger = true;
         | 
| 431 | 
            +
                            }
         | 
| 432 | 
            +
                            return trigger;
         | 
| 433 | 
            +
                        },
         | 
| 434 | 
            +
                        _checkInputValue: function checkInputValue() {
         | 
| 435 | 
            +
                            var inputValue, areEquivalent, hasDifferentWhitespace;
         | 
| 436 | 
            +
                            inputValue = this.getInputValue();
         | 
| 437 | 
            +
                            areEquivalent = areQueriesEquivalent(inputValue, this.query);
         | 
| 438 | 
            +
                            hasDifferentWhitespace = areEquivalent ? this.query.length !== inputValue.length : false;
         | 
| 439 | 
            +
                            if (!areEquivalent) {
         | 
| 440 | 
            +
                                this.trigger("queryChanged", this.query = inputValue);
         | 
| 441 | 
            +
                            } else if (hasDifferentWhitespace) {
         | 
| 442 | 
            +
                                this.trigger("whitespaceChanged", this.query);
         | 
| 443 | 
            +
                            }
         | 
| 444 | 
            +
                        },
         | 
| 445 | 
            +
                        focus: function focus() {
         | 
| 446 | 
            +
                            this.$input.focus();
         | 
| 447 | 
            +
                        },
         | 
| 448 | 
            +
                        blur: function blur() {
         | 
| 449 | 
            +
                            this.$input.blur();
         | 
| 450 | 
            +
                        },
         | 
| 451 | 
            +
                        getQuery: function getQuery() {
         | 
| 452 | 
            +
                            return this.query;
         | 
| 453 | 
            +
                        },
         | 
| 454 | 
            +
                        setQuery: function setQuery(query) {
         | 
| 455 | 
            +
                            this.query = query;
         | 
| 456 | 
            +
                        },
         | 
| 457 | 
            +
                        getInputValue: function getInputValue() {
         | 
| 458 | 
            +
                            return this.$input.val();
         | 
| 459 | 
            +
                        },
         | 
| 460 | 
            +
                        setInputValue: function setInputValue(value, silent) {
         | 
| 461 | 
            +
                            this.$input.val(value);
         | 
| 462 | 
            +
                            !silent && this._checkInputValue();
         | 
| 463 | 
            +
                        },
         | 
| 464 | 
            +
                        getHintValue: function getHintValue() {
         | 
| 465 | 
            +
                            return this.$hint.val();
         | 
| 466 | 
            +
                        },
         | 
| 467 | 
            +
                        setHintValue: function setHintValue(value) {
         | 
| 468 | 
            +
                            this.$hint.val(value);
         | 
| 469 | 
            +
                        },
         | 
| 470 | 
            +
                        resetInputValue: function resetInputValue() {
         | 
| 471 | 
            +
                            this.$input.val(this.query);
         | 
| 472 | 
            +
                        },
         | 
| 473 | 
            +
                        clearHint: function clearHint() {
         | 
| 474 | 
            +
                            this.$hint.val("");
         | 
| 475 | 
            +
                        },
         | 
| 476 | 
            +
                        getLanguageDirection: function getLanguageDirection() {
         | 
| 477 | 
            +
                            return (this.$input.css("direction") || "ltr").toLowerCase();
         | 
| 478 | 
            +
                        },
         | 
| 479 | 
            +
                        hasOverflow: function hasOverflow() {
         | 
| 480 | 
            +
                            var constraint = this.$input.width() - 2;
         | 
| 481 | 
            +
                            this.$overflowHelper.text(this.getInputValue());
         | 
| 482 | 
            +
                            return this.$overflowHelper.width() >= constraint;
         | 
| 483 | 
            +
                        },
         | 
| 484 | 
            +
                        isCursorAtEnd: function() {
         | 
| 485 | 
            +
                            var valueLength, selectionStart, range;
         | 
| 486 | 
            +
                            valueLength = this.$input.val().length;
         | 
| 487 | 
            +
                            selectionStart = this.$input[0].selectionStart;
         | 
| 488 | 
            +
                            if (_.isNumber(selectionStart)) {
         | 
| 489 | 
            +
                                return selectionStart === valueLength;
         | 
| 490 | 
            +
                            } else if (document.selection) {
         | 
| 491 | 
            +
                                range = document.selection.createRange();
         | 
| 492 | 
            +
                                range.moveStart("character", -valueLength);
         | 
| 493 | 
            +
                                return valueLength === range.text.length;
         | 
| 494 | 
            +
                            }
         | 
| 495 | 
            +
                            return true;
         | 
| 496 | 
            +
                        },
         | 
| 497 | 
            +
                        destroy: function destroy() {
         | 
| 498 | 
            +
                            this.$hint.off(".tt");
         | 
| 499 | 
            +
                            this.$input.off(".tt");
         | 
| 500 | 
            +
                            this.$hint = this.$input = this.$overflowHelper = null;
         | 
| 501 | 
            +
                        }
         | 
| 502 | 
            +
                    });
         | 
| 503 | 
            +
                    return Input;
         | 
| 504 | 
            +
                    function buildOverflowHelper($input) {
         | 
| 505 | 
            +
                        return $('<pre aria-hidden="true"></pre>').css({
         | 
| 506 | 
            +
                            position: "absolute",
         | 
| 507 | 
            +
                            visibility: "hidden",
         | 
| 508 | 
            +
                            whiteSpace: "nowrap",
         | 
| 509 | 
            +
                            fontFamily: $input.css("font-family"),
         | 
| 510 | 
            +
                            fontSize: $input.css("font-size"),
         | 
| 511 | 
            +
                            fontStyle: $input.css("font-style"),
         | 
| 512 | 
            +
                            fontVariant: $input.css("font-variant"),
         | 
| 513 | 
            +
                            fontWeight: $input.css("font-weight"),
         | 
| 514 | 
            +
                            wordSpacing: $input.css("word-spacing"),
         | 
| 515 | 
            +
                            letterSpacing: $input.css("letter-spacing"),
         | 
| 516 | 
            +
                            textIndent: $input.css("text-indent"),
         | 
| 517 | 
            +
                            textRendering: $input.css("text-rendering"),
         | 
| 518 | 
            +
                            textTransform: $input.css("text-transform")
         | 
| 519 | 
            +
                        }).insertAfter($input);
         | 
| 520 | 
            +
                    }
         | 
| 521 | 
            +
                    function areQueriesEquivalent(a, b) {
         | 
| 522 | 
            +
                        return Input.normalizeQuery(a) === Input.normalizeQuery(b);
         | 
| 523 | 
            +
                    }
         | 
| 524 | 
            +
                    function withModifier($e) {
         | 
| 525 | 
            +
                        return $e.altKey || $e.ctrlKey || $e.metaKey || $e.shiftKey;
         | 
| 526 | 
            +
                    }
         | 
| 527 | 
            +
                }();
         | 
| 528 | 
            +
                var Dataset = function() {
         | 
| 529 | 
            +
                    var datasetKey = "ttDataset", valueKey = "ttValue", datumKey = "ttDatum";
         | 
| 530 | 
            +
                    function Dataset(o) {
         | 
| 531 | 
            +
                        o = o || {};
         | 
| 532 | 
            +
                        o.templates = o.templates || {};
         | 
| 533 | 
            +
                        if (!o.source) {
         | 
| 534 | 
            +
                            $.error("missing source");
         | 
| 535 | 
            +
                        }
         | 
| 536 | 
            +
                        if (o.name && !isValidName(o.name)) {
         | 
| 537 | 
            +
                            $.error("invalid dataset name: " + o.name);
         | 
| 538 | 
            +
                        }
         | 
| 539 | 
            +
                        this.query = null;
         | 
| 540 | 
            +
                        this.highlight = !!o.highlight;
         | 
| 541 | 
            +
                        this.name = o.name || _.getUniqueId();
         | 
| 542 | 
            +
                        this.source = o.source;
         | 
| 543 | 
            +
                        this.displayFn = getDisplayFn(o.display || o.displayKey);
         | 
| 544 | 
            +
                        this.templates = getTemplates(o.templates, this.displayFn);
         | 
| 545 | 
            +
                        this.$el = $(html.dataset.replace("%CLASS%", this.name));
         | 
| 546 | 
            +
                    }
         | 
| 547 | 
            +
                    Dataset.extractDatasetName = function extractDatasetName(el) {
         | 
| 548 | 
            +
                        return $(el).data(datasetKey);
         | 
| 549 | 
            +
                    };
         | 
| 550 | 
            +
                    Dataset.extractValue = function extractDatum(el) {
         | 
| 551 | 
            +
                        return $(el).data(valueKey);
         | 
| 552 | 
            +
                    };
         | 
| 553 | 
            +
                    Dataset.extractDatum = function extractDatum(el) {
         | 
| 554 | 
            +
                        return $(el).data(datumKey);
         | 
| 555 | 
            +
                    };
         | 
| 556 | 
            +
                    _.mixin(Dataset.prototype, EventEmitter, {
         | 
| 557 | 
            +
                        _render: function render(query, suggestions) {
         | 
| 558 | 
            +
                            if (!this.$el) {
         | 
| 559 | 
            +
                                return;
         | 
| 560 | 
            +
                            }
         | 
| 561 | 
            +
                            var that = this, hasSuggestions;
         | 
| 562 | 
            +
                            this.$el.empty();
         | 
| 563 | 
            +
                            hasSuggestions = suggestions && suggestions.length;
         | 
| 564 | 
            +
                            if (!hasSuggestions && this.templates.empty) {
         | 
| 565 | 
            +
                                this.$el.html(getEmptyHtml()).prepend(that.templates.header ? getHeaderHtml() : null).append(that.templates.footer ? getFooterHtml() : null);
         | 
| 566 | 
            +
                            } else if (hasSuggestions) {
         | 
| 567 | 
            +
                                this.$el.html(getSuggestionsHtml()).prepend(that.templates.header ? getHeaderHtml() : null).append(that.templates.footer ? getFooterHtml() : null);
         | 
| 568 | 
            +
                            }
         | 
| 569 | 
            +
                            this.trigger("rendered");
         | 
| 570 | 
            +
                            function getEmptyHtml() {
         | 
| 571 | 
            +
                                return that.templates.empty({
         | 
| 572 | 
            +
                                    query: query,
         | 
| 573 | 
            +
                                    isEmpty: true
         | 
| 574 | 
            +
                                });
         | 
| 575 | 
            +
                            }
         | 
| 576 | 
            +
                            function getSuggestionsHtml() {
         | 
| 577 | 
            +
                                var $suggestions, nodes;
         | 
| 578 | 
            +
                                $suggestions = $(html.suggestions).css(css.suggestions);
         | 
| 579 | 
            +
                                nodes = _.map(suggestions, getSuggestionNode);
         | 
| 580 | 
            +
                                $suggestions.append.apply($suggestions, nodes);
         | 
| 581 | 
            +
                                that.highlight && highlight({
         | 
| 582 | 
            +
                                    node: $suggestions[0],
         | 
| 583 | 
            +
                                    pattern: query
         | 
| 584 | 
            +
                                });
         | 
| 585 | 
            +
                                return $suggestions;
         | 
| 586 | 
            +
                                function getSuggestionNode(suggestion) {
         | 
| 587 | 
            +
                                    var $el, innerHtml, outerHtml;
         | 
| 588 | 
            +
                                    innerHtml = that.templates.suggestion(suggestion);
         | 
| 589 | 
            +
                                    outerHtml = html.suggestion.replace("%BODY%", innerHtml);
         | 
| 590 | 
            +
                                    $el = $(outerHtml).data(datasetKey, that.name).data(valueKey, that.displayFn(suggestion)).data(datumKey, suggestion);
         | 
| 591 | 
            +
                                    $el.children().each(function() {
         | 
| 592 | 
            +
                                        $(this).css(css.suggestionChild);
         | 
| 593 | 
            +
                                    });
         | 
| 594 | 
            +
                                    return $el;
         | 
| 595 | 
            +
                                }
         | 
| 596 | 
            +
                            }
         | 
| 597 | 
            +
                            function getHeaderHtml() {
         | 
| 598 | 
            +
                                return that.templates.header({
         | 
| 599 | 
            +
                                    query: query,
         | 
| 600 | 
            +
                                    isEmpty: !hasSuggestions
         | 
| 601 | 
            +
                                });
         | 
| 602 | 
            +
                            }
         | 
| 603 | 
            +
                            function getFooterHtml() {
         | 
| 604 | 
            +
                                return that.templates.footer({
         | 
| 605 | 
            +
                                    query: query,
         | 
| 606 | 
            +
                                    isEmpty: !hasSuggestions
         | 
| 607 | 
            +
                                });
         | 
| 608 | 
            +
                            }
         | 
| 609 | 
            +
                        },
         | 
| 610 | 
            +
                        getRoot: function getRoot() {
         | 
| 611 | 
            +
                            return this.$el;
         | 
| 612 | 
            +
                        },
         | 
| 613 | 
            +
                        update: function update(query) {
         | 
| 614 | 
            +
                            var that = this;
         | 
| 615 | 
            +
                            this.query = query;
         | 
| 616 | 
            +
                            this.source(query, renderIfQueryIsSame);
         | 
| 617 | 
            +
                            function renderIfQueryIsSame(suggestions) {
         | 
| 618 | 
            +
                                query === that.query && that._render(query, suggestions);
         | 
| 619 | 
            +
                            }
         | 
| 620 | 
            +
                        },
         | 
| 621 | 
            +
                        clear: function clear() {
         | 
| 622 | 
            +
                            this._render(this.query || "");
         | 
| 623 | 
            +
                        },
         | 
| 624 | 
            +
                        isEmpty: function isEmpty() {
         | 
| 625 | 
            +
                            return this.$el.is(":empty");
         | 
| 626 | 
            +
                        },
         | 
| 627 | 
            +
                        destroy: function destroy() {
         | 
| 628 | 
            +
                            this.$el = null;
         | 
| 629 | 
            +
                        }
         | 
| 630 | 
            +
                    });
         | 
| 631 | 
            +
                    return Dataset;
         | 
| 632 | 
            +
                    function getDisplayFn(display) {
         | 
| 633 | 
            +
                        display = display || "value";
         | 
| 634 | 
            +
                        return _.isFunction(display) ? display : displayFn;
         | 
| 635 | 
            +
                        function displayFn(obj) {
         | 
| 636 | 
            +
                            return obj[display];
         | 
| 637 | 
            +
                        }
         | 
| 638 | 
            +
                    }
         | 
| 639 | 
            +
                    function getTemplates(templates, displayFn) {
         | 
| 640 | 
            +
                        return {
         | 
| 641 | 
            +
                            empty: templates.empty && _.templatify(templates.empty),
         | 
| 642 | 
            +
                            header: templates.header && _.templatify(templates.header),
         | 
| 643 | 
            +
                            footer: templates.footer && _.templatify(templates.footer),
         | 
| 644 | 
            +
                            suggestion: templates.suggestion || suggestionTemplate
         | 
| 645 | 
            +
                        };
         | 
| 646 | 
            +
                        function suggestionTemplate(context) {
         | 
| 647 | 
            +
                            return "<p>" + displayFn(context) + "</p>";
         | 
| 648 | 
            +
                        }
         | 
| 649 | 
            +
                    }
         | 
| 650 | 
            +
                    function isValidName(str) {
         | 
| 651 | 
            +
                        return /^[_a-zA-Z0-9-]+$/.test(str);
         | 
| 652 | 
            +
                    }
         | 
| 653 | 
            +
                }();
         | 
| 654 | 
            +
                var Dropdown = function() {
         | 
| 655 | 
            +
                    function Dropdown(o) {
         | 
| 656 | 
            +
                        var that = this, onSuggestionClick, onSuggestionMouseEnter, onSuggestionMouseLeave;
         | 
| 657 | 
            +
                        o = o || {};
         | 
| 658 | 
            +
                        if (!o.menu) {
         | 
| 659 | 
            +
                            $.error("menu is required");
         | 
| 660 | 
            +
                        }
         | 
| 661 | 
            +
                        this.isOpen = false;
         | 
| 662 | 
            +
                        this.isEmpty = true;
         | 
| 663 | 
            +
                        this.datasets = _.map(o.datasets, initializeDataset);
         | 
| 664 | 
            +
                        onSuggestionClick = _.bind(this._onSuggestionClick, this);
         | 
| 665 | 
            +
                        onSuggestionMouseEnter = _.bind(this._onSuggestionMouseEnter, this);
         | 
| 666 | 
            +
                        onSuggestionMouseLeave = _.bind(this._onSuggestionMouseLeave, this);
         | 
| 667 | 
            +
                        this.$menu = $(o.menu).on("click.tt", ".tt-suggestion", onSuggestionClick).on("mouseenter.tt", ".tt-suggestion", onSuggestionMouseEnter).on("mouseleave.tt", ".tt-suggestion", onSuggestionMouseLeave);
         | 
| 668 | 
            +
                        _.each(this.datasets, function(dataset) {
         | 
| 669 | 
            +
                            that.$menu.append(dataset.getRoot());
         | 
| 670 | 
            +
                            dataset.onSync("rendered", that._onRendered, that);
         | 
| 671 | 
            +
                        });
         | 
| 672 | 
            +
                    }
         | 
| 673 | 
            +
                    _.mixin(Dropdown.prototype, EventEmitter, {
         | 
| 674 | 
            +
                        _onSuggestionClick: function onSuggestionClick($e) {
         | 
| 675 | 
            +
                            this.trigger("suggestionClicked", $($e.currentTarget));
         | 
| 676 | 
            +
                        },
         | 
| 677 | 
            +
                        _onSuggestionMouseEnter: function onSuggestionMouseEnter($e) {
         | 
| 678 | 
            +
                            this._removeCursor();
         | 
| 679 | 
            +
                            this._setCursor($($e.currentTarget), true);
         | 
| 680 | 
            +
                        },
         | 
| 681 | 
            +
                        _onSuggestionMouseLeave: function onSuggestionMouseLeave($e) {
         | 
| 682 | 
            +
                            this._removeCursor();
         | 
| 683 | 
            +
                        },
         | 
| 684 | 
            +
                        _onRendered: function onRendered() {
         | 
| 685 | 
            +
                            this.isEmpty = _.every(this.datasets, isDatasetEmpty);
         | 
| 686 | 
            +
                            this.isEmpty ? this._hide() : this.isOpen && this._show();
         | 
| 687 | 
            +
                            this.trigger("datasetRendered");
         | 
| 688 | 
            +
                            function isDatasetEmpty(dataset) {
         | 
| 689 | 
            +
                                return dataset.isEmpty();
         | 
| 690 | 
            +
                            }
         | 
| 691 | 
            +
                        },
         | 
| 692 | 
            +
                        _hide: function() {
         | 
| 693 | 
            +
                            this.$menu.hide();
         | 
| 694 | 
            +
                        },
         | 
| 695 | 
            +
                        _show: function() {
         | 
| 696 | 
            +
                            this.$menu.css("display", "block");
         | 
| 697 | 
            +
                        },
         | 
| 698 | 
            +
                        _getSuggestions: function getSuggestions() {
         | 
| 699 | 
            +
                            return this.$menu.find(".tt-suggestion");
         | 
| 700 | 
            +
                        },
         | 
| 701 | 
            +
                        _getCursor: function getCursor() {
         | 
| 702 | 
            +
                            return this.$menu.find(".tt-cursor").first();
         | 
| 703 | 
            +
                        },
         | 
| 704 | 
            +
                        _setCursor: function setCursor($el, silent) {
         | 
| 705 | 
            +
                            $el.first().addClass("tt-cursor");
         | 
| 706 | 
            +
                            !silent && this.trigger("cursorMoved");
         | 
| 707 | 
            +
                        },
         | 
| 708 | 
            +
                        _removeCursor: function removeCursor() {
         | 
| 709 | 
            +
                            this._getCursor().removeClass("tt-cursor");
         | 
| 710 | 
            +
                        },
         | 
| 711 | 
            +
                        _moveCursor: function moveCursor(increment) {
         | 
| 712 | 
            +
                            var $suggestions, $oldCursor, newCursorIndex, $newCursor;
         | 
| 713 | 
            +
                            if (!this.isOpen) {
         | 
| 714 | 
            +
                                return;
         | 
| 715 | 
            +
                            }
         | 
| 716 | 
            +
                            $oldCursor = this._getCursor();
         | 
| 717 | 
            +
                            $suggestions = this._getSuggestions();
         | 
| 718 | 
            +
                            this._removeCursor();
         | 
| 719 | 
            +
                            newCursorIndex = $suggestions.index($oldCursor) + increment;
         | 
| 720 | 
            +
                            newCursorIndex = (newCursorIndex + 1) % ($suggestions.length + 1) - 1;
         | 
| 721 | 
            +
                            if (newCursorIndex === -1) {
         | 
| 722 | 
            +
                                this.trigger("cursorRemoved");
         | 
| 723 | 
            +
                                return;
         | 
| 724 | 
            +
                            } else if (newCursorIndex < -1) {
         | 
| 725 | 
            +
                                newCursorIndex = $suggestions.length - 1;
         | 
| 726 | 
            +
                            }
         | 
| 727 | 
            +
                            this._setCursor($newCursor = $suggestions.eq(newCursorIndex));
         | 
| 728 | 
            +
                            this._ensureVisible($newCursor);
         | 
| 729 | 
            +
                        },
         | 
| 730 | 
            +
                        _ensureVisible: function ensureVisible($el) {
         | 
| 731 | 
            +
                            var elTop, elBottom, menuScrollTop, menuHeight;
         | 
| 732 | 
            +
                            elTop = $el.position().top;
         | 
| 733 | 
            +
                            elBottom = elTop + $el.outerHeight(true);
         | 
| 734 | 
            +
                            menuScrollTop = this.$menu.scrollTop();
         | 
| 735 | 
            +
                            menuHeight = this.$menu.height() + parseInt(this.$menu.css("paddingTop"), 10) + parseInt(this.$menu.css("paddingBottom"), 10);
         | 
| 736 | 
            +
                            if (elTop < 0) {
         | 
| 737 | 
            +
                                this.$menu.scrollTop(menuScrollTop + elTop);
         | 
| 738 | 
            +
                            } else if (menuHeight < elBottom) {
         | 
| 739 | 
            +
                                this.$menu.scrollTop(menuScrollTop + (elBottom - menuHeight));
         | 
| 740 | 
            +
                            }
         | 
| 741 | 
            +
                        },
         | 
| 742 | 
            +
                        close: function close() {
         | 
| 743 | 
            +
                            if (this.isOpen) {
         | 
| 744 | 
            +
                                this.isOpen = false;
         | 
| 745 | 
            +
                                this._removeCursor();
         | 
| 746 | 
            +
                                this._hide();
         | 
| 747 | 
            +
                                this.trigger("closed");
         | 
| 748 | 
            +
                            }
         | 
| 749 | 
            +
                        },
         | 
| 750 | 
            +
                        open: function open() {
         | 
| 751 | 
            +
                            if (!this.isOpen) {
         | 
| 752 | 
            +
                                this.isOpen = true;
         | 
| 753 | 
            +
                                !this.isEmpty && this._show();
         | 
| 754 | 
            +
                                this.trigger("opened");
         | 
| 755 | 
            +
                            }
         | 
| 756 | 
            +
                        },
         | 
| 757 | 
            +
                        setLanguageDirection: function setLanguageDirection(dir) {
         | 
| 758 | 
            +
                            this.$menu.css(dir === "ltr" ? css.ltr : css.rtl);
         | 
| 759 | 
            +
                        },
         | 
| 760 | 
            +
                        moveCursorUp: function moveCursorUp() {
         | 
| 761 | 
            +
                            this._moveCursor(-1);
         | 
| 762 | 
            +
                        },
         | 
| 763 | 
            +
                        moveCursorDown: function moveCursorDown() {
         | 
| 764 | 
            +
                            this._moveCursor(+1);
         | 
| 765 | 
            +
                        },
         | 
| 766 | 
            +
                        getDatumForSuggestion: function getDatumForSuggestion($el) {
         | 
| 767 | 
            +
                            var datum = null;
         | 
| 768 | 
            +
                            if ($el.length) {
         | 
| 769 | 
            +
                                datum = {
         | 
| 770 | 
            +
                                    raw: Dataset.extractDatum($el),
         | 
| 771 | 
            +
                                    value: Dataset.extractValue($el),
         | 
| 772 | 
            +
                                    datasetName: Dataset.extractDatasetName($el)
         | 
| 773 | 
            +
                                };
         | 
| 774 | 
            +
                            }
         | 
| 775 | 
            +
                            return datum;
         | 
| 776 | 
            +
                        },
         | 
| 777 | 
            +
                        getDatumForCursor: function getDatumForCursor() {
         | 
| 778 | 
            +
                            return this.getDatumForSuggestion(this._getCursor().first());
         | 
| 779 | 
            +
                        },
         | 
| 780 | 
            +
                        getDatumForTopSuggestion: function getDatumForTopSuggestion() {
         | 
| 781 | 
            +
                            return this.getDatumForSuggestion(this._getSuggestions().first());
         | 
| 782 | 
            +
                        },
         | 
| 783 | 
            +
                        update: function update(query) {
         | 
| 784 | 
            +
                            _.each(this.datasets, updateDataset);
         | 
| 785 | 
            +
                            function updateDataset(dataset) {
         | 
| 786 | 
            +
                                dataset.update(query);
         | 
| 787 | 
            +
                            }
         | 
| 788 | 
            +
                        },
         | 
| 789 | 
            +
                        empty: function empty() {
         | 
| 790 | 
            +
                            _.each(this.datasets, clearDataset);
         | 
| 791 | 
            +
                            this.isEmpty = true;
         | 
| 792 | 
            +
                            function clearDataset(dataset) {
         | 
| 793 | 
            +
                                dataset.clear();
         | 
| 794 | 
            +
                            }
         | 
| 795 | 
            +
                        },
         | 
| 796 | 
            +
                        isVisible: function isVisible() {
         | 
| 797 | 
            +
                            return this.isOpen && !this.isEmpty;
         | 
| 798 | 
            +
                        },
         | 
| 799 | 
            +
                        destroy: function destroy() {
         | 
| 800 | 
            +
                            this.$menu.off(".tt");
         | 
| 801 | 
            +
                            this.$menu = null;
         | 
| 802 | 
            +
                            _.each(this.datasets, destroyDataset);
         | 
| 803 | 
            +
                            function destroyDataset(dataset) {
         | 
| 804 | 
            +
                                dataset.destroy();
         | 
| 805 | 
            +
                            }
         | 
| 806 | 
            +
                        }
         | 
| 807 | 
            +
                    });
         | 
| 808 | 
            +
                    return Dropdown;
         | 
| 809 | 
            +
                    function initializeDataset(oDataset) {
         | 
| 810 | 
            +
                        return new Dataset(oDataset);
         | 
| 811 | 
            +
                    }
         | 
| 812 | 
            +
                }();
         | 
| 813 | 
            +
                var Typeahead = function() {
         | 
| 814 | 
            +
                    var attrsKey = "ttAttrs";
         | 
| 815 | 
            +
                    function Typeahead(o) {
         | 
| 816 | 
            +
                        var $menu, $input, $hint, datasets;
         | 
| 817 | 
            +
                        o = o || {};
         | 
| 818 | 
            +
                        if (!o.input) {
         | 
| 819 | 
            +
                            $.error("missing input");
         | 
| 820 | 
            +
                        }
         | 
| 821 | 
            +
                        this.autoselect = !!o.autoselect;
         | 
| 822 | 
            +
                        this.minLength = _.isNumber(o.minLength) ? o.minLength : 1;
         | 
| 823 | 
            +
                        this.$node = buildDomStructure(o.input, o.withHint);
         | 
| 824 | 
            +
                        $menu = this.$node.find(".tt-dropdown-menu");
         | 
| 825 | 
            +
                        $input = this.$node.find(".tt-input");
         | 
| 826 | 
            +
                        $hint = this.$node.find(".tt-hint");
         | 
| 827 | 
            +
                        this.eventBus = o.eventBus || new EventBus({
         | 
| 828 | 
            +
                            el: $input
         | 
| 829 | 
            +
                        });
         | 
| 830 | 
            +
                        this.dropdown = new Dropdown({
         | 
| 831 | 
            +
                            menu: $menu,
         | 
| 832 | 
            +
                            datasets: o.datasets
         | 
| 833 | 
            +
                        }).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);
         | 
| 834 | 
            +
                        this.input = new Input({
         | 
| 835 | 
            +
                            input: $input,
         | 
| 836 | 
            +
                            hint: $hint
         | 
| 837 | 
            +
                        }).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);
         | 
| 838 | 
            +
                        $menu.on("mousedown.tt", function($e) {
         | 
| 839 | 
            +
                            if (_.isMsie() && _.isMsie() < 9) {
         | 
| 840 | 
            +
                                $input[0].onbeforedeactivate = function() {
         | 
| 841 | 
            +
                                    window.event.returnValue = false;
         | 
| 842 | 
            +
                                    $input[0].onbeforedeactivate = null;
         | 
| 843 | 
            +
                                };
         | 
| 844 | 
            +
                            }
         | 
| 845 | 
            +
                            $e.preventDefault();
         | 
| 846 | 
            +
                        });
         | 
| 847 | 
            +
                    }
         | 
| 848 | 
            +
                    _.mixin(Typeahead.prototype, {
         | 
| 849 | 
            +
                        _onSuggestionClicked: function onSuggestionClicked(type, $el) {
         | 
| 850 | 
            +
                            var datum;
         | 
| 851 | 
            +
                            if (datum = this.dropdown.getDatumForSuggestion($el)) {
         | 
| 852 | 
            +
                                this._select(datum);
         | 
| 853 | 
            +
                            }
         | 
| 854 | 
            +
                        },
         | 
| 855 | 
            +
                        _onCursorMoved: function onCursorMoved() {
         | 
| 856 | 
            +
                            var datum = this.dropdown.getDatumForCursor();
         | 
| 857 | 
            +
                            this.input.clearHint();
         | 
| 858 | 
            +
                            this.input.setInputValue(datum.value, true);
         | 
| 859 | 
            +
                            this.eventBus.trigger("cursorchanged", datum.raw, datum.datasetName);
         | 
| 860 | 
            +
                        },
         | 
| 861 | 
            +
                        _onCursorRemoved: function onCursorRemoved() {
         | 
| 862 | 
            +
                            this.input.resetInputValue();
         | 
| 863 | 
            +
                            this._updateHint();
         | 
| 864 | 
            +
                        },
         | 
| 865 | 
            +
                        _onDatasetRendered: function onDatasetRendered() {
         | 
| 866 | 
            +
                            this._updateHint();
         | 
| 867 | 
            +
                        },
         | 
| 868 | 
            +
                        _onOpened: function onOpened() {
         | 
| 869 | 
            +
                            this._updateHint();
         | 
| 870 | 
            +
                            this.eventBus.trigger("opened");
         | 
| 871 | 
            +
                        },
         | 
| 872 | 
            +
                        _onClosed: function onClosed() {
         | 
| 873 | 
            +
                            this.input.clearHint();
         | 
| 874 | 
            +
                            this.eventBus.trigger("closed");
         | 
| 875 | 
            +
                        },
         | 
| 876 | 
            +
                        _onFocused: function onFocused() {
         | 
| 877 | 
            +
                            this.dropdown.empty();
         | 
| 878 | 
            +
                            this.dropdown.open();
         | 
| 879 | 
            +
                        },
         | 
| 880 | 
            +
                        _onBlurred: function onBlurred() {
         | 
| 881 | 
            +
                            this.dropdown.close();
         | 
| 882 | 
            +
                        },
         | 
| 883 | 
            +
                        _onEnterKeyed: function onEnterKeyed(type, $e) {
         | 
| 884 | 
            +
                            var cursorDatum, topSuggestionDatum;
         | 
| 885 | 
            +
                            cursorDatum = this.dropdown.getDatumForCursor();
         | 
| 886 | 
            +
                            topSuggestionDatum = this.dropdown.getDatumForTopSuggestion();
         | 
| 887 | 
            +
                            if (cursorDatum) {
         | 
| 888 | 
            +
                                this._select(cursorDatum);
         | 
| 889 | 
            +
                                $e.preventDefault();
         | 
| 890 | 
            +
                            } else if (this.autoselect && topSuggestionDatum) {
         | 
| 891 | 
            +
                                this._select(topSuggestionDatum);
         | 
| 892 | 
            +
                                $e.preventDefault();
         | 
| 893 | 
            +
                            }
         | 
| 894 | 
            +
                        },
         | 
| 895 | 
            +
                        _onTabKeyed: function onTabKeyed(type, $e) {
         | 
| 896 | 
            +
                            var datum;
         | 
| 897 | 
            +
                            if (datum = this.dropdown.getDatumForCursor()) {
         | 
| 898 | 
            +
                                this._select(datum);
         | 
| 899 | 
            +
                                $e.preventDefault();
         | 
| 900 | 
            +
                            } else {
         | 
| 901 | 
            +
                                this._autocomplete();
         | 
| 902 | 
            +
                            }
         | 
| 903 | 
            +
                        },
         | 
| 904 | 
            +
                        _onEscKeyed: function onEscKeyed() {
         | 
| 905 | 
            +
                            this.dropdown.close();
         | 
| 906 | 
            +
                            this.input.resetInputValue();
         | 
| 907 | 
            +
                        },
         | 
| 908 | 
            +
                        _onUpKeyed: function onUpKeyed() {
         | 
| 909 | 
            +
                            var query = this.input.getQuery();
         | 
| 910 | 
            +
                            if (!this.dropdown.isOpen && query.length >= this.minLength) {
         | 
| 911 | 
            +
                                this.dropdown.update(query);
         | 
| 912 | 
            +
                            }
         | 
| 913 | 
            +
                            this.dropdown.open();
         | 
| 914 | 
            +
                            this.dropdown.moveCursorUp();
         | 
| 915 | 
            +
                        },
         | 
| 916 | 
            +
                        _onDownKeyed: function onDownKeyed() {
         | 
| 917 | 
            +
                            var query = this.input.getQuery();
         | 
| 918 | 
            +
                            if (!this.dropdown.isOpen && query.length >= this.minLength) {
         | 
| 919 | 
            +
                                this.dropdown.update(query);
         | 
| 920 | 
            +
                            }
         | 
| 921 | 
            +
                            this.dropdown.open();
         | 
| 922 | 
            +
                            this.dropdown.moveCursorDown();
         | 
| 923 | 
            +
                        },
         | 
| 924 | 
            +
                        _onLeftKeyed: function onLeftKeyed() {
         | 
| 925 | 
            +
                            this.dir === "rtl" && this._autocomplete();
         | 
| 926 | 
            +
                        },
         | 
| 927 | 
            +
                        _onRightKeyed: function onRightKeyed() {
         | 
| 928 | 
            +
                            this.dir === "ltr" && this._autocomplete();
         | 
| 929 | 
            +
                        },
         | 
| 930 | 
            +
                        _onQueryChanged: function onQueryChanged(e, query) {
         | 
| 931 | 
            +
                            this.input.clearHint();
         | 
| 932 | 
            +
                            this.dropdown.empty();
         | 
| 933 | 
            +
                            query.length >= this.minLength && this.dropdown.update(query);
         | 
| 934 | 
            +
                            this.dropdown.open();
         | 
| 935 | 
            +
                            this._setLanguageDirection();
         | 
| 936 | 
            +
                        },
         | 
| 937 | 
            +
                        _onWhitespaceChanged: function onWhitespaceChanged() {
         | 
| 938 | 
            +
                            this._updateHint();
         | 
| 939 | 
            +
                            this.dropdown.open();
         | 
| 940 | 
            +
                        },
         | 
| 941 | 
            +
                        _setLanguageDirection: function setLanguageDirection() {
         | 
| 942 | 
            +
                            var dir;
         | 
| 943 | 
            +
                            if (this.dir !== (dir = this.input.getLanguageDirection())) {
         | 
| 944 | 
            +
                                this.dir = dir;
         | 
| 945 | 
            +
                                this.$node.css("direction", dir);
         | 
| 946 | 
            +
                                this.dropdown.setLanguageDirection(dir);
         | 
| 947 | 
            +
                            }
         | 
| 948 | 
            +
                        },
         | 
| 949 | 
            +
                        _updateHint: function updateHint() {
         | 
| 950 | 
            +
                            var datum, inputValue, query, escapedQuery, frontMatchRegEx, match;
         | 
| 951 | 
            +
                            datum = this.dropdown.getDatumForTopSuggestion();
         | 
| 952 | 
            +
                            if (datum && this.dropdown.isVisible() && !this.input.hasOverflow()) {
         | 
| 953 | 
            +
                                inputValue = this.input.getInputValue();
         | 
| 954 | 
            +
                                query = Input.normalizeQuery(inputValue);
         | 
| 955 | 
            +
                                escapedQuery = _.escapeRegExChars(query);
         | 
| 956 | 
            +
                                frontMatchRegEx = new RegExp("^(?:" + escapedQuery + ")(.*$)", "i");
         | 
| 957 | 
            +
                                match = frontMatchRegEx.exec(datum.value);
         | 
| 958 | 
            +
                                this.input.setHintValue(inputValue + (match ? match[1] : ""));
         | 
| 959 | 
            +
                            }
         | 
| 960 | 
            +
                        },
         | 
| 961 | 
            +
                        _autocomplete: function autocomplete() {
         | 
| 962 | 
            +
                            var hint, query, datum;
         | 
| 963 | 
            +
                            hint = this.input.getHintValue();
         | 
| 964 | 
            +
                            query = this.input.getQuery();
         | 
| 965 | 
            +
                            if (hint && query !== hint && this.input.isCursorAtEnd()) {
         | 
| 966 | 
            +
                                datum = this.dropdown.getDatumForTopSuggestion();
         | 
| 967 | 
            +
                                datum && this.input.setInputValue(datum.value);
         | 
| 968 | 
            +
                                this.eventBus.trigger("autocompleted", datum.raw, datum.datasetName);
         | 
| 969 | 
            +
                            }
         | 
| 970 | 
            +
                        },
         | 
| 971 | 
            +
                        _select: function select(datum) {
         | 
| 972 | 
            +
                            this.input.clearHint();
         | 
| 973 | 
            +
                            this.input.setQuery(datum.value);
         | 
| 974 | 
            +
                            this.input.setInputValue(datum.value, true);
         | 
| 975 | 
            +
                            this._setLanguageDirection();
         | 
| 976 | 
            +
                            this.eventBus.trigger("selected", datum.raw, datum.datasetName);
         | 
| 977 | 
            +
                            this.dropdown.close();
         | 
| 978 | 
            +
                            _.defer(_.bind(this.dropdown.empty, this.dropdown));
         | 
| 979 | 
            +
                        },
         | 
| 980 | 
            +
                        open: function open() {
         | 
| 981 | 
            +
                            this.dropdown.open();
         | 
| 982 | 
            +
                        },
         | 
| 983 | 
            +
                        close: function close() {
         | 
| 984 | 
            +
                            this.dropdown.close();
         | 
| 985 | 
            +
                        },
         | 
| 986 | 
            +
                        getQuery: function getQuery() {
         | 
| 987 | 
            +
                            return this.input.getQuery();
         | 
| 988 | 
            +
                        },
         | 
| 989 | 
            +
                        setQuery: function setQuery(val) {
         | 
| 990 | 
            +
                            this.input.setInputValue(val);
         | 
| 991 | 
            +
                        },
         | 
| 992 | 
            +
                        destroy: function destroy() {
         | 
| 993 | 
            +
                            this.input.destroy();
         | 
| 994 | 
            +
                            this.dropdown.destroy();
         | 
| 995 | 
            +
                            destroyDomStructure(this.$node);
         | 
| 996 | 
            +
                            this.$node = null;
         | 
| 997 | 
            +
                        }
         | 
| 998 | 
            +
                    });
         | 
| 999 | 
            +
                    return Typeahead;
         | 
| 1000 | 
            +
                    function buildDomStructure(input, withHint) {
         | 
| 1001 | 
            +
                        var $input, $wrapper, $dropdown, $hint;
         | 
| 1002 | 
            +
                        $input = $(input);
         | 
| 1003 | 
            +
                        $wrapper = $(html.wrapper).css(css.wrapper);
         | 
| 1004 | 
            +
                        $dropdown = $(html.dropdown).css(css.dropdown);
         | 
| 1005 | 
            +
                        $hint = $input.clone().css(css.hint).css(getBackgroundStyles($input));
         | 
| 1006 | 
            +
                        $hint.val("").removeData().addClass("tt-hint").removeAttr("id name placeholder").prop("disabled", true).attr({
         | 
| 1007 | 
            +
                            autocomplete: "off",
         | 
| 1008 | 
            +
                            spellcheck: "false"
         | 
| 1009 | 
            +
                        });
         | 
| 1010 | 
            +
                        $input.data(attrsKey, {
         | 
| 1011 | 
            +
                            dir: $input.attr("dir"),
         | 
| 1012 | 
            +
                            autocomplete: $input.attr("autocomplete"),
         | 
| 1013 | 
            +
                            spellcheck: $input.attr("spellcheck"),
         | 
| 1014 | 
            +
                            style: $input.attr("style")
         | 
| 1015 | 
            +
                        });
         | 
| 1016 | 
            +
                        $input.addClass("tt-input").attr({
         | 
| 1017 | 
            +
                            autocomplete: "off",
         | 
| 1018 | 
            +
                            spellcheck: false
         | 
| 1019 | 
            +
                        }).css(withHint ? css.input : css.inputWithNoHint);
         | 
| 1020 | 
            +
                        try {
         | 
| 1021 | 
            +
                            !$input.attr("dir") && $input.attr("dir", "auto");
         | 
| 1022 | 
            +
                        } catch (e) {}
         | 
| 1023 | 
            +
                        return $input.wrap($wrapper).parent().prepend(withHint ? $hint : null).append($dropdown);
         | 
| 1024 | 
            +
                    }
         | 
| 1025 | 
            +
                    function getBackgroundStyles($el) {
         | 
| 1026 | 
            +
                        return {
         | 
| 1027 | 
            +
                            backgroundAttachment: $el.css("background-attachment"),
         | 
| 1028 | 
            +
                            backgroundClip: $el.css("background-clip"),
         | 
| 1029 | 
            +
                            backgroundColor: $el.css("background-color"),
         | 
| 1030 | 
            +
                            backgroundImage: $el.css("background-image"),
         | 
| 1031 | 
            +
                            backgroundOrigin: $el.css("background-origin"),
         | 
| 1032 | 
            +
                            backgroundPosition: $el.css("background-position"),
         | 
| 1033 | 
            +
                            backgroundRepeat: $el.css("background-repeat"),
         | 
| 1034 | 
            +
                            backgroundSize: $el.css("background-size")
         | 
| 1035 | 
            +
                        };
         | 
| 1036 | 
            +
                    }
         | 
| 1037 | 
            +
                    function destroyDomStructure($node) {
         | 
| 1038 | 
            +
                        var $input = $node.find(".tt-input");
         | 
| 1039 | 
            +
                        _.each($input.data(attrsKey), function(val, key) {
         | 
| 1040 | 
            +
                            _.isUndefined(val) ? $input.removeAttr(key) : $input.attr(key, val);
         | 
| 1041 | 
            +
                        });
         | 
| 1042 | 
            +
                        $input.detach().removeData(attrsKey).removeClass("tt-input").insertAfter($node);
         | 
| 1043 | 
            +
                        $node.remove();
         | 
| 1044 | 
            +
                    }
         | 
| 1045 | 
            +
                }();
         | 
| 1046 | 
            +
                (function() {
         | 
| 1047 | 
            +
                    var old, typeaheadKey, methods;
         | 
| 1048 | 
            +
                    old = $.fn.typeahead;
         | 
| 1049 | 
            +
                    typeaheadKey = "ttTypeahead";
         | 
| 1050 | 
            +
                    methods = {
         | 
| 1051 | 
            +
                        initialize: function initialize(o, datasets) {
         | 
| 1052 | 
            +
                            datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
         | 
| 1053 | 
            +
                            o = o || {};
         | 
| 1054 | 
            +
                            return this.each(attach);
         | 
| 1055 | 
            +
                            function attach() {
         | 
| 1056 | 
            +
                                var $input = $(this), eventBus, typeahead;
         | 
| 1057 | 
            +
                                _.each(datasets, function(d) {
         | 
| 1058 | 
            +
                                    d.highlight = !!o.highlight;
         | 
| 1059 | 
            +
                                });
         | 
| 1060 | 
            +
                                typeahead = new Typeahead({
         | 
| 1061 | 
            +
                                    input: $input,
         | 
| 1062 | 
            +
                                    eventBus: eventBus = new EventBus({
         | 
| 1063 | 
            +
                                        el: $input
         | 
| 1064 | 
            +
                                    }),
         | 
| 1065 | 
            +
                                    withHint: _.isUndefined(o.hint) ? true : !!o.hint,
         | 
| 1066 | 
            +
                                    minLength: o.minLength,
         | 
| 1067 | 
            +
                                    autoselect: o.autoselect,
         | 
| 1068 | 
            +
                                    datasets: datasets
         | 
| 1069 | 
            +
                                });
         | 
| 1070 | 
            +
                                $input.data(typeaheadKey, typeahead);
         | 
| 1071 | 
            +
                            }
         | 
| 1072 | 
            +
                        },
         | 
| 1073 | 
            +
                        open: function open() {
         | 
| 1074 | 
            +
                            return this.each(openTypeahead);
         | 
| 1075 | 
            +
                            function openTypeahead() {
         | 
| 1076 | 
            +
                                var $input = $(this), typeahead;
         | 
| 1077 | 
            +
                                if (typeahead = $input.data(typeaheadKey)) {
         | 
| 1078 | 
            +
                                    typeahead.open();
         | 
| 1079 | 
            +
                                }
         | 
| 1080 | 
            +
                            }
         | 
| 1081 | 
            +
                        },
         | 
| 1082 | 
            +
                        close: function close() {
         | 
| 1083 | 
            +
                            return this.each(closeTypeahead);
         | 
| 1084 | 
            +
                            function closeTypeahead() {
         | 
| 1085 | 
            +
                                var $input = $(this), typeahead;
         | 
| 1086 | 
            +
                                if (typeahead = $input.data(typeaheadKey)) {
         | 
| 1087 | 
            +
                                    typeahead.close();
         | 
| 1088 | 
            +
                                }
         | 
| 1089 | 
            +
                            }
         | 
| 1090 | 
            +
                        },
         | 
| 1091 | 
            +
                        val: function val(newVal) {
         | 
| 1092 | 
            +
                            return !arguments.length ? getQuery(this.first()) : this.each(setQuery);
         | 
| 1093 | 
            +
                            function setQuery() {
         | 
| 1094 | 
            +
                                var $input = $(this), typeahead;
         | 
| 1095 | 
            +
                                if (typeahead = $input.data(typeaheadKey)) {
         | 
| 1096 | 
            +
                                    typeahead.setQuery(newVal);
         | 
| 1097 | 
            +
                                }
         | 
| 1098 | 
            +
                            }
         | 
| 1099 | 
            +
                            function getQuery($input) {
         | 
| 1100 | 
            +
                                var typeahead, query;
         | 
| 1101 | 
            +
                                if (typeahead = $input.data(typeaheadKey)) {
         | 
| 1102 | 
            +
                                    query = typeahead.getQuery();
         | 
| 1103 | 
            +
                                }
         | 
| 1104 | 
            +
                                return query;
         | 
| 1105 | 
            +
                            }
         | 
| 1106 | 
            +
                        },
         | 
| 1107 | 
            +
                        destroy: function destroy() {
         | 
| 1108 | 
            +
                            return this.each(unattach);
         | 
| 1109 | 
            +
                            function unattach() {
         | 
| 1110 | 
            +
                                var $input = $(this), typeahead;
         | 
| 1111 | 
            +
                                if (typeahead = $input.data(typeaheadKey)) {
         | 
| 1112 | 
            +
                                    typeahead.destroy();
         | 
| 1113 | 
            +
                                    $input.removeData(typeaheadKey);
         | 
| 1114 | 
            +
                                }
         | 
| 1115 | 
            +
                            }
         | 
| 1116 | 
            +
                        }
         | 
| 1117 | 
            +
                    };
         | 
| 1118 | 
            +
                    $.fn.typeahead = function(method) {
         | 
| 1119 | 
            +
                        if (methods[method]) {
         | 
| 1120 | 
            +
                            return methods[method].apply(this, [].slice.call(arguments, 1));
         | 
| 1121 | 
            +
                        } else {
         | 
| 1122 | 
            +
                            return methods.initialize.apply(this, arguments);
         | 
| 1123 | 
            +
                        }
         | 
| 1124 | 
            +
                    };
         | 
| 1125 | 
            +
                    $.fn.typeahead.noConflict = function noConflict() {
         | 
| 1126 | 
            +
                        $.fn.typeahead = old;
         | 
| 1127 | 
            +
                        return this;
         | 
| 1128 | 
            +
                    };
         | 
| 1129 | 
            +
                })();
         | 
| 1130 | 
            +
            })(window.jQuery);
         |