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
23 KiB

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