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.0 - 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(){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,S=w.selector,C=w.error,k="."+T,I="module-"+T,E=e(this),A=E.find(S.text),D=E.find(S.search),F=E.find(S.input),M=E.prev().find(S.text).length>0?E.prev().find(S.text):E.prev(),O=E.children(S.menu),q=O.find(S.item),V=!1,z=!1,Q=this,R=E.data(I);b={initialize:function(){b.debug("Initializing dropdown",w),b.is.alreadySetup()?b.error(C.alreadySetup):b.setup.layout(),b.save.defaults(),b.set.selected(),b.create.id(),l&&b.bind.touchEvents(),b.bind.mouseEvents(),b.bind.keyboardEvents(),b.observeChanges(),b.instantiate()},instantiate:function(){b.verbose("Storing instance of dropdown",b),R=b,E.data(I,b)},destroy:function(){b.verbose("Destroying previous dropdown for",E),b.remove.tabbable(),E.off(k).removeData(I),O.off(k),s.off(h)},observeChanges:function(){"MutationObserver"in t&&(p=new MutationObserver(function(e){b.is.selectMutation(e)?(b.debug("<select> modified, recreating menu"),b.setup.select()):(b.debug("DOM tree modified, updating selector cache"),b.refresh())}),p.observe(Q,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",p))},create:{id:function(){g=(Math.random().toString(16)+"000000000").substr(2,8),h="."+g,b.verbose("Creating unique id for element",g)}},search:function(){var e;e=D.val(),b.verbose("Searching for query",e),b.filter(e),b.is.searchSelection()&&b.can.show()&&b.show()},setup:{layout:function(){E.is("select")&&b.setup.select(),b.is.search()&&!b.is.searchable()&&(D=e("<input />").addClass(y.search).insertBefore(A)),w.allowTab&&b.set.tabbable()},select:function(){var t=b.get.selectValues();b.debug("Dropdown initialized on a select",t),E.is("select")&&(F=E),F.parent(S.dropdown).length>0?(b.debug("UI dropdown already exists. Creating dropdown menu only"),E=F.closest(S.dropdown),O=E.children(S.menu),0===O.length&&(O=e("<div />").addClass(y.menu).appendTo(E)),O.html(w.templates.menu(t))):(b.debug("Creating entire dropdown from select"),E=e("<div />").attr("class",F.attr("class")).addClass(y.selection).addClass(y.dropdown).html(w.templates.dropdown(t)).insertBefore(F),F.removeAttr("class").prependTo(E)),b.refresh()}},refresh:function(){b.verbose("Refreshing selector cache"),A=E.find(S.text),D=E.find(S.search),F=E.find(S.input),M=E.prev().find(S.text).length>0?E.prev().find(S.text):E.prev(),O=E.children(S.menu),q=O.find(S.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.searchSelection()&&b.is.allFiltered()||b.can.show()&&!b.is.active()&&(b.debug("Showing dropdown"),b.animate.show(function(){b.can.click()&&b.bind.intent(),b.set.visible(),t.call(Q)}),w.onShow.call(Q))},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(Q)}),w.onHide.call(Q))},hideOthers:function(){b.verbose("Finding other dropdowns to hide"),r.not(E).has(S.menu+":visible:not(."+y.animating+")").dropdown("hide")},hideSubMenus:function(){var e=O.find(S.menu);e.transition("hide")},bind:{keyboardEvents:function(){b.debug("Binding keyboard events"),E.on("keydown"+k,b.event.keydown),b.is.searchable()&&E.on(b.get.inputEvent(),S.search,b.event.input)},touchEvents:function(){b.debug("Touch device detected binding additional touch events"),b.is.searchSelection()||E.on("touchstart"+k,b.event.test.toggle),O.on("touchstart"+k,S.item,b.event.item.mouseenter)},mouseEvents:function(){b.verbose("Mouse detected binding mouse events"),b.is.searchSelection()?E.on("mousedown"+k,S.menu,b.event.menu.activate).on("mouseup"+k,S.menu,b.event.menu.deactivate).on("click"+k,S.search,b.show).on("focus"+k,S.search,b.event.searchFocus).on("blur"+k,S.search,b.event.searchBlur).on(