/*!
* # Semantic UI 2.2.0 - Dropdown
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2015 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(e,t,n,i){"use strict";t="undefined"!=typeof t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.dropdown=function(a){var o,s=e(this),r=e(n),l=s.selector||"",c="ontouchstart"in n.documentElement,u=(new Date).getTime(),d=[],v=arguments[0],m="string"==typeof v,f=[].slice.call(arguments,1);return s.each(function(h){var g,p,b,w,x,C,y,S,A=e.isPlainObject(a)?e.extend(!0,{},e.fn.dropdown.settings,a):e.extend({},e.fn.dropdown.settings),T=A.className,k=A.message,L=A.fields,I=A.keys,D=A.metadata,q=A.namespace,R=A.regExp,O=A.selector,V=A.error,E=A.templates,M="."+q,F="module-"+q,z=e(this),P=e(A.context),H=z.find(O.text),j=z.find(O.search),N=z.find(O.sizer),U=z.find(O.input),K=z.find(O.icon),W=z.prev().find(O.text).length>0?z.prev().find(O.text):z.prev(),B=z.children(O.menu),$=B.find(O.item),Q=!1,Y=!1,G=!1,J=this,X=z.data(F);S={initialize:function(){S.debug("Initializing dropdown",A),S.is.alreadySetup()?S.setup.reference():(S.setup.layout(),S.refreshData(),S.save.defaults(),S.restore.selected(),S.create.id(),S.bind.events(),S.observeChanges(),S.instantiate())},instantiate:function(){S.verbose("Storing instance of dropdown",S),X=S,z.data(F,S)},destroy:function(){S.verbose("Destroying previous dropdown",z),S.remove.tabbable(),z.off(M).removeData(F),B.off(M),r.off(w),S.disconnect.menuObserver(),S.disconnect.selectObserver()},observeChanges:function(){"MutationObserver"in t&&(C=new MutationObserver(S.event.select.mutation),y=new MutationObserver(S.event.menu.mutation),S.debug("Setting up mutation observer",C,y),S.observe.select(),S.observe.menu())},disconnect:{menuObserver:function(){y&&y.disconnect()},selectObserver:function(){y&&y.disconnect()}},observe:{select:function(){S.has.input()&&C.observe(U[0],{childList:!0,subtree:!0})},menu:function(){S.has.menu()&&y.observe(B[0],{childList:!0,subtree:!0})}},create:{id:function(){x=(Math.random().toString(16)+"000000000").substr(2,8),w="."+x,S.verbose("Creating unique id for element",x)},userChoice:function(t){var n,a,o;return(t=t||S.get.userValues())?(t=e.isArray(t)?t:[t],e.each(t,function(t,s){S.get.item(s)===!1&&(o=A.templates.addition(S.add.variables(k.addResult,s)),a=e("
").html(o).attr("data-"+D.value,s).attr("data-"+D.text,s).addClass(T.addition).addClass(T.item),A.hideAdditions&&a.addClass(T.hidden),n=n===i?a:n.add(a),S.verbose("Creating user choices for value",s,a))}),n):!1},userLabels:function(t){var n=S.get.userValues();n&&(S.debug("Adding user labels",n),e.each(n,function(e,t){S.verbose("Adding custom user value"),S.add.label(t,t)}))},menu:function(){B=e("").addClass(T.menu).appendTo(z)},sizer:function(){N=e("").addClass(T.sizer).insertAfter(j)}},search:function(e){e=e!==i?e:S.get.query(),S.verbose("Searching for query",e),S.has.minCharacters(e)?S.filter(e):S.hide()},select:{firstUnfiltered:function(){S.verbose("Selecting first non-filtered element"),S.remove.selectedItem(),$.not(O.unselectable).not(O.addition+O.hidden).eq(0).addClass(T.selected)},nextAvailable:function(e){e=e.eq(0);var t=e.nextAll(O.item).not(O.unselectable).eq(0),n=e.prevAll(O.item).not(O.unselectable).eq(0),i=t.length>0;i?(S.verbose("Moving selection to",t),t.addClass(T.selected)):(S.verbose("Moving selection to",n),n.addClass(T.selected))}},setup:{api:function(){var e={debug:A.debug,urlData:{value:S.get.value(),query:S.get.query()},on:!1};S.verbose("First request, initializing API"),z.api(e)},layout:function(){z.is("select")&&(S.setup.select(),S.setup.returnedObject()),S.has.menu()||S.create.menu(),S.is.search()&&!S.has.search()&&(S.verbose("Adding search input"),j=e("").addClass(T.search).prop("autocomplete","off").insertBefore(H)),S.is.multiple()&&S.is.searchSelection()&&!S.has.sizer()&&S.create.sizer(),A.allowTab&&S.set.tabbable()},select:function(){var t=S.get.selectValues();S.debug("Dropdown initialized on a select",t),z.is("select")&&(U=z),U.parent(O.dropdown).length>0?(S.debug("UI dropdown already exists. Creating dropdown menu only"),z=U.closest(O.dropdown),S.has.menu()||S.create.menu(),B=z.children(O.menu),S.setup.menu(t)):(S.debug("Creating entire dropdown from select"),z=e("").attr("class",U.attr("class")).addClass(T.selection).addClass(T.dropdown).html(E.dropdown(t)).insertBefore(U),U.hasClass(T.multiple)&&U.prop("multiple")===!1&&(S.error(V.missingMultiple),U.prop("multiple",!0)),U.is("[multiple]")&&S.set.multiple(),U.prop("disabled")&&(S.debug("Disabling dropdown"),z.addClass(T.disabled)),U.removeAttr("class").detach().prependTo(z)),S.refresh()},menu:function(e){B.html(E.menu(e,L)),$=B.find(O.item)},reference:function(){S.debug("Dropdown behavior was called on select, replacing with closest dropdown"),z=z.parent(O.dropdown),S.refresh(),S.setup.returnedObject(),m&&(X=S,S.invoke(v))},returnedObject:function(){var e=s.slice(0,h),t=s.slice(h+1);s=e.add(z).add(t)}},refresh:function(){S.refreshSelectors(),S.refreshData()},refreshSelectors:function(){S.verbose("Refreshing selector cache"),H=z.find(O.text),j=z.find(O.search),U=z.find(O.input),K=z.find(O.icon),W=z.prev().find(O.text).length>0?z.prev().find(O.text):z.prev(),B=z.children(O.menu),$=B.find(O.item)},refreshData:function(){S.verbose("Refreshing cached metadata"),$.removeData(D.text).removeData(D.value)},clearData:function(){S.verbose("Clearing metadata"),$.removeData(D.text).removeData(D.value),z.removeData(D.defaultText).removeData(D.defaultValue).removeData(D.placeholderText)},toggle:function(){S.verbose("Toggling menu visibility"),S.is.active()?S.hide():S.show()},show:function(t){if(t=e.isFunction(t)?t:function(){},S.can.show()&&!S.is.active()){if(S.debug("Showing dropdown"),!S.has.message()||S.has.maxSelections()||S.has.allResultsFiltered()||S.remove.message(),S.is.allFiltered())return!0;A.onShow.call(J)!==!1&&S.animate.show(function(){S.can.click()&&S.bind.intent(),S.has.menuSearch()&&S.focusSearch(),S.set.visible(),t.call(J)})}},hide:function(t){t=e.isFunction(t)?t:function(){},S.is.active()&&(S.debug("Hiding dropdown"),A.onHide.call(J)!==!1&&S.animate.hide(function(){S.remove.visible(),t.call(J)}))},hideOthers:function(){S.verbose("Finding other dropdowns to hide"),s.not(z).has(O.menu+"."+T.visible).dropdown("hide")},hideMenu:function(){S.verbose("Hiding menu instantaneously"),S.remove.active(),S.remove.visible(),B.transition("hide")},hideSubMenus:function(){var e=B.children(O.item).find(O.menu);S.verbose("Hiding sub menus",e),e.transition("hide")},bind:{events:function(){c&&S.bind.touchEvents(),S.bind.keyboardEvents(),S.bind.inputEvents(),S.bind.mouseEvents()},touchEvents:function(){S.debug("Touch device detected binding additional touch events"),S.is.searchSelection()||S.is.single()&&z.on("touchstart"+M,S.event.test.toggle),B.on("touchstart"+M,O.item,S.event.item.mouseenter)},keyboardEvents:function(){S.verbose("Binding keyboard events"),z.on("keydown"+M,S.event.keydown),S.has.search()&&z.on(S.get.inputEvent()+M,O.search,S.event.input),S.is.multiple()&&r.on("keydown"+w,S.event.document.keydown)},inputEvents:function(){S.verbose("Binding input change events"),z.on("change"+M,O.input,S.event.change)},mouseEvents:function(){S.verbose("Binding mouse events"),S.is.multiple()&&z.on("click"+M,O.label,S.event.label.click).on("click"+M,O.remove,S.event.remove.click),S.is.searchSelection()?(z.on("mousedown"+M,S.event.mousedown).on("mouseup"+M,S.event.mouseup).on("mousedown"+M,O.menu,S.event.menu.mousedown).on("mouseup"+M,O.menu,S.event.menu.mouseup).on("click"+M,O.icon,S.event.icon.click).on("focus"+M,O.search,S.event.search.focus).on("click"+M,O.search,S.event.search.focus).on("blur"+M,O.search,S.event.search.blur).on("click"+M,O.text,S.event.text.focus),S.is.multiple()&&z.on("click"+M,S.event.click)):("click"==A.on?z.on("click"+M,O.icon,S.event.icon.click).on("click"+M,S.event.test.toggle):"hover"==A.on?z.on("mouseenter"+M,S.delay.show).on("mouseleave"+M,S.delay.hide):z.on(A.on+M,S.toggle),z.on("mousedown"+M,S.event.mousedown).on("mouseup"+M,S.event.mouseup).on("focus"+M,S.event.focus).on("blur"+M,S.event.blur)),B.on("mouseenter"+M,O.item,S.event.item.mouseenter).on("mouseleave"+M,O.item,S.event.item.mouseleave).on("click"+M,O.item,S.event.item.click)},intent:function(){S.verbose("Binding hide intent event to document"),c&&r.on("touchstart"+w,S.event.test.touch).on("touchmove"+w,S.event.test.touch),r.on("click"+w,S.event.test.hide)}},unbind:{intent:function(){S.verbose("Removing hide intent event from document"),c&&r.off("touchstart"+w).off("touchmove"+w),r.off("click"+w)}},filter:function(e){var t=e!==i?e:S.get.query(),n=function(){S.is.multiple()&&S.filterActive(),S.select.firstUnfiltered(),S.has.allResultsFiltered()?A.onNoResults.call(J,t)?A.allowAdditions?A.hideAdditions&&(S.verbose("User addition with no menu, setting empty style"),S.set.empty(),S.hideMenu()):(S.verbose("All items filtered, showing message",t),S.add.message(k.noResults)):(S.verbose("All items filtered, hiding dropdown",t),S.hideMenu()):(S.remove.empty(),S.remove.message()),A.allowAdditions&&S.add.userSuggestion(e),S.is.searchSelection()&&S.can.show()&&S.is.focusedOnSearch()&&S.show()};A.useLabels&&S.has.maxSelections()||(A.apiSettings?S.can.useAPI()?S.queryRemote(t,function(){n()}):S.error(V.noAPI):(S.filterItems(t),n()))},queryRemote:function(t,n){var i={errorDuration:!1,cache:"local",throttle:A.throttle,urlData:{query:t},onError:function(){S.add.message(k.serverError),n()},onFailure:function(){S.add.message(k.serverError),n()},onSuccess:function(e){S.remove.message(),S.setup.menu({values:e[L.remoteValues]}),n()}};z.api("get request")||S.setup.api(),i=e.extend(!0,{},i,A.apiSettings),z.api("setting",i).api("query")},filterItems:function(t){var n=t!==i?t:S.get.query(),a=null,o=S.escape.regExp(n),s=new RegExp("^"+o,"igm");S.has.query()&&(a=[],S.verbose("Searching for matching values",n),$.each(function(){var t,i,o=e(this);if("both"==A.match||"text"==A.match){if(t=String(S.get.choiceText(o,!1)),-1!==t.search(s))return a.push(this),!0;if(A.fullTextSearch&&S.fuzzySearch(n,t))return a.push(this),!0}if("both"==A.match||"value"==A.match){if(i=String(S.get.choiceValue(o,t)),-1!==i.search(s))return a.push(this),!0;if(A.fullTextSearch&&S.fuzzySearch(n,i))return a.push(this),!0}})),S.debug("Showing only matched items",n),S.remove.filteredItem(),a&&$.not(a).addClass(T.filtered)},fuzzySearch:function(e,t){var n=t.length,i=e.length;if(e=e.toLowerCase(),t=t.toLowerCase(),i>n)return!1;if(i===n)return e===t;e:for(var a=0,o=0;i>a;a++){for(var s=e.charCodeAt(a);n>o;)if(t.charCodeAt(o++)===s)continue e;return!1}return!0},filterActive:function(){A.useLabels&&$.filter("."+T.active).addClass(T.filtered)},focusSearch:function(e){S.has.search()&&!S.is.focusedOnSearch()&&(e?(z.off("focus"+M,O.search),j.focus(),z.on("focus"+M,O.search,S.event.search.focus)):j.focus())},forceSelection:function(){var e=$.not(T.filtered).filter("."+T.selected).eq(0),t=$.not(T.filtered).filter("."+T.active).eq(0),n=e.length>0?e:t,i=n.size()>0;return i?(S.debug("Forcing partial selection to selected item",n),void S.event.item.click.call(n,{},!0)):void(A.allowAdditions?(S.set.selected(S.get.query()),S.remove.searchTerm()):S.remove.searchTerm())},event:{change:function(){G||(S.debug("Input changed, updating selection"),S.set.selected())},focus:function(){A.showOnFocus&&!Q&&S.is.hidden()&&!p&&S.show()},blur:function(e){p=n.activeElement===this,Q||p||(S.remove.activeLabel(),S.hide())},mousedown:function(){S.is.searchSelection()?b=!0:Q=!0},mouseup:function(){S.is.searchSelection()?b=!1:Q=!1},click:function(t){var n=e(t.target);n.is(z)&&(S.is.focusedOnSearch()?S.show():S.focusSearch())},search:{focus:function(){Q=!0,S.is.multiple()&&S.remove.activeLabel(),A.showOnFocus&&S.search()},blur:function(e){p=n.activeElement===this,b||Y||p||(A.forceSelection&&S.has.query()&&S.forceSelection(),S.hide()),b=!1}},icon:{click:function(e){S.toggle(),e.stopPropagation()}},text:{focus:function(e){Q=!0,S.focusSearch()}},input:function(e){(S.is.multiple()||S.is.searchSelection())&&S.set.filtered(),clearTimeout(S.timer),S.timer=setTimeout(S.search,A.delay.search)},label:{click:function(t){var n=e(this),i=z.find(O.label),a=i.filter("."+T.active),o=n.nextAll("."+T.active),s=n.prevAll("."+T.active),r=o.length>0?n.nextUntil(o).add(a).add(n):n.prevUntil(s).add(a).add(n);t.shiftKey?(a.removeClass(T.active),r.addClass(T.active)):t.ctrlKey?n.toggleClass(T.active):(a.removeClass(T.active),n.addClass(T.active)),A.onLabelSelect.apply(this,i.filter("."+T.active))}},remove:{click:function(){var t=e(this).parent();t.hasClass(T.active)?S.remove.activeLabels():S.remove.activeLabels(t)}},test:{toggle:function(e){var t=S.is.multiple()?S.show:S.toggle;S.is.bubbledLabelClick(e)||S.determine.eventOnElement(e,t)&&e.preventDefault()},touch:function(e){S.determine.eventOnElement(e,function(){"touchstart"==e.type?S.timer=setTimeout(function(){S.hide()},A.delay.touch):"touchmove"==e.type&&clearTimeout(S.timer)}),e.stopPropagation()},hide:function(e){S.determine.eventInModule(e,S.hide)}},select:{mutation:function(e){S.debug("