|
|
!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,d=(new Date).getTime(),l=[],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,z="module-"+T,I=e(this),D=I.find(C.text),E=I.find(C.search),F=I.find(C.input),A=I.prev().find(C.text).size()>0?I.prev().find(C.text):I.prev(),M=I.children(C.menu),O=M.find(C.item),q=!1,V=!1,Q=this,P=I.data(z);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),P=b,I.data(z,b)},destroy:function(){b.verbose("Destroying previous dropdown for",I),b.remove.tabbable(),I.off(k).removeData(z),r.off(h)},observeChanges:function(){"MutationObserver"in t&&(p=new MutationObserver(function(){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(){b.verbose("Creating unique id for element"),g=b.get.uniqueID(),h="."+g}},search:function(){var e;e=E.val(),b.verbose("Searching for query",e),b.is.searchSelection()&&(b.filter(e),b.can.show()&&b.show())},setup:{layout:function(){I.is("select")&&b.setup.select(),b.is.search()&&!b.is.searchable()&&(E=e("<input />").addClass(y.search).insertBefore(D)),w.allowTab&&b.set.tabbable()},select:function(){var t=b.get.selectValues();b.debug("Dropdown initialized on a select",t),F=I,F.parents(C.dropdown).size()>0?(b.debug("Creating dropdown menu only from template"),I=F.closest(C.dropdown),0===I.find("."+y.dropdown).size()&&e("<div />").addClass(y.menu).html(w.templates.menu(t)).appendTo(I)):(b.debug("Creating entire dropdown from template"),I=e("<div />").attr("class",F.attr("class")).addClass(y.selection).addClass(y.dropdown).html(w.templates.dropdown(t)).insertBefore(F),F.removeAttr("class").prependTo(I)),b.refresh()}},refresh:function(){D=I.find(C.text),E=I.find(C.search),F=I.find(C.input),M=I.children(C.menu),O=M.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(),e.proxy(t,Q)()}),e.proxy(w.onShow,Q)())},hide:function(t){t=e.isFunction(t)?t:function(){},b.is.active()&&(b.debug("Hiding dropdown"),b.animate.hide(function(){b.remove.visible(),e.proxy(t,Q)()}),e.proxy(w.onHide,Q)())},hideOthers:function(){b.verbose("Finding other dropdowns to hide"),s.not(I).has(C.menu+":visible:not(."+y.animating+")").dropdown("hide")},hideSubMenus:function(){var e=M.find(C.menu);e.transition("hide")},bind:{keyboardEvents:function(){b.debug("Binding keyboard events"),I.on("keydown"+k,b.event.keydown),b.is.searchable()&&I.on(b.get.inputEvent(),C.search,b.event.input)},touchEvents:function(){b.debug("Touch device detected binding additional touch events"),b.is.searchSelection()||I.on("touchstart"+k,b.event.test.toggle),M.on("touchstart"+k,C.item,b.event.item.mouseenter)},mouseEvents:function(){b.verbose("Mouse detected binding mouse events"),b.is.searchSelection()?I.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?I.on("click"+k,b.event.test.toggle):"hover"==w.on?I.on("mouseenter"+k,b.delay.show).on("mouseleave"+k,b.delay.hide):I.on(w.on+k,b.toggle),I.on("mousedown"+k,b.event.mousedown).on("mouseup"+k,b.event.mouseup).on("focus"+k,b.event.focus).on("blur"+k,b.event.blur)),M.on("mouseenter"+k,C.item,b.event.item.mouseenter).on("mousel
|