You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
7.5 KiB
11 lines
7.5 KiB
/*
|
|
* # Semantic UI
|
|
* git://github.com/Semantic-Org/Semantic-UI.git#1.0
|
|
*
|
|
*
|
|
* Copyright 2014 Contributors
|
|
* Released under the MIT license
|
|
* http://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(e,t,n,a){e.fn.state=function(t){var i,o=e(this),s=o.selector||"",r=("ontouchstart"in n.documentElement,(new Date).getTime()),c=[],u=arguments[0],l="string"==typeof u,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),g=f.error,v=f.metadata,x=f.className,m=f.namespace,b=f.states,p=f.text,h="."+m,y=m+"-module",T=e(this),C=this,w=T.data(y);n={initialize:function(){n.verbose("Initializing module"),f.automatic&&n.add.defaults(),f.context&&""!==s?e(f.context).on(s,"mouseenter"+h,n.change.text).on(s,"mouseleave"+h,n.reset.text).on(s,"click"+h,n.toggle.state):T.on("mouseenter"+h,n.change.text).on("mouseleave"+h,n.reset.text).on("click"+h,n.toggle.state),n.instantiate()},instantiate:function(){n.verbose("Storing instance of module",n),w=n,T.data(y,n)},destroy:function(){n.verbose("Destroying previous module",w),T.off(h).removeData(y)},refresh:function(){n.verbose("Refreshing selector cache"),T=e(C)},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,C),e.extend(f.states,o,i))})}},is:{active:function(){return T.hasClass(x.active)},loading:function(){return T.hasClass(x.loading)},inactive:function(){return!T.hasClass(x.active)},state:function(e){return x[e]===a?!1:T.hasClass(x[e])},enabled:function(){return!T.is(f.filter.active)},disabled:function(){return T.is(f.filter.active)},textEnabled:function(){return!T.is(f.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),b[e]=!0},disallow:function(e){n.debug("No longer allowing",e),b[e]=!1},allows:function(e){return b[e]||!1},enable:function(){T.removeClass(x.disabled)},disable:function(){T.addClass(x.disabled)},setState:function(e){n.allows(e)&&T.addClass(x[e])},removeState:function(e){n.allows(e)&&T.removeClass(x[e])},toggle:{state:function(){var t;if(n.allows("active")&&n.is.enabled()){if(n.refresh(),e.fn.api!==a&&(t=T.api("get request")))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()})):(f.activateTest=function(){return!1},f.deactivateTest=function(){return!1})},change:{state:function(){n.debug("Determining state change direction"),n.is.inactive()?n.activate():n.deactivate(),f.sync&&n.sync(),e.proxy(f.onChange,C)()},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(){e.proxy(f.activateTest,C)()&&(n.debug("Setting state to active"),T.addClass(x.active),n.update.text(p.active),e.proxy(f.onActivate,C)())},deactivate:function(){e.proxy(f.deactivateTest,C)()&&(n.debug("Setting state to inactive"),T.removeClass(x.active),n.update.text(p.inactive),e.proxy(f.onDeactivate,C)())},sync:function(){n.verbose("Syncing other buttons to current state"),o.not(T).state(n.is.active()?"activate":"deactivate")},get:{text:function(){return f.selector.text?T.find(f.selector.text).text():T.html()},textFor:function(e){return p[e]||!1}},flash:{text:function(t,a,i){var o=n.get.text();n.debug("Flashing text message",t,a),t=t||f.text.flash,a=a||f.flashDuration,i=i||function(){},n.update.text(t),setTimeout(function(){n.update.text(o),e.proxy(i,C)()},a)}},reset:{text:function(){var e=p.active||T.data(v.storedText),t=p.inactive||T.data(v.storedText);n.is.textEnabled()&&(n.is.active()&&e?(n.verbose("Resetting active text",e),n.update.text(e)):t&&(n.verbose("Resetting inactive text",e),n.update.text(t)))}},update:{text:function(e){var t=n.get.text();e&&e!==t?(n.debug("Updating text",e),f.selector.text?T.data(v.storedText,e).find(f.selector.text).text(e):T.data(v.storedText,e).html(e)):n.debug("Text is already sane, ignoring update",e)}},setting:function(t,i){if(n.debug("Changing setting",t,i),e.isPlainObject(t))e.extend(!0,f,t);else{if(i===a)return f[t];f[t]=i}},internal:function(t,i){if(e.isPlainObject(t))e.extend(!0,n,t);else{if(i===a)return n[t];n[t]=i}},debug:function(){f.debug&&(f.performance?n.performance.log(arguments):(n.debug=Function.prototype.bind.call(console.info,console,f.name+":"),n.debug.apply(console,arguments)))},verbose:function(){f.verbose&&f.debug&&(f.performance?n.performance.log(arguments):(n.verbose=Function.prototype.bind.call(console.info,console,f.name+":"),n.verbose.apply(console,arguments)))},error:function(){n.error=Function.prototype.bind.call(console.error,console,f.name+":"),n.error.apply(console,arguments)},performance:{log:function(e){var t,a,i;f.performance&&(t=(new Date).getTime(),i=r||t,a=t-i,r=t,c.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:C,"Execution Time":a})),clearTimeout(n.performance.timer),n.performance.timer=setTimeout(n.performance.display,100)},display:function(){var t=f.name+":",i=0;r=!1,clearTimeout(n.performance.timer),e.each(c,function(e,t){i+=t["Execution Time"]}),t+=" "+i+"ms",s&&(t+=" '"+s+"'"),(console.group!==a||console.table!==a)&&c.length>0&&(console.groupCollapsed(t),console.table?console.table(c):e.each(c,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),c=[]}},invoke:function(t,o,s){var r,c,u,l=w;return o=o||d,s=C||s,"string"==typeof t&&l!==a&&(t=t.split(/[\. ]/),r=t.length-1,e.each(t,function(i,o){var s=i!=r?o+t[i+1].charAt(0).toUpperCase()+t[i+1].slice(1):t;if(e.isPlainObject(l[s])&&i!=r)l=l[s];else{if(l[s]!==a)return c=l[s],!1;if(!e.isPlainObject(l[o])||i==r)return l[o]!==a?(c=l[o],!1):(n.error(g.method,t),!1);l=l[o]}})),e.isFunction(c)?u=c.apply(s,o):c!==a&&(u=c),e.isArray(i)?i.push(u):i!==a?i=[i,u]:u!==a&&(i=u),c}},l?(w===a&&n.initialize(),n.invoke(u)):(w!==a&&n.destroy(),n.initialize())}),i!==a?i:this},e.fn.state.settings={name:"State",debug:!1,verbose:!0,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);
|