|
|
/* * # Semantic UI * git://github.com/Semantic-Org/Semantic-UI.git
* * * Copyright 2014 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !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=this,I=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.observeChanges(),m.bind.mouseEvents(),m.bind.keyboardEvents(),m.instantiate()},instantiate:function(){m.verbose("Storing instance of dropdown",m),I=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(O,{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"),console.log(m.is.active()),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,O)())},hide:function(){m.is.active()&&(m.debug("Hiding dropdown"),m.animate.hide(function(){m.remove.filteredItem(),m.remove.visible()}),e.proxy(h.onHide,O)())},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);console.log(e.not(t)),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),m.is.searchSelection()?C.on("focus"+x,w.search,m.event.searchFocus).on("blur"+x,w.search,m.event.searchBlur):C.on("mousedown",m.event.mousedown).on("mouseup",m.event.mouseup).on("focus"+x,m.event.focus).on("blur"+x,m.event.blur)},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()||("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("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)},intent:function(){m.ve
|