|
|
/*! * # Semantic UI 1.11.5 - Dropdown * http://github.com/semantic-org/semantic-ui/
* * * Copyright 2014 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !function(e,t,n,i){"use strict";e.fn.dropdown=function(o){var a,r=e(this),s=e(n),l=r.selector||"",c="ontouchstart"in n.documentElement,u=(new Date).getTime(),d=[],v=arguments[0],f="string"==typeof v,m=[].slice.call(arguments,1);return r.each(function(){var h,g,p,b,w,y=e.isPlainObject(o)?e.extend(!0,{},e.fn.dropdown.settings,o):e.extend({},e.fn.dropdown.settings),x=y.className,C=y.metadata,T=y.namespace,S=y.selector,k=y.error,A=y.templates,I="."+T,E="module-"+T,D=e(this),V=D.find(S.text),F=D.find(S.search),M=D.find(S.input),O=D.find(S.icon),q=D.prev().find(S.text).length>0?D.prev().find(S.text):D.prev(),R=D.children(S.menu),P=R.find(S.item),j=!1,z=!1,L=this,K=D.data(E);w={initialize:function(){w.debug("Initializing dropdown",y),w.is.alreadySetup()?w.setup.reference():(w.setup.layout(),w.save.defaults(),w.set.selected(),w.create.id(),c&&w.bind.touchEvents(),w.bind.mouseEvents(),w.bind.keyboardEvents(),w.observeChanges(),w.instantiate())},instantiate:function(){w.verbose("Storing instance of dropdown",w),K=w,D.data(E,w)},destroy:function(){w.verbose("Destroying previous dropdown for",D),w.remove.tabbable(),D.off(I).removeData(E),R.off(I),s.off(h),p&&p.disconnect(),b&&b.disconnect()},observeChanges:function(){"MutationObserver"in t&&(p=new MutationObserver(function(){w.debug("<select> modified, recreating menu"),w.setup.select()}),b=new MutationObserver(function(){w.debug("Menu modified, updating selector cache"),w.refresh()}),w.has.input()&&p.observe(M[0],{childList:!0,subtree:!0}),w.has.menu()&&b.observe(R[0],{childList:!0,subtree:!0}),w.debug("Setting up mutation observer",p,b))},create:{id:function(){g=(Math.random().toString(16)+"000000000").substr(2,8),h="."+g,w.verbose("Creating unique id for element",g)}},search:function(){var e;e=F.val(),w.verbose("Searching for query",e),w.filter(e),w.is.searchSelection()&&w.can.show()&&w.show()},setup:{layout:function(){D.is("select")&&w.setup.select(),w.is.search()&&!w.has.search()&&(F=e("<input />").addClass(x.search).insertBefore(V)),y.allowTab&&w.set.tabbable()},select:function(){var t=w.get.selectValues();w.debug("Dropdown initialized on a select",t),D.is("select")&&(M=D),M.parent(S.dropdown).length>0?(w.debug("UI dropdown already exists. Creating dropdown menu only"),D=M.closest(S.dropdown),R=D.children(S.menu),0===R.length&&(R=e("<div />").addClass(x.menu).appendTo(D)),R.html(A.menu(t))):(w.debug("Creating entire dropdown from select"),D=e("<div />").attr("class",M.attr("class")).addClass(x.selection).addClass(x.dropdown).html(A.dropdown(t)).insertBefore(M),M.removeAttr("class").prependTo(D)),M.is("[multiple]")&&w.set.multiple(),w.refresh()},reference:function(){var e,t,n=r.index(D);w.debug("Dropdown behavior was called on select, replacing with closest dropdown"),D=D.parent(S.dropdown),w.refresh(),e=r.slice(0,n),t=r.slice(n+1),r=e.add(D).add(t)}},refresh:function(){w.verbose("Refreshing selector cache"),V=D.find(S.text),F=D.find(S.search),M=D.find(S.input),O=D.find(S.icon),q=D.prev().find(S.text).length>0?D.prev().find(S.text):D.prev(),R=D.children(S.menu),P=R.find(S.item)},toggle:function(){w.verbose("Toggling menu visibility"),w.is.active()?w.hide():w.show()},show:function(t){t=e.isFunction(t)?t:function(){},w.is.searchSelection()&&w.is.allFiltered()||w.can.show()&&!w.is.active()&&(w.debug("Showing dropdown"),w.is.multiple()&&w.filterActive(),w.animate.show(function(){w.can.click()&&w.bind.intent(),w.set.visible(),t.call(L)}),y.onShow.call(L))},hide:function(t){t=e.isFunction(t)?t:function(){},w.is.active()&&(w.debug("Hiding dropdown"),w.animate.hide(function(){w.remove.visible(),t.call(L)}),y.onHide.call(L))},hideOthers:function(){w.verbose("Finding other dropdowns to hide"),r.not(D).has(S.menu+":visible:not(."+x.animating+")").dropdown("hide")},hideSubMenus:function(){var e=R.find(S.menu);e.transition("hide")},bind:{keyboardEvents:function(){w.debug("Binding keyboard events"),D.on("keydown"+I,w.event.keydown),w.has.search()&&D.on(w.get.inputEvent()+I,S.search,w.event.input),w.is.multiple()&&s.on("keydown"+h,w.event.document.keydown)},touchEvents:function(){w.debug("To
|