"+displayFn(context)+"
"}}(o.templates,this.displayFn),this.$el=$(html.dataset.replace("%CLASS%",this.name))}return Dataset.extractDatasetName=function(el){return $(el).data("ttDataset")},Dataset.extractValue=function(el){return $(el).data("ttValue")},Dataset.extractDatum=function(el){return $(el).data("ttDatum")},_.mixin(Dataset.prototype,EventEmitter,{_render:function(query,suggestions){if(this.$el){var hasSuggestions,that=this;this.$el.empty(),!(hasSuggestions=suggestions&&suggestions.length)&&this.templates.empty?this.$el.html(that.templates.empty({query:query,isEmpty:!0})).prepend(that.templates.header?getHeaderHtml():null).append(that.templates.footer?getFooterHtml():null):hasSuggestions&&this.$el.html(function(){var $suggestions,nodes;return $suggestions=$(html.suggestions).css(css.suggestions),nodes=_.map(suggestions,getSuggestionNode),$suggestions.append.apply($suggestions,nodes),that.highlight&&highlight({className:"tt-highlight",node:$suggestions[0],pattern:query}),$suggestions;function getSuggestionNode(suggestion){var $el;return($el=$(html.suggestion).append(that.templates.suggestion(suggestion)).data("ttDataset",that.name).data("ttValue",that.displayFn(suggestion)).data("ttDatum",suggestion)).children().each((function(){$(this).css(css.suggestionChild)})),$el}}()).prepend(that.templates.header?getHeaderHtml():null).append(that.templates.footer?getFooterHtml():null),this.trigger("rendered")}function getHeaderHtml(){return that.templates.header({query:query,isEmpty:!hasSuggestions})}function getFooterHtml(){return that.templates.footer({query:query,isEmpty:!hasSuggestions})}},getRoot:function(){return this.$el},update:function(query){var that=this;this.query=query,this.canceled=!1,this.source(query,(function(suggestions){that.canceled||query!==that.query||that._render(query,suggestions)}))},cancel:function(){this.canceled=!0},clear:function(){this.cancel(),this.$el.empty(),this.trigger("rendered")},isEmpty:function(){return this.$el.is(":empty")},destroy:function(){this.$el=null}}),Dataset}(),Dropdown=function(){"use strict";function Dropdown(o){var onSuggestionClick,onSuggestionMouseEnter,onSuggestionMouseLeave,that=this;(o=o||{}).menu||$.error("menu is required"),this.isOpen=!1,this.isEmpty=!0,this.datasets=_.map(o.datasets,initializeDataset),onSuggestionClick=_.bind(this._onSuggestionClick,this),onSuggestionMouseEnter=_.bind(this._onSuggestionMouseEnter,this),onSuggestionMouseLeave=_.bind(this._onSuggestionMouseLeave,this),this.$menu=$(o.menu).on("click.tt",".tt-suggestion",onSuggestionClick).on("mouseenter.tt",".tt-suggestion",onSuggestionMouseEnter).on("mouseleave.tt",".tt-suggestion",onSuggestionMouseLeave),_.each(this.datasets,(function(dataset){that.$menu.append(dataset.getRoot()),dataset.onSync("rendered",that._onRendered,that)}))}return _.mixin(Dropdown.prototype,EventEmitter,{_onSuggestionClick:function($e){this.trigger("suggestionClicked",$($e.currentTarget))},_onSuggestionMouseEnter:function($e){this._removeCursor(),this._setCursor($($e.currentTarget),!0)},_onSuggestionMouseLeave:function(){this._removeCursor()},_onRendered:function(){this.isEmpty=_.every(this.datasets,(function(dataset){return dataset.isEmpty()})),this.isEmpty?this._hide():this.isOpen&&this._show(),this.trigger("datasetRendered")},_hide:function(){this.$menu.hide()},_show:function(){this.$menu.css("display","block")},_getSuggestions:function(){return this.$menu.find(".tt-suggestion")},_getCursor:function(){return this.$menu.find(".tt-cursor").first()},_setCursor:function($el,silent){$el.first().addClass("tt-cursor"),!silent&&this.trigger("cursorMoved")},_removeCursor:function(){this._getCursor().removeClass("tt-cursor")},_moveCursor:function(increment){var $suggestions,$oldCursor,newCursorIndex,$newCursor;this.isOpen&&($oldCursor=this._getCursor(),$suggestions=this._getSuggestions(),this._removeCursor(),-1!==(newCursorIndex=((newCursorIndex=$suggestions.index($oldCursor)+increment)+1)%($suggestions.length+1)-1)?(newCursorIndex<-1&&(newCursorIndex=$suggestions.length-1),this._setCursor($newCursor=$suggestions.eq(newCursorIndex)),this._ensureVisible($newCursor)):this.trigger("cursorRemoved"))},_ensureVisible:function($el){var elTop,elBottom,menuScrollTop,menuHeight;elBottom=(elTop=$el.position().top)+$el.outerHeight(!0),menuScrollTop=this.$menu.scrollTop(),menuHeight=this.$menu.height()+parseInt(this.$menu.css("paddingTop"),10)+parseInt(this.$menu.css("paddingBottom"),10),elTop<0?this.$menu.scrollTop(menuScrollTop+elTop):menuHeight