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.
 
 
 

1 lines
7.3 KiB

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