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

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