11 lines
7.9 KiB
JavaScript
11 lines
7.9 KiB
JavaScript
|
/*
|
||
|
* # Fomantic UI - 2.8.8
|
||
|
* https://github.com/fomantic/Fomantic-UI
|
||
|
* http://fomantic-ui.com/
|
||
|
*
|
||
|
* Copyright 2021 Contributors
|
||
|
* Released under the MIT license
|
||
|
* http://opensource.org/licenses/MIT
|
||
|
*
|
||
|
*/
|
||
|
!function(w,e,t,C){"use strict";w.isFunction=w.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},e=void 0!==e&&e.Math==Math?e:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),w.fn.state=function(v){var g,b=w(this),x=b.selector||"",p=(new Date).getTime(),h=[],m=v,T="string"==typeof m,y=[].slice.call(arguments,1);return b.each(function(){var c,i=w.isPlainObject(v)?w.extend(!0,{},w.fn.state.settings,v):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,l=e+"-module",u=w(this),d=this,f=u.data(l);c={initialize:function(){c.verbose("Initializing module"),i.automatic&&c.add.defaults(),i.context&&""!==x?w(i.context).on(x,"mouseenter"+s,c.change.text).on(x,"mouseleave"+s,c.reset.text).on(x,"click"+s,c.toggle.state):u.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),f=c,u.data(l,c)},destroy:function(){c.verbose("Destroying previous module",f),u.off(s).removeData(l)},refresh:function(){c.verbose("Refreshing selector cache"),u=w(d)},add:{defaults:function(){var n=v&&w.isPlainObject(v.states)?v.states:{};w.each(i.defaults,function(e,t){c.is[e]!==C&&c.is[e]()&&(c.verbose("Adding default states",e,d),w.extend(i.states,t,n))})}},is:{active:function(){return u.hasClass(t.active)},loading:function(){return u.hasClass(t.loading)},inactive:function(){return!u.hasClass(t.active)},state:function(e){return t[e]!==C&&u.hasClass(t[e])},enabled:function(){return!u.is(i.filter.active)},disabled:function(){return u.is(i.filter.active)},textEnabled:function(){return!u.is(i.filter.text)},button:function(){return u.is(".button:not(a, .submit)")},input:function(){return u.is("input")},progress:function(){return u.is(".ui.progress")}},allow:function(e){c.debug("Now allowing state",e),a[e]=!0},disallow:function(e){c.debug("No longer allowing",e),a[e]=!1},allows:function(e){return a[e]||!1},enable:function(){u.removeClass(t.disabled)},disable:function(){u.addClass(t.disabled)},setState:function(e){c.allows(e)&&u.addClass(t[e])},removeState:function(e){c.allows(e)&&u.removeClass(t[e])},toggle:{state:function(){var e;if(c.allows("active")&&c.is.enabled()){if(c.refresh(),w.fn.api!==C)if(e=u.api("get request"),u.api("was cancelled"))c.debug("API Request cancelled by beforesend"),i.activateTest=function(){return!1},i.deactivateTest=function(){return!1};else if(e)return void c.listenTo(e);c.change.state()}}},listenTo:function(e){c.debug("API request detected, waiting for state signal",e),e&&(o.loading&&c.update.text(o.loading),w.when(e).then(function(){"resolved"==e.state()?(c.debug("API request succeeded"),i.activateTest=function(){return!0},i.deactivateTest=function(){return!0}):(c.debug("API request failed"),i.activateTest=function(){return!1},i.deactivateTest=function(){return!1}),c.change.state()}))},change:{state:function(){c.debug("Determining state change direction"),c.is.inactive()?c.activate():c.deactivate(),i.sync&&c.sync(),i.onChange.call(d)},text:function(){c.is.textEnabled()&&(c.is.disabled()?(c.verbose("Changing text to disabled text",o.hover),c.update.text(o.disabled)):c.is.active()?o.hover?(c.verbose("Changing text to hover text",o.hover),c.update.text(o.hover)):o.deactivate&&(c.verbose("Changing text to deactivating text",o.deactivate),c.update.text(o.deactivate)):o.hover?(c.verbose("Changing text to hover text",o.hover),c.update.text(o.hover)):o.activate&&(c.verbose("Changing text to activating text",o.activate),c.update.text(o.activate)))}},activate:function(){i.activateTest.call(d)&&(c.debug("Setting state to active"),u.addClass(t.active),c.update.text(o.active),i.onActivate.call(d))},deactivate:function(){i.deactivateTest.call(d)&&(c.debug("Setting state to inactive"),u.removeClass(t.active),c.update.text(o.inactive),i.onDeactivate.call(d))},sync:function(){c.verbose("Syncing other buttons to current state"),c.is.active()?b.not(u).state("activate"):b.not(u).state("deactivate")},get:{text:function(){r
|