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
  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,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,I="module-"+T,D=e(this),O=D.find(S.text),V=D.find(S.search),F=D.find(S.input),q=D.find(S.icon),R=D.prev().find(S.text).length>0?D.prev().find(S.text):D.prev(),M=D.children(S.menu),P=M.find(S.item),L=!1,j=!1,z=this,H=D.data(I);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,D.data(I,w)},destroy:function(){w.verbose("Destroying previous dropdown for",D),w.remove.tabbable(),D.off(E).removeData(I),M.off(E),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(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=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(y.search).insertBefore(O)),x.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),M=D.children(S.menu),0===M.length&&(M=e("<div />").addClass(y.menu).appendTo(D)),M.html(A.menu(t))):(w.debug("Creating entire dropdown from select"),D=e("<div />").attr("class",F.attr("class")).addClass(y.selection).addClass(y.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),q=D.find(S.icon),R=D.prev().find(S.text).length>0?D.prev().find(S.text):D.prev(),M=D.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.filterActive(),w.animate.show(function(){w.can.click()&&w.bind.intent(),w.set.visible(),t.call(z)}),x.onShow.call(z))},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(z)}),x.onHide.call(z))},hideOthers:function(){w.verbose("Finding other dropdowns to hide"),r.not(D).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"),D.on("keydown"+E,w.event.keydown),w.has.search()&&D.on(w.get.inputEvent()+E,S.search,w.event.input),w.is.multiple()&&s.on("keydown"+h,w.event.document.keydown)},touchEve