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