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

9 years ago
9 years ago
9 years ago
9 years ago
  1. /*!
  2. * # Semantic UI 1.11.3 - 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),c=r.selector||"",l="ontouchstart"in n.documentElement,u=(new Date).getTime(),d=[],f=arguments[0],v="string"==typeof f,m=[].slice.call(arguments,1);return r.each(function(h){var 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,S=y.namespace,C=y.selector,k=y.error,I="."+S,E="module-"+S,A=e(this),D=A.find(C.text),F=A.find(C.search),M=A.find(C.input),O=A.prev().find(C.text).length>0?A.prev().find(C.text):A.prev(),q=A.children(C.menu),V=q.find(C.item),z=!1,Q=!1,R=this,P=A.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(),l&&w.bind.touchEvents(),w.bind.mouseEvents(),w.bind.keyboardEvents(),w.observeChanges(),w.instantiate())},instantiate:function(){w.verbose("Storing instance of dropdown",w),P=w,A.data(E,w)},destroy:function(){w.verbose("Destroying previous dropdown for",A),w.remove.tabbable(),A.off(I).removeData(E),q.off(I),s.off(g)},observeChanges:function(){"MutationObserver"in t&&(b=new MutationObserver(function(e){w.is.selectMutation(e)?(w.debug("<select> modified, recreating menu"),w.setup.select()):(w.debug("DOM tree modified, updating selector cache"),w.refresh())}),b.observe(R,{childList:!0,subtree:!0}),w.debug("Setting up mutation observer",b))},create:{id:function(){p=(Math.random().toString(16)+"000000000").substr(2,8),g="."+p,w.verbose("Creating unique id for element",p)}},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(){A.is("select")&&w.setup.select(),w.is.search()&&!w.is.searchable()&&(F=e("<input />").addClass(x.search).insertBefore(D)),y.allowTab&&w.set.tabbable()},select:function(){var t=w.get.selectValues();w.debug("Dropdown initialized on a select",t),A.is("select")&&(M=A),M.parent(C.dropdown).length>0?(w.debug("UI dropdown already exists. Creating dropdown menu only"),A=M.closest(C.dropdown),q=A.children(C.menu),0===q.length&&(q=e("<div />").addClass(x.menu).appendTo(A)),q.html(y.templates.menu(t))):(w.debug("Creating entire dropdown from select"),A=e("<div />").attr("class",M.attr("class")).addClass(x.selection).addClass(x.dropdown).html(y.templates.dropdown(t)).insertBefore(M),M.removeAttr("class").prependTo(A)),w.setup.reference()},reference:function(){var e,t;w.debug("Dropdown behavior was called on select, replacing with closest dropdown"),A=A.closest(C.dropdown),w.refresh(),e=r.slice(0,h),t=r.slice(h+1),r=e.add(A).add(t)}},refresh:function(){w.verbose("Refreshing selector cache"),D=A.find(C.text),F=A.find(C.search),M=A.find(C.input),O=A.prev().find(C.text).length>0?A.prev().find(C.text):A.prev(),q=A.children(C.menu),V=q.find(C.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.animate.show(function(){w.can.click()&&w.bind.intent(),w.set.visible(),t.call(R)}),y.onShow.call(R))},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(R)}),y.onHide.call(R))},hideOthers:function(){w.verbose("Finding other dropdowns to hide"),r.not(A).has(C.menu+":visible:not(."+x.animating+")").dropdown("hide")},hideSubMenus:function(){var e=q.find(C.menu);e.transition("hide")},bind:{keyboardEvents:function(){w.debug("Binding keyboard events"),A.on("keydown"+I,w.event.keydown),w.is.searchable()&&A.on(w.get.inputEvent(),C.search,w.event.input)},touchEvents:function(){w.debug("Touch device detected binding additional touch events"),w.is.searchSelection()||A.on("touchstart"+I,w.event.test.toggle),q.on("touchstart"+I,C.item,w.event.item.mouseenter)},mouseEvents:function(){w.verbose("Mouse detected binding mouse events"),w.is.searchSelection()?A.on("mou