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.

0 lines
7.4 KiB

  1. !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.errors,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,v=a(this),w=a(this).find(l.menu),x=a(this).find(l.item),y=a(this).find(l.text),z=a(this).find(l.input),A="ontouchstart"in c.documentElement,B=this,C=v.data(o);b={initialize:function(){b.debug("Initializing dropdown with bound events",v),A?v.on("touchstart"+n,b.event.test.toggle):"click"==h.on?v.on("click"+n,b.event.test.toggle):"hover"==h.on?v.on("mouseenter"+n,b.delay.show).on("mouseleave"+n,b.delay.hide):v.on(h.on+n,b.toggle),"form"==h.action&&b.set.selected(),x.on(b.get.selectEvent()+n,b.event.item.click),b.instantiate()},instantiate:function(){b.verbose("Storing instance of module",b),v.data(o,b)},destroy:function(){b.verbose("Destroying previous module for",v),v.off(k).removeData(o)},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"),x.removeClass(i.active),d.addClass(i.active),b.action.determine(e,f),a.proxy(h.onChange,v.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(w).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(m.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 A?"touchstart":"click"},text:function(){return y.text()},value:function(){return z.val()},item:function(b){var c;return b=b||z.val(),x.each(function(){a(this).data(j.value)==b&&(c=a(this))}),c||!1}},set:{text:function(a){b.debug("Changing text",a,y),y.removeClass(i.placeholder),y.text(a)},value:function(a){b.debug("Adding selected value to hidden input",a,z),z.val(a)},visible:function(){v.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(),x.removeClass(i.active),d.addClass(i.active),b.set.text(c))}},remove:{visible:function(){v.removeClass(i.visible)}},is:{visible:function(){return w.is(":visible")},hidden:function(){return w.is(":not(:visible)")}},can:{click:function(){return A||"click"==h.on},show:function(){return!v.hasClass(i.disabled)}},animate:{show:function(c){b.verbose("Doing menu showing animation"),c=c||function(){},"none"==h.animation?c():a.fn.transition!==d?w.transition(h.animation,h.duration,c):"slide down"==h.animation?w.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.animation?w.hide().clearQueue().fadeIn(h.duration,function(){a.proxy(b.event.resetStyle,this)(),c()}):b.error(m.animation)},hide:function(c){b.verbose("Doing menu hiding animation"),c=c||function(){},"none"==h.animation?c():a.fn.transition!==d?w.transition(h.animation,h.duration,c):"slide down"==h.animation?w.show().clearQueue().children().clearQueue().css("o