wishthis/node_modules/fomantic-ui/dist/components/state.min.js

11 lines
No EOL
7.8 KiB
JavaScript

/*
* # Fomantic UI - 2.9.3
* https://github.com/fomantic/Fomantic-UI
* https://fomantic-ui.com/
*
* Copyright 2023 Contributors
* Released under the MIT license
* https://opensource.org/licenses/MIT
*
*/
!function(C,A,a){"use strict";A=void 0!==A&&A.Math===Math?A:globalThis,C.fn.state=function(g){var b,x=C(this),p=Date.now(),m=[],h=g,T="string"==typeof h,y=[].slice.call(arguments,1),w=function(e,t){var n;return 0<=[A,a].indexOf(e)?n=C(e):0===(n=C(t.document).find(e)).length&&(n=t.frameElement?w(e,t.parent):A),n};return x.each(function(){var i=C.isPlainObject(g)?C.extend(!0,{},C.fn.state.settings,g):C.extend({},C.fn.state.settings),c=i.error,n=i.metadata,t=i.className,e=i.namespace,a=i.states,o=i.text,s="."+e,r=e+"-module",l=C(this),u=i.context?w(i.context,A):l,d=this,f=l.data(r),v={initialize:function(){v.verbose("Initializing module"),i.automatic&&v.add.defaults(),u.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),f=v,l.data(r,v)},destroy:function(){v.verbose("Destroying previous module",f),u.off(s),l.removeData(n.storedText).removeData(r)},refresh:function(){v.verbose("Refreshing selector cache"),l=C(d)},add:{defaults:function(){var n=g&&C.isPlainObject(g.states)?g.states:{};C.each(i.defaults,function(e,t){void 0!==v.is[e]&&v.is[e]()&&(v.verbose("Adding default states",e,d),C.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!==C.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),C.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(d)},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(d)&&(v.debug("Setting state to active"),l.addClass(t.active),v.update.text(o.active),i.onActivate.call(d))},deactivate:function(){i.deactivateTest.call(d)&&(v.debug("Setting state to inactive"),l.removeClass(t.active),v.update.text(o.inactive),i.onDeactivate.call(d))},sync:function(){v.verbose("Syncing other buttons to current state"),v.is.active()?x.not(l).state("activate"):x.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(d)},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),C.isPlainObject(e))C.extend(!0,i,e);else{if(void 0===t)return i[e];C.isPlainObject(i[e])?C.extend(!0,i[e],t):i[e]=t}},internal:function(e,t){if(C.isPlainObject(e))C.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:d,"Execution Time":n})),clearTimeout(v.performance.timer),v.performance.timer=setTimeout(function(){v.performance.display()},500)},display:function(){var e=i.name+":",n=0;p=!1,clearTimeout(v.performance.timer),C.each(m,function(e,t){n+=t["Execution Time"]}),e+=" "+n+"ms",0<m.length&&(console.groupCollapsed(e),console.table?console.table(m):C.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,r=f;return e=e||y,t=t||d,"string"==typeof a&&void 0!==r&&(a=a.split(/[ .]/),i=a.length-1,C.each(a,function(e,t){var n=e!==i?t+a[e+1].charAt(0).toUpperCase()+a[e+1].slice(1):a;if(C.isPlainObject(r[n])&&e!==i)r=r[n];else{if(void 0!==r[n])return o=r[n],!1;{if(!C.isPlainObject(r[t])||e===i)return void 0!==r[t]?o=r[t]:v.error(c.method,a),!1;r=r[t]}}})),"function"==typeof(s=o)&&"number"!=typeof s.nodeType?n=o.apply(t,e):void 0!==o&&(n=o),Array.isArray(b)?b.push(n):void 0!==b?b=[b,n]:void 0!==n&&(b=n),o}};T?(void 0===f&&v.initialize(),v.invoke(h)):(void 0!==f&&f.invoke("destroy"),v.initialize())}),void 0!==b?b:this},C.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);