mirror of https://github.com/morpheus65535/bazarr
1 line
7.7 KiB
JavaScript
1 line
7.7 KiB
JavaScript
|
!function(e,t,n,a){"use strict";t=void 0!==t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.state=function(t){var a,i=e(this),o=i.selector||"",s=(n.documentElement,(new Date).getTime()),c=[],r=arguments[0],l="string"==typeof r,u=[].slice.call(arguments,1);return i.each(function(){var n,d=e.isPlainObject(t)?e.extend(!0,{},e.fn.state.settings,t):e.extend({},e.fn.state.settings),v=d.error,f=d.metadata,g=d.className,b=d.namespace,x=d.states,h=d.text,m="."+b,p=b+"-module",T=e(this),y=this,w=T.data(p);n={initialize:function(){n.verbose("Initializing module"),d.automatic&&n.add.defaults(),d.context&&""!==o?e(d.context).on(o,"mouseenter"+m,n.change.text).on(o,"mouseleave"+m,n.reset.text).on(o,"click"+m,n.toggle.state):T.on("mouseenter"+m,n.change.text).on("mouseleave"+m,n.reset.text).on("click"+m,n.toggle.state),n.instantiate()},instantiate:function(){n.verbose("Storing instance of module",n),w=n,T.data(p,n)},destroy:function(){n.verbose("Destroying previous module",w),T.off(m).removeData(p)},refresh:function(){n.verbose("Refreshing selector cache"),T=e(y)},add:{defaults:function(){var a=t&&e.isPlainObject(t.states)?t.states:{};e.each(d.defaults,function(t,i){void 0!==n.is[t]&&n.is[t]()&&(n.verbose("Adding default states",t,y),e.extend(d.states,i,a))})}},is:{active:function(){return T.hasClass(g.active)},loading:function(){return T.hasClass(g.loading)},inactive:function(){return!T.hasClass(g.active)},state:function(e){return void 0!==g[e]&&T.hasClass(g[e])},enabled:function(){return!T.is(d.filter.active)},disabled:function(){return T.is(d.filter.active)},textEnabled:function(){return!T.is(d.filter.text)},button:function(){return T.is(".button:not(a, .submit)")},input:function(){return T.is("input")},progress:function(){return T.is(".ui.progress")}},allow:function(e){n.debug("Now allowing state",e),x[e]=!0},disallow:function(e){n.debug("No longer allowing",e),x[e]=!1},allows:function(e){return x[e]||!1},enable:function(){T.removeClass(g.disabled)},disable:function(){T.addClass(g.disabled)},setState:function(e){n.allows(e)&&T.addClass(g[e])},removeState:function(e){n.allows(e)&&T.removeClass(g[e])},toggle:{state:function(){var t;if(n.allows("active")&&n.is.enabled()){if(n.refresh(),void 0!==e.fn.api)if(t=T.api("get request"),T.api("was cancelled"))n.debug("API Request cancelled by beforesend"),d.activateTest=function(){return!1},d.deactivateTest=function(){return!1};else if(t)return void n.listenTo(t);n.change.state()}}},listenTo:function(t){n.debug("API request detected, waiting for state signal",t),t&&(h.loading&&n.update.text(h.loading),e.when(t).then(function(){"resolved"==t.state()?(n.debug("API request succeeded"),d.activateTest=function(){return!0},d.deactivateTest=function(){return!0}):(n.debug("API request failed"),d.activateTest=function(){return!1},d.deactivateTest=function(){return!1}),n.change.state()}))},change:{state:function(){n.debug("Determining state change direction"),n.is.inactive()?n.activate():n.deactivate(),d.sync&&n.sync(),d.onChange.call(y)},text:function(){n.is.textEnabled()&&(n.is.disabled()?(n.verbose("Changing text to disabled text",h.hover),n.update.text(h.disabled)):n.is.active()?h.hover?(n.verbose("Changing text to hover text",h.hover),n.update.text(h.hover)):h.deactivate&&(n.verbose("Changing text to deactivating text",h.deactivate),n.update.text(h.deactivate)):h.hover?(n.verbose("Changing text to hover text",h.hover),n.update.text(h.hover)):h.activate&&(n.verbose("Changing text to activating text",h.activate),n.update.text(h.activate)))}},activate:function(){d.activateTest.call(y)&&(n.debug("Setting state to active"),T.addClass(g.active),n.update.text(h.active),d.onActivate.call(y))},deactivate:function(){d.deactivateTest.call(y)&&(n.debug("Setting state to inactive"),T.removeClass(g.active),n.update.text(h.inactive),d.onDeactivate.call(y))},sync:function(){n.verbose("Syncing other buttons to current state"),n.is.active()?i.not(T).state("activate"):i.not(T).state("deactivate")},get:{text:function(){return d.selector.text?T.find(d.selector.text).text
|