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

  1. (function(e,t,n,o){e.fn.dropdown=function(t){var i,a=e(this),s=e(n),r=e.isPlainObject(t)?e.extend(!0,{},e.fn.dropdown.settings,t):e.fn.dropdown.settings,c="."+r.namespace,l="module-"+r.namespace,u=a.selector||"",d=(new Date).getTime(),m=[],f=arguments[0],g="string"==typeof f,p=[].slice.call(arguments,1);return a.each(function(){var t,h=e(this),v=e(this).find(r.selector.menu),b=e(this).find(r.selector.item),y=e(this).find(r.selector.text),x=e(this).find(r.selector.input),C="ontouchstart"in n.documentElement,w=(h.selector||"",this),T=h.data("module-"+r.namespace),k=r.className,N=r.metadata,z=r.namespace,E=r.animation,D=r.errors;t={initialize:function(){t.verbose("Initializing dropdown with bound events",h),C?h.on("touchstart"+c,t.event.test.toggle):"click"==r.on?h.on("click"+c,t.event.test.toggle):"hover"==r.on?h.on("mouseenter"+c,t.show).on("mouseleave"+c,t.delayedHide):h.on(r.on+c,t.toggle),"form"==r.action&&t.set.selected(),b.on(t.get.selectEvent()+c,t.event.item.click),h.data(l,t)},destroy:function(){t.verbose("Destroying previous module for",h),h.off(z)},event:{stopPropagation:function(e){e.stopPropagation()},test:{toggle:function(e){t.intent.test(e,t.toggle),e.stopPropagation()},hide:function(e){t.intent.test(e,t.hide),e.stopPropagation()}},item:{click:function(n){var o=e(this),i=o.data(N.text)||o.text(),a=o.data(N.value)||i;t.verbose("Adding active state to selected item"),b.removeClass(k.active),o.addClass(k.active),t.action.determine(i,a),e.proxy(r.onChange,h.get())(a,i),n.stopPropagation()}}},intent:{test:function(n,o){t.debug("Determining whether event occurred in dropdown",n.target),o=o||function(){},0===e(n.target).closest(v).size()?(t.verbose("Triggering event",o),o()):t.verbose("Event occurred in dropdown, canceling callback")},bind:function(){t.verbose("Binding hide intent event to document"),s.on(t.get.selectEvent(),t.event.test.hide)},unbind:function(){t.verbose("Removing hide intent event from document"),s.off(t.get.selectEvent())}},action:{determine:function(n,o){e.isFunction(t.action[r.action])?(t.verbose("Triggering preset action",r.action),t.action[r.action](n,o)):e.isFunction(r.action)?(t.verbose("Triggering user action",r.action),r.action(n,o)):t.error(D.action)},none:function(){},hide:function(){t.hide()},changeText:function(e){t.set.text(e),t.hide()},form:function(e,n){t.set.text(e),t.set.value(n),t.hide()}},get:{selectEvent:function(){return C?"touchstart":"click"},text:function(){return y.text()},value:function(){return x.val()},item:function(t){var n;return t=t||x.val(),b.each(function(){e(this).data(N.value)==t&&(n=e(this))}),n||!1}},set:{text:function(e){t.debug("Changing text",e,y),y.removeClass(k.placeholder),y.text(e)},value:function(e){t.debug("Adding selected value to hidden input",e,x),x.val(e)},selected:function(e){var n,o=(e||x.val(),t.get.item(e));o&&(t.debug("Setting selected menu item to",o),n=o.data(N.text)||o.text(),b.removeClass(k.active),o.addClass(k.active),t.set.text(n))}},is:{visible:function(){return v.is(":visible")},hidden:function(){return v.is(":not(:visible)")}},can:{click:function(){return C||"click"==r.on},show:function(){return!h.hasClass(k.disabled)}},animate:{show:function(){t.verbose("Doing menu showing animation"),"none"==E.show?v.show():"fade"==E.show?v.fadeIn(150):"slide"==E.show?v.clearQueue().children().clearQueue().css("opacity",0).delay(50).animate({opacity:1},200,"easeOutQuad").end().slideDown(100,"easeOutQuad"):t.error(D.animation)},hide:function(){t.verbose("Doing menu hiding animation"),"none"==E.hide?v.hide():"fade"==E.hide?v.fadeOut(150):"slide"==E.hide?v.clearQueue().children().clearQueue().css("opacity",1).animate({opacity:0},100,"easeOutQuad").end().delay(50).slideUp(100,"easeOutQuad"):t.error(D.animation)}},show:function(){t.debug("Checking if dropdown can show"),clearTimeout(t.graceTimer),t.is.visible()||(t.hideOthers(),h.addClass(k.visible),t.animate.show(),t.can.click()&&t.intent.bind(),e.proxy(r.onShow,h.get())())},hide:function(){t.is.hidden()||(t.debug("Hiding dropdown"),h.removeClass(k.visible),t.can.click()&&t.intent.unbind(),t.animate.