You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
27 KiB

9 years ago
9 years ago
9 years ago
9 years ago
  1. /*!
  2. * # Semantic UI 2.0.0 - Dropdown
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Copyright 2014 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !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),O=D.find(S.text),V=D.find(S.search),F=D.find(S.input),M=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,H=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),H=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(F[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=V.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()&&(V=e("<input />").addClass(x.search).insertBefore(O)),y.allowTab&&w.set.tabbable()},select:function(){var t=w.get.selectValues();w.debug("Dropdown initialized on a select",t),D.is("select")&&(F=D),F.parent(S.dropdown).length>0?(w.debug("UI dropdown already exists. Creating dropdown menu only"),D=F.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",F.attr("class")).addClass(x.selection).addClass(x.dropdown).html(A.dropdown(t)).insertBefore(F),F.removeAttr("class").detach().prependTo(D)),F.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"),O=D.find(S.text),V=D.find(S.search),F=D.find(S.input),M=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.children(S.item).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)},touchEve