|
|
!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,k=a(this),v=k.find(l.item),w=k.find(l.text),x=k.find(l.input),y=k.children(l.menu),z="ontouchstart"in c.documentElement,A=this,B=k.data(o);b={initialize:function(){b.debug("Initializing dropdown",h),z?k.on("touchstart"+n,b.event.test.toggle):"click"==h.on?k.on("click"+n,b.event.test.toggle):"hover"==h.on?k.on("mouseenter"+n,b.delay.show).on("mouseleave"+n,b.delay.hide):k.on(h.on+n,b.toggle),"form"==h.action&&b.set.selected(),v.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),k.data(o,b)},destroy:function(){b.verbose("Destroying previous dropdown for",k),v.off(n),k.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;0===d.find(l.menu).size()&&(b.verbose("Adding active state to selected item"),v.removeClass(i.active),d.addClass(i.active),b.determine.selectAction(e,f),a.proxy(h.onChange,A)(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(y).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 z?"touchstart":"click"},text:function(){return w.text()},value:function(){return x.val()},item:function(b){var c;return b=b||x.val(),v.each(function(){a(this).data(j.value)==b&&(c=a(this))}),c||!1}},set:{text:function(a){b.debug("Changing text",a,w),w.removeClass(i.placeholder),w.text(a)},value:function(a){b.debug("Adding selected value to hidden input",a,x),x.val(a)},active:function(){k.addClass(i.active)},visible:function(){k.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(),v.removeClass(i.active),d.addClass(i.active),b.set.text(c))}},remove:{active:function(){k.removeClass(i.active)},visible:function(){k.removeClass(i.visible)}},is:{visible:function(a){return a?a.is(":visible"):y.is(":visible")},hidden:function(a){return a?a.is(":not(:visible)"):y.is(":not(:visible)")}},can:{click:function(){return z||"click"==h.on},show:function(){return!k.hasClass(i.disabled)}},animate:{show:function(c,e){var f=e||y;c=c||function(){},b.is.hidden(f)&&(b.
|