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
6.9 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.animation,m=h.selector,n=h.errors,o="."+k,p="module-"+k,q=f.selector||"",r=(new Date).getTime(),s=[],t=arguments[0],u="string"==typeof t,v=[].slice.call(arguments,1);return f.each(function(){var b,w=a(this),x=a(this).find(m.menu),y=a(this).find(m.item),z=a(this).find(m.text),A=a(this).find(m.input),B="ontouchstart"in c.documentElement,C=this,D=w.data(p);b={initialize:function(){b.debug("Initializing dropdown with bound events",w),B?w.on("touchstart"+o,b.event.test.toggle):"click"==h.on?w.on("click"+o,b.event.test.toggle):"hover"==h.on?w.on("mouseenter"+o,b.delay.show).on("mouseleave"+o,b.delay.hide):w.on(h.on+o,b.toggle),"form"==h.action&&b.set.selected(),y.on(b.get.selectEvent()+o,b.event.item.click),b.instantiate()},instantiate:function(){b.verbose("Storing instance of module",b),w.data(p,b)},destroy:function(){b.verbose("Destroying previous module for",w),w.off(k).removeData(p)},event:{stopPropagation:function(a){a.stopPropagation()},test:{toggle:function(a){b.intent.test(a,b.toggle),a.stopPropagation()},hide:function(a){b.intent.test(a,b.hide),a.stopPropagation()}},item:{click:function(c){var d=a(this),e=d.data(j.text)||d.text(),f=d.data(j.value)||e;b.verbose("Adding active state to selected item"),y.removeClass(i.active),d.addClass(i.active),b.action.determine(e,f),a.proxy(h.onChange,w.get())(f,e),c.stopPropagation()}},resetStyle:function(){a(this).removeAttr("style")}},intent:{test: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:function(){b.verbose("Binding hide intent event to document"),g.on(b.get.selectEvent(),b.event.test.hide)},unbind:function(){b.verbose("Removing hide intent event from document"),g.off(b.get.selectEvent())}},action:{determine:function(c,d){a.isFunction(b.action[h.action])?(b.verbose("Triggering preset action",h.action),b.action[h.action](c,d)):a.isFunction(h.action)?(b.verbose("Triggering user action",h.action),h.action(c,d)):b.error(n.action)},none:function(){},hide:function(){b.hide()},changeText:function(a){b.set.text(a),b.hide()},form:function(a,c){b.set.text(a),b.set.value(c),b.hide()}},get:{selectEvent:function(){return B?"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(j.value)==b&&(c=a(this))}),c||!1}},set:{text:function(a){b.debug("Changing text",a,z),z.removeClass(i.placeholder),z.text(a)},value:function(a){b.debug("Adding selected value to hidden input",a,A),A.val(a)},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(),y.removeClass(i.active),d.addClass(i.active),b.set.text(c))}},is:{visible:function(){return x.is(":visible")},hidden:function(){return x.is(":not(:visible)")}},can:{click:function(){return B||"click"==h.on},show:function(){return!w.hasClass(i.disabled)}},animate:{show:function(){b.verbose("Doing menu showing animation"),"none"==l.show?x.show():"fade"==l.show?x.hide().clearQueue().fadeIn(150,b.event.resetStyle):"slide"==l.show?x.hide().clearQueue().children().clearQueue().css("opacity",0).delay(50).animate({opacity:1},200,"easeOutQuad",b.event.resetStyle).end().slideDown(100,"easeOutQuad",b.event.resetStyle):b.error(n.animation)},hide:function(){b.verbose("Doing menu hiding animation"),"none"==l.hide?x.hide():"fade"==l.hide?x.show().clearQueue().fadeOut(150,b.event.resetStyle):"slide"==l.hide?x.show().clearQueue().children().clearQueue().css("opacity",1).animate({opacity:0},100,"easeOutQuad",b.event.resetStyle).end().delay(50).slideUp(100,"easeOutQuad",b.event.resetStyle):b.error(n.animation)}},show:function(){b.debug("Checking if dropdown can show"),b.is.visible()||(b.hideOthers(),w.addClass(i.visible),b.animate.show(),b.can.click()&&b.intent.bind(),a.proxy(h.onShow,w.get())())},hide:function(){b.is.hidden()||(b.debug("Hiding dropdown"),w.removeClass(i.visible),b.can.click()&&b.intent.unbind(),b.animate.hide(),a.proxy(h.onHide,w.get())())},delay:{show:function(){b.verbose("Delaying show event to ensure user intent"),clearTimeout(b.graceTimer),b.graceTimer=setTimeout(b.show,h.delay.show)},hide:function(){b.verbose("Delaying hide event to ensure user intent"),clearTimeout(b.graceTimer),b.graceTimer=setTimeout(b.hide,h.delay.hide)}},hideOthers:function(){b.verbose("Finding other dropdowns to hide"),f.not(w).has(m.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.moduleName+":"))},verbose:function(){h.verbose&&h.debug&&(h.performance?b.performance.log(arguments):b.verbose=Function.prototype.bind.call(console.info,console,h.moduleName+":"))},error:function(){b.error=Function.prototype.bind.call(console.log,console,h.moduleName+":")},performance:{log:function(a){var c,d,e;h.performance&&(c=(new Date).getTime(),e=r||c,d=c-e,r=c,s.push({Element:C,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.moduleName+":",e=0;r=!1,clearTimeout(b.performance.timer),a.each(s,function(a,b){e+=b["Execution Time"]}),c+=" "+e+"ms",q&&(c+=" '"+q+"'"),(console.group!==d||console.table!==d)&&s.length>0&&(console.groupCollapsed(c),console.table?console.table(s):a.each(s,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),s=[]}},invoke:function(c,e,f){var g,h;return e=e||v,f=C||f,"string"==typeof c&&D!==d&&(c=c.split(/[\. ]/),g=c.length-1,a.each(c,function(c,e){a.isPlainObject(D[e])&&c!=g?D=D[e]:D[e]!==d?h=D[e]:b.error(n.method)})),a.isFunction(h)?h.apply(f,e):h||!1}},u?(D===d&&b.initialize(),e=b.invoke(t)):(D!==d&&b.destroy(),b.initialize())}),e?e:this},a.fn.dropdown.settings={moduleName:"Dropdown",namespace:"dropdown",verbose:!0,debug:!0,performance:!0,on:"click",action:"hide",delay:{show:50,hide:300},animation:{show:"slide",hide:"slide"},onChange:function(){},onShow:function(){},onHide:function(){},errors:{action:"You called a dropdown action that was not defined",method:"The method you called is not defined.",animation:"The requested animation 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);