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