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

11 lines
7.8 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
2023-08-17 09:47:40 +00:00
* # Fomantic UI - 2.9.2
2022-01-13 13:00:31 +00:00
* https://github.com/fomantic/Fomantic-UI
2023-08-17 09:47:40 +00:00
* https://fomantic-ui.com/
2022-01-13 13:00:31 +00:00
*
2023-08-17 09:47:40 +00:00
* Copyright 2023 Contributors
2022-01-13 13:00:31 +00:00
* Released under the MIT license
2023-08-17 09:47:40 +00:00
* https://opensource.org/licenses/MIT
2022-01-13 13:00:31 +00:00
*
*/
2023-08-17 09:47:40 +00:00
!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}},flas