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

  1. /*
  2. * # Semantic UI
  3. * https://github.com/Semantic-Org/Semantic-UI
  4. * http://beta.semantic-ui.com/
  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,s=e(this),r=e(n),u=s.selector||"",c="ontouchstart"in n.documentElement,d=(new Date).getTime(),l=[],v=arguments[0],f="string"==typeof v,m=[].slice.call(arguments,1);return s.each(function(){var n,h,p=e.isPlainObject(o)?e.extend(!0,{},e.fn.dropdown.settings,o):e.extend({},e.fn.dropdown.settings),g=p.className,b=p.metadata,w=p.namespace,y=p.selector,x=p.error,T="."+w,C="module-"+w,k=e(this),S=k.find(y.text),z=k.find(y.search),E=k.find(y.input),D=k.prev().find(y.text).size()>0?k.prev().find(y.text):k.prev(),M=k.children(y.menu),A=M.find(y.item),O=!1,I=!1,Q=this,F=k.data(C);h={initialize:function(){h.debug("Initializing dropdown",p),h.setup.layout(),h.save.defaults(),h.set.selected(),c&&h.bind.touchEvents(),h.bind.mouseEvents(),h.bind.keyboardEvents(),h.observeChanges(),h.instantiate()},instantiate:function(){h.verbose("Storing instance of dropdown",h),F=h,k.data(C,h)},destroy:function(){h.verbose("Destroying previous dropdown for",k),k.off(T).removeData(C)},observeChanges:function(){"MutationObserver"in t&&(n=new MutationObserver(function(){h.debug("DOM tree modified, updating selector cache"),h.refresh()}),n.observe(Q,{childList:!0,subtree:!0}),h.debug("Setting up mutation observer",n))},setup:{layout:function(){k.is("select")&&h.setup.select(),h.is.search()&&!h.is.searchable()&&(z=e("<input />").addClass(g.search).insertBefore(S)),p.allowTab&&(h.is.searchable()?(h.debug("Searchable dropdown initialized"),z.val("").attr("tabindex",0),M.attr("tabindex","-1")):(h.debug("Simple selection dropdown initialized"),k.attr("tabindex")||(k.attr("tabindex",0),M.attr("tabindex","-1"))))},select:function(){var t=h.get.selectValues();h.debug("Dropdown initialized on a select",t),E=k,E.parents(y.dropdown).size()>0?(h.debug("Creating dropdown menu only from template"),k=E.closest(y.dropdown),0===k.find("."+g.dropdown).size()&&e("<div />").addClass(g.menu).html(p.templates.menu(t)).appendTo(k)):(h.debug("Creating entire dropdown from template"),k=e("<div />").attr("class",E.attr("class")).addClass(g.selection).addClass(g.dropdown).html(p.templates.dropdown(t)).insertBefore(E),E.removeAttr("class").prependTo(k)),h.refresh()}},refresh:function(){S=k.find(y.text),z=k.find(y.search),E=k.find(y.input),M=k.children(y.menu),A=M.find(y.item)},toggle:function(){h.verbose("Toggling menu visibility"),h.is.active()?h.hide():h.show()},show:function(){h.debug("Checking if dropdown can show"),h.is.active()||(h.animate.show(function(){h.can.click()&&h.bind.intent(),h.set.visible()}),e.proxy(p.onShow,Q)())},hide:function(){h.is.active()&&(h.debug("Hiding dropdown"),h.animate.hide(function(){h.remove.filteredItem(),h.remove.visible()}),e.proxy(p.onHide,Q)())},hideOthers:function(){h.verbose("Finding other dropdowns to hide"),s.not(k).has(y.menu+":visible:not(."+g.animating+")").dropdown("hide")},hideSubMenus:function(){var e=M.find(y.menu),t=e.has(y.item+"."+g.active);e.not(t).removeClass(g.visible).removeAttr("style")},bind:{keyboardEvents:function(){h.debug("Binding keyboard events"),k.on("keydown"+T,h.event.keydown),h.is.searchable()&&k.on(h.get.inputEvent(),y.search,h.event.input)},touchEvents:function(){h.debug("Touch device detected binding additional touch events"),h.is.searchSelection()||k.on("touchstart"+T,h.event.test.toggle),M.on("touchstart"+T,y.item,h.event.item.mouseenter)},mouseEvents:function(){h.verbose("Mouse detected binding mouse events"),h.is.searchSelection()?k.on("mousedown"+T,y.menu,h.event.menu.activate).on("mouseup"+T,y.menu,h.event.menu.deactivate).on("focus"+T,y.search,h.event.searchFocus).on("blur"+T,y.search,h.event.searchBlur):("click"==p.on?k.on("click"+T,h.event.test.toggle):"hover"==p.on?k.on("mouseenter"+T,h.delay.show).on("mouseleave"+T,h.delay.hide):k.on(p.on+T,h.toggle),k.on("mousedown"+T,h.event.mousedown).on("mouseup"+T,h.event.mouseup).on("focus"+T,h.event.focus).on("blur"+T,h.event.blur)),M.on("mouseenter"+T,y.item,h.event.item.mouseenter).on("mouseleave"+T,y.item,h.event.item.mouseleave).on("click"+T,y.item,h.event.item.click)},intent:function(){h.verb