|
|
/*! * # 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,s=e(this),r=e(n),l=s.selector||"",c="ontouchstart"in n.documentElement,u=(new Date).getTime(),d=[],v=arguments[0],f="string"==typeof v,m=[].slice.call(arguments,1);return s.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.message,S=y.metadata,T=y.namespace,k=y.regExp,A=y.selector,D=y.error,E=y.templates,L="."+T,I="module-"+T,O=e(this),q=O.find(A.text),F=O.find(A.search),R=O.find(A.input),z=O.find(A.icon),V=O.prev().find(A.text).length>0?O.prev().find(A.text):O.prev(),M=O.children(A.menu),P=M.find(A.item),j=!1,H=!1,U=this,K=O.data(I);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,O.data(I,w)},destroy:function(){w.verbose("Destroying previous dropdown for",O),w.remove.tabbable(),O.off(L).removeData(I),M.off(L),r.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(R[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=w.get.query();w.verbose("Searching for query",e),w.filter(e),w.is.searchSelection()&&w.can.show()&&w.show()},select:{firstUnfiltered:function(){w.verbose("Selecting first non-filtered element"),w.remove.selectedItem(),P.not("."+x.filtered).eq(0).addClass(x.selected)},nextAvailable:function(e){e=e.eq(0);var t=e.nextAll(A.item).not("."+x.filtered).eq(0),n=e.prevAll(A.item).not("."+x.filtered).eq(0),i=t.length>0;i?(w.verbose("Moving selection to",t),t.addClass(x.selected)):(w.verbose("Moving selection to",n),n.addClass(x.selected))}},setup:{layout:function(){O.is("select")&&w.setup.select(),w.is.search()&&!w.has.search()&&(F=e("<input />").addClass(x.search).insertBefore(q)),y.allowTab&&w.set.tabbable()},select:function(){var t=w.get.selectValues();w.debug("Dropdown initialized on a select",t),O.is("select")&&(R=O),R.parent(A.dropdown).length>0?(w.debug("UI dropdown already exists. Creating dropdown menu only"),O=R.closest(A.dropdown),M=O.children(A.menu),0===M.length&&(M=e("<div />").addClass(x.menu).appendTo(O)),M.html(E.menu(t))):(w.debug("Creating entire dropdown from select"),O=e("<div />").attr("class",R.attr("class")).addClass(x.selection).addClass(x.dropdown).html(E.dropdown(t)).insertBefore(R),R.removeAttr("class").detach().prependTo(O)),R.is("[multiple]")&&w.set.multiple(),w.refresh()},reference:function(){var e,t,n=s.index(O);w.debug("Dropdown behavior was called on select, replacing with closest dropdown"),O=O.parent(A.dropdown),w.refresh(),e=s.slice(0,n),t=s.slice(n+1),s=e.add(O).add(t),f&&(K=w,w.invoke(v))}},refresh:function(){w.verbose("Refreshing selector cache"),q=O.find(A.text),F=O.find(A.search),R=O.find(A.input),z=O.find(A.icon),V=O.prev().find(A.text).length>0?O.prev().find(A.text):O.prev(),M=O.children(A.menu),P=M.find(A.item)},toggle:function(){w.verbose("Toggling menu visibility"),w.is.active()?w.hide():w.show()},show:function(t){if(t=e.isFunction(t)?t:function(){},w.can.show()&&!w.is.active()){if(w.debug("Showing dropdown"),w.is.multiple()&&!w.has.search()&&w.is.allFiltered())return!0;w.animate.show(function(){w.can.click()&&w.bind.intent(),w.set.visible(),t.call(U)}),y.onShow.call(U)}},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(U)}),y.onHide.call
|