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.
 
 
 

1 lines
8.3 KiB

!function(a,b,c,d){a.fn.dropdown=function(b){var e,f=a(this),g=a(c),h=a.isPlainObject(b)?a.extend(!0,{},a.fn.dropdown.settings,b):a.fn.dropdown.settings,i=h.className,j=h.metadata,k=h.namespace,l=h.selector,m=h.error,n="."+k,o="module-"+k,p=f.selector||"",q=(new Date).getTime(),r=[],s=arguments[0],t="string"==typeof s,u=[].slice.call(arguments,1);return f.each(function(){var b,e=a(this),k=e.find(l.item),v=e.find(l.text),w=e.find(l.input),x=e.children(l.menu),y="ontouchstart"in c.documentElement,z=this,A=e.data(o);b={initialize:function(){b.debug("Initializing dropdown",h),y?e.on("touchstart"+n,b.event.test.toggle):"click"==h.on?e.on("click"+n,b.event.test.toggle):"hover"==h.on?e.on("mouseenter"+n,b.delay.show).on("mouseleave"+n,b.delay.hide):e.on(h.on+n,b.toggle),"updateForm"==h.action&&b.set.selected(),k.on("mouseenter"+n,b.event.item.mouseenter).on("mouseleave"+n,b.event.item.mouseleave).on(b.get.selectEvent()+n,b.event.item.click),b.instantiate()},instantiate:function(){b.verbose("Storing instance of dropdown",b),e.data(o,b)},destroy:function(){b.verbose("Destroying previous dropdown for",e),k.off(n),e.off(n).removeData(o)},event:{stopPropagation:function(a){a.stopPropagation()},test:{toggle:function(a){b.determine.intent(a,b.toggle),a.stopImmediatePropagation()},hide:function(a){b.determine.intent(a,b.hide),a.stopPropagation()}},item:{mouseenter:function(){var c=a(this).find(l.menu),d=a(this).siblings(l.item).children(l.menu);c.size()>0&&(clearTimeout(b.itemTimer),b.itemTimer=setTimeout(function(){b.animate.hide(!1,d),b.verbose("Showing sub-menu",c),b.animate.show(!1,c)},2*h.delay.show))},mouseleave:function(){var c=a(this).find(l.menu);c.size()>0&&(clearTimeout(b.itemTimer),b.itemTimer=setTimeout(function(){b.verbose("Hiding sub-menu",c),b.animate.hide(!1,c)},h.delay.hide))},click:function(c){var d=a(this),e=d.data(j.text)||d.text(),f=d.data(j.value)||e.toLowerCase();0===d.find(l.menu).size()&&(b.verbose("Adding active state to selected item"),k.removeClass(i.active),d.addClass(i.active),b.determine.selectAction(e,f),a.proxy(h.onChange,z)(f,e),c.stopPropagation())}},resetStyle:function(){a(this).removeAttr("style")}},determine:{selectAction:function(c,d){b.verbose("Determining action",h.action),a.isFunction(b[h.action])?(b.verbose("Triggering preset action",h.action),b[h.action](c,d)):a.isFunction(h.action)?(b.verbose("Triggering user action",h.action),h.action(c,d)):b.error(m.action)},intent:function(c,d){b.debug("Determining whether event occurred in dropdown",c.target),d=d||function(){},0===a(c.target).closest(x).size()?(b.verbose("Triggering event",d),d()):b.verbose("Event occurred in dropdown, canceling callback")}},bind:{intent:function(){b.verbose("Binding hide intent event to document"),g.on(b.get.selectEvent(),b.event.test.hide)}},unbind:{intent:function(){b.verbose("Removing hide intent event from document"),g.off(b.get.selectEvent())}},nothing:function(){},changeText:function(a){b.set.text(a),b.hide()},updateForm:function(a,c){b.set.text(a),b.set.value(c),b.hide()},get:{selectEvent:function(){return y?"touchstart":"click"},text:function(){return v.text()},value:function(){return w.val()},item:function(b){var c;return b=b||w.val(),k.each(function(){a(this).data(j.value)==b&&(c=a(this))}),c||!1}},set:{text:function(a){b.debug("Changing text",a,v),v.removeClass(i.placeholder),v.text(a)},value:function(a){b.debug("Adding selected value to hidden input",a,w),w.val(a)},active:function(){e.addClass(i.active)},visible:function(){e.addClass(i.visible)},selected:function(a){var c,d=b.get.item(a);d&&(b.debug("Setting selected menu item to",d),c=d.data(j.text)||d.text(),k.removeClass(i.active),d.addClass(i.active),b.set.text(c))}},remove:{active:function(){e.removeClass(i.active)},visible:function(){e.removeClass(i.visible)}},is:{visible:function(a){return a?a.is(":animated, :visible"):x.is(":animated, :visible")},hidden:function(a){return a?a.is(":not(:animated, :visible)"):x.is(":not(:animated, :visible)")}},can:{click:function(){return y||"click"==h.on},show:function(){return!e.hasClass(i.disabled)}},animate:{show:function(c,e){var f=e||x;c=c||function(){},b.is.hidden(f)&&(b.verbose("Doing menu show animation",f),"none"==h.transition?c():a.fn.transition!==d?f.transition({animation:h.transition+" in",duration:h.duration,complete:c,queue:!1}):"slide down"==h.transition?f.hide().clearQueue().children().clearQueue().css("opacity",0).delay(50).animate({opacity:1},h.duration,"easeOutQuad",b.event.resetStyle).end().slideDown(100,"easeOutQuad",function(){a.proxy(b.event.resetStyle,this)(),c()}):"fade"==h.transition?f.hide().clearQueue().fadeIn(h.duration,function(){a.proxy(b.event.resetStyle,this)(),c()}):b.error(m.transition))},hide:function(c,e){var f=e||x;c=c||function(){},b.is.visible(f)&&(b.verbose("Doing menu hide animation",f),a.fn.transition!==d?f.transition({animation:h.transition+" out",duration:h.duration,complete:c,queue:!1}):"none"==h.transition?c():"slide down"==h.transition?f.show().clearQueue().children().clearQueue().css("opacity",1).animate({opacity:0},100,"easeOutQuad",b.event.resetStyle).end().delay(50).slideUp(100,"easeOutQuad",function(){a.proxy(b.event.resetStyle,this)(),c()}):"fade"==h.transition?f.show().clearQueue().fadeOut(150,function(){a.proxy(b.event.resetStyle,this)(),c()}):b.error(m.transition))}},show:function(){b.debug("Checking if dropdown can show"),b.is.hidden()&&(b.hideOthers(),b.set.active(),b.animate.show(b.set.visible),b.can.click()&&b.bind.intent(),a.proxy(h.onShow,z)())},hide:function(){b.is.visible()&&(b.debug("Hiding dropdown"),b.can.click()&&b.unbind.intent(),b.remove.active(),b.animate.hide(b.remove.visible),a.proxy(h.onHide,z)())},delay:{show:function(){b.verbose("Delaying show event to ensure user intent"),clearTimeout(b.timer),b.timer=setTimeout(b.show,h.delay.show)},hide:function(){b.verbose("Delaying hide event to ensure user intent"),clearTimeout(b.timer),b.timer=setTimeout(b.hide,h.delay.hide)}},hideOthers:function(){b.verbose("Finding other dropdowns to hide"),f.not(e).has(l.menu+":visible").dropdown("hide")},toggle:function(){b.verbose("Toggling menu visibility"),b.is.hidden()?b.show():b.hide()},setting:function(b,c){return c===d?h[b]:(a.isPlainObject(b)?a.extend(!0,h,b):h[b]=c,void 0)},internal:function(c,e){return e===d?b[c]:(a.isPlainObject(c)?a.extend(!0,b,c):b[c]=e,void 0)},debug:function(){h.debug&&(h.performance?b.performance.log(arguments):(b.debug=Function.prototype.bind.call(console.info,console,h.name+":"),b.debug.apply(console,arguments)))},verbose:function(){h.verbose&&h.debug&&(h.performance?b.performance.log(arguments):(b.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),b.verbose.apply(console,arguments)))},error:function(){b.error=Function.prototype.bind.call(console.error,console,h.name+":"),b.error.apply(console,arguments)},performance:{log:function(a){var c,d,e;h.performance&&(c=(new Date).getTime(),e=q||c,d=c-e,q=c,r.push({Element:z,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":d})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,100)},display:function(){var c=h.name+":",e=0;q=!1,clearTimeout(b.performance.timer),a.each(r,function(a,b){e+=b["Execution Time"]}),c+=" "+e+"ms",p&&(c+=" '"+p+"'"),(console.group!==d||console.table!==d)&&r.length>0&&(console.groupCollapsed(c),console.table?console.table(r):a.each(r,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),r=[]}},invoke:function(c,e,f){var g,h;return e=e||u,f=z||f,"string"==typeof c&&A!==d&&(c=c.split(/[\. ]/),g=c.length-1,a.each(c,function(c,e){a.isPlainObject(A[e])&&c!=g?A=A[e]:A[e]!==d?h=A[e]:b.error(m.method)})),a.isFunction(h)?h.apply(f,e):h||!1}},t?(A===d&&b.initialize(),b.invoke(s)):(A!==d&&b.destroy(),b.initialize())}),e?e:this},a.fn.dropdown.settings={name:"Dropdown",namespace:"dropdown",verbose:!0,debug:!0,performance:!0,on:"click",action:"hide",delay:{show:200,hide:300},transition:"slide down",duration:250,onChange:function(){},onShow:function(){},onHide:function(){},error:{action:"You called a dropdown action that was not defined",method:"The method you called is not defined.",transition:"The requested transition was not found"},metadata:{text:"text",value:"value"},selector:{menu:".menu",item:".menu > .item",text:"> .text",input:'> input[type="hidden"]'},className:{active:"active",placeholder:"default",disabled:"disabled",visible:"visible"}}}(jQuery,window,document);