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