|
|
!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(:anima
|