11 lines
No EOL
7.8 KiB
JavaScript
11 lines
No EOL
7.8 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.2
|
|
* https://github.com/fomantic/Fomantic-UI
|
|
* https://fomantic-ui.com/
|
|
*
|
|
* Copyright 2023 Contributors
|
|
* Released under the MIT license
|
|
* https://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(w,C,A){"use strict";C=void 0!==C&&C.Math===Math?C:globalThis,w.fn.state=function(f){var g,b=w(this),x=b.selector||"",p=Date.now(),m=[],h=f,y="string"==typeof h,T=[].slice.call(arguments,1);return b.each(function(){var i=w.isPlainObject(f)?w.extend(!0,{},w.fn.state.settings,f):w.extend({},w.fn.state.settings),r=i.error,n=i.metadata,t=i.className,e=i.namespace,a=i.states,o=i.text,s="."+e,c=e+"-module",l=w(this),u=this,d=l.data(c),v={initialize:function(){v.verbose("Initializing module"),i.automatic&&v.add.defaults(),i.context&&""!==x?([C,A].indexOf(i.context)<0?w(A).find(i.context):w(i.context)).on(x,"mouseenter"+s,v.change.text).on(x,"mouseleave"+s,v.reset.text).on(x,"click"+s,v.toggle.state):l.on("mouseenter"+s,v.change.text).on("mouseleave"+s,v.reset.text).on("click"+s,v.toggle.state),v.instantiate()},instantiate:function(){v.verbose("Storing instance of module",v),d=v,l.data(c,v)},destroy:function(){v.verbose("Destroying previous module",d),l.off(s).removeData(c)},refresh:function(){v.verbose("Refreshing selector cache"),l=w(u)},add:{defaults:function(){var n=f&&w.isPlainObject(f.states)?f.states:{};w.each(i.defaults,function(e,t){void 0!==v.is[e]&&v.is[e]()&&(v.verbose("Adding default states",e,u),w.extend(i.states,t,n))})}},is:{active:function(){return l.hasClass(t.active)},loading:function(){return l.hasClass(t.loading)},inactive:function(){return!l.hasClass(t.active)},state:function(e){return void 0!==t[e]&&l.hasClass(t[e])},enabled:function(){return!l.is(i.filter.active)},disabled:function(){return l.is(i.filter.active)},textEnabled:function(){return!l.is(i.filter.text)},button:function(){return l.is(".button:not(a, .submit)")},input:function(){return l.is("input")},progress:function(){return l.is(".ui.progress")}},allow:function(e){v.debug("Now allowing state",e),a[e]=!0},disallow:function(e){v.debug("No longer allowing",e),a[e]=!1},allows:function(e){return a[e]||!1},enable:function(){l.removeClass(t.disabled)},disable:function(){l.addClass(t.disabled)},setState:function(e){v.allows(e)&&l.addClass(t[e])},removeState:function(e){v.allows(e)&&l.removeClass(t[e])},toggle:{state:function(){var e;if(v.allows("active")&&v.is.enabled()){if(v.refresh(),void 0!==w.fn.api)if(e=l.api("get request"),l.api("was cancelled"))v.debug("API Request cancelled by beforesend"),i.activateTest=function(){return!1},i.deactivateTest=function(){return!1};else if(e)return void v.listenTo(e);v.change.state()}}},listenTo:function(e){v.debug("API request detected, waiting for state signal",e),e&&(o.loading&&v.update.text(o.loading),w.when(e).then(function(){"resolved"===e.state()?(v.debug("API request succeeded"),i.activateTest=function(){return!0},i.deactivateTest=function(){return!0}):(v.debug("API request failed"),i.activateTest=function(){return!1},i.deactivateTest=function(){return!1}),v.change.state()}))},change:{state:function(){v.debug("Determining state change direction"),v.is.inactive()?v.activate():v.deactivate(),i.sync&&v.sync(),i.onChange.call(u)},text:function(){v.is.textEnabled()&&(v.is.disabled()?(v.verbose("Changing text to disabled text",o.hover),v.update.text(o.disabled)):v.is.active()?o.hover?(v.verbose("Changing text to hover text",o.hover),v.update.text(o.hover)):o.deactivate&&(v.verbose("Changing text to deactivating text",o.deactivate),v.update.text(o.deactivate)):o.hover?(v.verbose("Changing text to hover text",o.hover),v.update.text(o.hover)):o.activate&&(v.verbose("Changing text to activating text",o.activate),v.update.text(o.activate)))}},activate:function(){i.activateTest.call(u)&&(v.debug("Setting state to active"),l.addClass(t.active),v.update.text(o.active),i.onActivate.call(u))},deactivate:function(){i.deactivateTest.call(u)&&(v.debug("Setting state to inactive"),l.removeClass(t.active),v.update.text(o.inactive),i.onDeactivate.call(u))},sync:function(){v.verbose("Syncing other buttons to current state"),v.is.active()?b.not(l).state("activate"):b.not(l).state("deactivate")},get:{text:function(){return i.selector.text?l.find(i.selector.text).text():l.html()},textFor:function(e){return o[e]||!1}},flash:{text:function(e,t,n){var a=v.get.text();v.debug("Flashing text message",e,t),e=e||i.text.flash,t=t||i.flashDuration,n=n||function(){},v.update.text(e),setTimeout(function(){v.update.text(a),n.call(u)},t)}},reset:{text:function(){var e=o.active||l.data(n.storedText),t=o.inactive||l.data(n.storedText);v.is.textEnabled()&&(v.is.active()&&e?(v.verbose("Resetting active text",e),v.update.text(e)):t&&(v.verbose("Resetting inactive text",e),v.update.text(t)))}},update:{text:function(e){var t=v.get.text();e&&e!==t?(v.debug("Updating text",e),i.selector.text?l.data(n.storedText,e).find(i.selector.text).text(e):l.data(n.storedText,e).html(e)):v.debug("Text is already set, ignoring update",e)}},setting:function(e,t){if(v.debug("Changing setting",e,t),w.isPlainObject(e))w.extend(!0,i,e);else{if(void 0===t)return i[e];w.isPlainObject(i[e])?w.extend(!0,i[e],t):i[e]=t}},internal:function(e,t){if(w.isPlainObject(e))w.extend(!0,v,e);else{if(void 0===t)return v[e];v[e]=t}},debug:function(){!i.silent&&i.debug&&(i.performance?v.performance.log(arguments):(v.debug=Function.prototype.bind.call(console.info,console,i.name+":"),v.debug.apply(console,arguments)))},verbose:function(){!i.silent&&i.verbose&&i.debug&&(i.performance?v.performance.log(arguments):(v.verbose=Function.prototype.bind.call(console.info,console,i.name+":"),v.verbose.apply(console,arguments)))},error:function(){i.silent||(v.error=Function.prototype.bind.call(console.error,console,i.name+":"),v.error.apply(console,arguments))},performance:{log:function(e){var t,n;i.performance&&(n=(t=Date.now())-(p||t),p=t,m.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:u,"Execution Time":n})),clearTimeout(v.performance.timer),v.performance.timer=setTimeout(v.performance.display,500)},display:function(){var e=i.name+":",n=0;p=!1,clearTimeout(v.performance.timer),w.each(m,function(e,t){n+=t["Execution Time"]}),e+=" "+n+"ms",x&&(e+=" '"+x+"'"),0<m.length&&(console.groupCollapsed(e),console.table?console.table(m):w.each(m,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),m=[]}},invoke:function(a,e,t){var i,o,n,s,c=d;return e=e||T,t=t||u,"string"==typeof a&&void 0!==c&&(a=a.split(/[ .]/),i=a.length-1,w.each(a,function(e,t){var n=e!==i?t+a[e+1].charAt(0).toUpperCase()+a[e+1].slice(1):a;if(w.isPlainObject(c[n])&&e!==i)c=c[n];else{if(void 0!==c[n])return o=c[n],!1;{if(!w.isPlainObject(c[t])||e===i)return void 0!==c[t]?o=c[t]:v.error(r.method,a),!1;c=c[t]}}})),"function"==typeof(s=o)&&"number"!=typeof s.nodeType?n=o.apply(t,e):void 0!==o&&(n=o),Array.isArray(g)?g.push(n):void 0!==g?g=[g,n]:void 0!==n&&(g=n),o}};y?(void 0===d&&v.initialize(),v.invoke(h)):(void 0!==d&&d.invoke("destroy"),v.initialize())}),void 0!==g?g:this},w.fn.state.settings={name:"State",debug:!1,verbose:!1,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); |