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

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