|
|
/*! * # Semantic UI 2.0.0 - 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),l=e(n),s=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,x=e.isPlainObject(o)?e.extend(!0,{},e.fn.dropdown.settings,o):e.extend({},e.fn.dropdown.settings),y=x.className,C=x.metadata,T=x.namespace,S=x.selector,k=x.error,A=x.templates,E="."+T,D="module-"+T,I=e(this),O=I.find(S.text),F=I.find(S.search),V=I.find(S.input),R=I.find(S.icon),q=I.prev().find(S.text).length>0?I.prev().find(S.text):I.prev(),M=I.children(S.menu),P=M.find(S.item),z=!1,L=!1,j=this,H=I.data(D);w={initialize:function(){w.debug("Initializing dropdown",x),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),H=w,I.data(D,w)},destroy:function(){w.verbose("Destroying previous dropdown for",I),w.remove.tabbable(),I.off(E).removeData(D),M.off(E),l.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(V[0],{childList:!0,subtree:!0}),w.has.menu()&&b.observe(M[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(){I.is("select")&&w.setup.select(),w.is.search()&&!w.has.search()&&(F=e("<input />").addClass(y.search).insertBefore(O)),x.allowTab&&w.set.tabbable()},select:function(){var t=w.get.selectValues();w.debug("Dropdown initialized on a select",t),I.is("select")&&(V=I),V.parent(S.dropdown).length>0?(w.debug("UI dropdown already exists. Creating dropdown menu only"),I=V.closest(S.dropdown),M=I.children(S.menu),0===M.length&&(M=e("<div />").addClass(y.menu).appendTo(I)),M.html(A.menu(t))):(w.debug("Creating entire dropdown from select"),I=e("<div />").attr("class",V.attr("class")).addClass(y.selection).addClass(y.dropdown).html(A.dropdown(t)).insertBefore(V),V.removeAttr("class").detach().prependTo(I)),V.is("[multiple]")&&w.set.multiple(),w.refresh()},reference:function(){var e,t,n=r.index(I);w.debug("Dropdown behavior was called on select, replacing with closest dropdown"),I=I.parent(S.dropdown),w.refresh(),e=r.slice(0,n),t=r.slice(n+1),r=e.add(I).add(t),f&&(H=w,w.invoke(v))}},refresh:function(){w.verbose("Refreshing selector cache"),O=I.find(S.text),F=I.find(S.search),V=I.find(S.input),R=I.find(S.icon),q=I.prev().find(S.text).length>0?I.prev().find(S.text):I.prev(),M=I.children(S.menu),P=M.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.is.searchSelection()&&w.filterActive(),w.animate.show(function(){w.can.click()&&w.bind.intent(),w.set.visible(),t.call(j)}),x.onShow.call(j))},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(j)}),x.onHide.call(j))},hideOthers:function(){w.verbose("Finding other dropdowns to hide"),r.not(I).has(S.menu+":visible:not(."+y.animating+")").dropdown("hide")},hideSubMenus:function(){var e=M.children(S.item).find(S.menu);e.transition("hide")},bind:{keyboardEvents:function(){w.debug("Binding keyboard events"),I.on("keydown"+E,w.event.keydown),w.has.search()&&I.on(w.get.inputEvent()+E,S.search,w.event.input),w.is.multiple()&&l.on("k
|