|
|
(function(e,t,n,a){e.fn.state=function(t){var n,o=e(this),i=o.selector||"",r=arguments[0],s=[].slice.call(arguments,1),l=(new Date).getTime(),c=[];return o.each(function(){var u,d=e(this),f=e.extend(!0,{},e.fn.state.settings,t),g=this,m=d.data("module-"+f.namespace),p="string"==typeof r,v=f.namespace,h=f.metadata,b=f.className,x=f.states,y=f.text;u={initialize:function(){u.verbose("Initializing module",g),f.automatic&&u.add.defaults(),f.context&&""!==i?(u.allows("hover")&&e(g,f.context).on(i,"mouseenter."+v,u.hover.enable).on(i,"mouseleave."+v,u.hover.disable),u.allows("pressed")&&e(g,f.context).on(i,"mousedown."+v,u.pressed.enable).on(i,"mouseup."+v,u.pressed.disable),u.allows("focus")&&e(g,f.context).on(i,"focus."+v,u.focus.enable).on(i,"blur."+v,u.focus.disable),e(f.context).on(i,"mouseenter."+v,u.text.change).on(i,"mouseleave."+v,u.text.reset).on(i,"click."+v,u.toggle)):(u.allows("hover")&&d.on("mouseenter."+v,u.hover.enable).on("mouseleave."+v,u.hover.disable),u.allows("pressed")&&d.on("mousedown."+v,u.pressed.enable).on("mouseup."+v,u.pressed.disable),u.allows("focus")&&d.on("focus."+v,u.focus.enable).on("blur."+v,u.focus.disable),d.on("mouseenter."+v,u.text.change).on("mouseleave."+v,u.text.reset).on("click."+v,u.toggle)),d.data("module-"+v,u)},destroy:function(){u.verbose("Destroying previous module",g),d.off("."+v)},refresh:function(){u.verbose("Refreshing selector cache",g),d=e(g)},add:{defaults:function(){var n=t&&e.isPlainObject(t.states)?t.states:{};e.each(f.defaults,function(t,o){u.is[t]!==a&&u.is[t]()&&(u.verbose("Adding default states",t,g),e.extend(f.states,o,n))})}},is:{active:function(){return d.hasClass(b.active)},loading:function(){return d.hasClass(b.loading)},inactive:function(){return!d.hasClass(b.active)},enabled:function(){return!d.is(f.filter.active)},disabled:function(){return d.is(f.filter.active)},textEnabled:function(){return!d.is(f.filter.text)},button:function(){return d.is(".button:not(a, .submit)")},input:function(){return d.is("input")}},allows:function(e){return x[e]||!1},enable:function(e){u.allows(e)&&d.addClass(b[e])},disable:function(e){u.allows(e)&&d.removeClass(b[e])},textFor:function(e){return y[e]||!1},focus:{enable:function(){d.addClass(b.focus)},disable:function(){d.removeClass(b.focus)}},hover:{enable:function(){d.addClass(b.hover)},disable:function(){d.removeClass(b.hover)}},pressed:{enable:function(){d.addClass(b.pressed).one("mouseleave",u.pressed.disable)},disable:function(){d.removeClass(b.pressed)}},toggle:function(){var e=d.data(h.promise);u.allows("active")&&u.is.enabled()&&(u.refresh(),e!==a?u.listenTo(e):u.change())},listenTo:function(t){u.debug("API request detected, waiting for state signal",t),t?(y.loading&&u.text.update(y.loading),e.when(t).then(function(){"resolved"==t.state()?(u.debug("API request succeeded"),f.activateTest=function(){return!0},f.deactivateTest=function(){return!0}):(u.debug("API request failed"),f.activateTest=function(){return!1},f.deactivateTest=function(){return!1}),u.change()})):(f.activateTest=function(){return!1},f.deactivateTest=function(){return!1})},change:function(){u.debug("Determining state change direction"),u.is.inactive()?u.activate():u.deactivate(),f.sync&&u.sync(),f.onChange()},activate:function(){e.proxy(f.activateTest,g)()&&(u.debug("Setting state to active"),d.addClass(b.active),u.text.update(y.active))},deactivate:function(){e.proxy(f.deactivateTest,g)()&&(u.debug("Setting state to inactive"),d.removeClass(b.active),u.text.update(y.inactive))},sync:function(){u.verbose("Syncing other buttons to current state"),u.is.active()?o.not(d).state("activate"):o.not(d).state("deactivate")},text:{get:function(){return f.selector.text?d.find(f.selector.text).text():d.html()},flash:function(e,t){var n=u.text.get();e=e||f.text.flash,t=t||f.flashDuration,u.text.update(e),setTimeout(function(){u.text.update(n)},t)},change:function(){u.verbose("Checking if text should be changed"),u.is.textEnabled()&&(u.is.active()?y.hover?(u.verbose("Changing text to hover text",y.hover),u.text.update(y.hover)):y.disable&&(u.verbose("Changing text to
|