!function(a,b,c,d){a.fn.state=function(b){var e,f=a(this),g=a.extend(!0,{},a.fn.state.settings,b),h=f.selector||"",i=("ontouchstart"in c.documentElement,(new Date).getTime()),j=[],k=arguments[0],l="string"==typeof k,m=[].slice.call(arguments,1),n=(g.error,g.metadata),o=g.className,p=g.namespace,q=g.states,r=g.text,s="."+p,t=p+"-module";return f.each(function(){var c,p=a(this),u=this,v=p.data(t);c={initialize:function(){c.verbose("Initializing module"),g.automatic&&c.add.defaults(),g.context&&""!==h?a(g.context).on(h,"mouseenter"+s,c.change.text).on(h,"mouseleave"+s,c.reset.text).on(h,"click"+s,c.toggle.state):p.on("mouseenter"+s,c.change.text).on("mouseleave"+s,c.reset.text).on("click"+s,c.toggle.state),c.instantiate()},instantiate:function(){c.verbose("Storing instance of module",c),v=c,p.data(t,c)},destroy:function(){c.verbose("Destroying previous module",v),p.off(s).removeData(t)},refresh:function(){c.verbose("Refreshing selector cache"),p=a(u)},add:{defaults:function(){var e=b&&a.isPlainObject(b.states)?b.states:{};a.each(g.defaults,function(b,f){c.is[b]!==d&&c.is[b]()&&(c.verbose("Adding default states",b,u),a.extend(g.states,f,e))})}},is:{active:function(){return p.hasClass(o.active)},loading:function(){return p.hasClass(o.loading)},inactive:function(){return!p.hasClass(o.active)},state:function(a){return o[a]===d?!1:p.hasClass(o[a])},enabled:function(){return!p.is(g.filter.active)},disabled:function(){return p.is(g.filter.active)},textEnabled:function(){return!p.is(g.filter.text)},button:function(){return p.is(".button:not(a, .submit)")},input:function(){return p.is("input")},progress:function(){return p.is(".ui.progress")}},allow:function(a){c.debug("Now allowing state",a),q[a]=!0},disallow:function(a){c.debug("No longer allowing",a),q[a]=!1},allows:function(a){return q[a]||!1},enable:function(){p.removeClass(o.disabled)},disable:function(){p.addClass(o.disabled)},setState:function(a){c.allows(a)&&p.addClass(o[a])},removeState:function(a){c.allows(a)&&p.removeClass(o[a])},toggle:{state:function(){var b;if(c.allows("active")&&c.is.enabled()){if(c.refresh(),a.fn.api!==d&&(b=p.api("get request")))return void c.listenTo(b);c.change.state()}}},listenTo:function(b){c.debug("API request detected, waiting for state signal",b),b?(r.loading&&c.update.text(r.loading),a.when(b).then(function(){"resolved"==b.state()?(c.debug("API request succeeded"),g.activateTest=function(){return!0},g.deactivateTest=function(){return!0}):(c.debug("API request failed"),g.activateTest=function(){return!1},g.deactivateTest=function(){return!1}),c.change.state()})):(g.activateTest=function(){return!1},g.deactivateTest=function(){return!1})},change:{state:function(){c.debug("Determining state change direction"),c.is.inactive()?c.activate():c.deactivate(),g.sync&&c.sync(),a.proxy(g.onChange,u)()},text:function(){c.is.textEnabled()&&(c.is.disabled()?(c.verbose("Changing text to disabled text",r.hover),c.update.text(r.disabled)):c.is.active()?r.hover?(c.verbose("Changing text to hover text",r.hover),c.update.text(r.hover)):r.disable&&(c.verbose("Changing text to disable text",r.disable),c.update.text(r.disable)):r.hover?(c.verbose("Changing text to hover text",r.disable),c.update.text(r.hover)):r.enable&&(c.verbose("Changing text to enable text",r.enable),c.update.text(r.enable)))}},activate:function(){a.proxy(g.activateTest,u)()&&(c.debug("Setting state to active"),p.addClass(o.active),c.update.text(r.active)),a.proxy(g.onActivate,u)()},deactivate:function(){a.proxy(g.deactivateTest,u)()&&(c.debug("Setting state to inactive"),p.removeClass(o.active),c.update.text(r.inactive)),a.proxy(g.onDeactivate,u)()},sync:function(){c.verbose("Syncing other buttons to current state"),f.not(p).state(c.is.active()?"activate":"deactivate")},get:{text:function(){return g.selector.text?p.find(g.selector.text).text():p.html()},textFor:function(a){return r[a]||!1}},flash:{text:function(b,d,e){var f=c.get.text();c.debug("Flashing text message",b,d),b=b||g.text.flash,d=d||g.flashDuration,e=e||function(){},c.update.text(b),setTimeout(function(){c.update.text(f),a.proxy(e,u)()},d)}},reset:{text:function(){var a=r.active||p.data(n.storedText),b=r.inactive||p.data(n.storedText);c.is.textEnabled()&&(c.is.active()&&a?(c.verbose("Resetting active text",a),c.update.text(a)):b&&(c.verbose("Resetting inactive text",a),c.update.text(b)))}},update:{text:function(a){var b=c.get.text();a&&a!==b?(c.debug("Updating text",a),g.selector.text?p.data(n.storedText,a).find(g.selector.text).text(a):p.data(n.storedText,a).html(a)):c.debug("Text is already sane, ignoring update",a)}},setting:function(b,e){return c.debug("Changing setting",b,e),e===d?g[b]:void(a.isPlainObject(b)?a.extend(!0,g,b):g[b]=e)},internal:function(b,e){return c.debug("Changing internal",b,e),e===d?c[b]:void(a.isPlainObject(b)?a.extend(!0,c,b):c[b]=e)},debug:function(){g.debug&&(g.performance?c.performance.log(arguments):(c.debug=Function.prototype.bind.call(console.info,console,g.name+":"),c.debug.apply(console,arguments)))},verbose:function(){g.verbose&&g.debug&&(g.performance?c.performance.log(arguments):(c.verbose=Function.prototype.bind.call(console.info,console,g.name+":"),c.verbose.apply(console,arguments)))},error:function(){c.error=Function.prototype.bind.call(console.error,console,g.name+":"),c.error.apply(console,arguments)},performance:{log:function(a){var b,d,e;g.performance&&(b=(new Date).getTime(),e=i||b,d=b-e,i=b,j.push({Element:u,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":d})),clearTimeout(c.performance.timer),c.performance.timer=setTimeout(c.performance.display,100)},display:function(){var b=g.name+":",e=0;i=!1,clearTimeout(c.performance.timer),a.each(j,function(a,b){e+=b["Execution Time"]}),b+=" "+e+"ms",h&&(b+=" '"+h+"'"),f.size()>1&&(b+=" ("+f.size()+")"),(console.group!==d||console.table!==d)&&j.length>0&&(console.groupCollapsed(b),console.table?console.table(j):a.each(j,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),j=[]}},invoke:function(b,c,f){var g,h,i,j=v;return c=c||m,f=u||f,"string"==typeof b&&j!==d&&(b=b.split(/[\. ]/),g=b.length-1,a.each(b,function(c,e){var f=c!=g?e+b[c+1].charAt(0).toUpperCase()+b[c+1].slice(1):b;if(a.isPlainObject(j[f])&&c!=g)j=j[f];else{if(j[f]!==d)return h=j[f],!1;if(!a.isPlainObject(j[e])||c==g)return j[e]!==d?(h=j[e],!1):!1;j=j[e]}})),a.isFunction(h)?i=h.apply(f,c):h!==d&&(i=h),a.isArray(e)?e.push(i):e!==d?e=[e,i]:i!==d&&(e=i),h}},l?(v===d&&c.initialize(),c.invoke(k)):(v!==d&&c.destroy(),c.initialize())}),e!==d?e:this},a.fn.state.settings={name:"State",debug:!1,verbose:!0,namespace:"state",performance:!0,onActivate:function(){},onDeactivate:function(){},onChange:function(){},activateTest:function(){return!0},deactivateTest:function(){return!0},automatic:!0,sync:!1,flashDuration:3e3,filter:{text:".loading, .disabled",active:".disabled"},context:!1,error:{method:"The method you called is not defined."},metadata:{promise:"promise",storedText:"stored-text"},className:{active:"active",disabled:"disabled",error:"error",loading:"loading",success:"success",warning:"warning"},selector:{text:!1},defaults:{input:{disabled:!0,loading:!0,active:!0},button:{disabled:!0,loading:!0,active:!0},progress:{active:!0,success:!0,warning:!0,error:!0}},states:{active:!0,disabled:!0,error:!0,loading:!0,success:!0,warning:!0},text:{disabled:!1,flash:!1,hover:!1,active:!1,inactive:!1,enable:!1,disable:!1}}}(jQuery,window,document);