-
Notifications
You must be signed in to change notification settings - Fork 37
/
ssm.min.js
executable file
·2 lines (2 loc) · 3.68 KB
/
ssm.min.js
1
2
/*! SimpleStateManager | license: MIT | version: 2.2.6 | build date: 2014-06-23 */
!function(a,b){"use strict";var c=!1,d={},e=[],f=0,g=[],h=10,i=null,j=[],k=function(){return"function"==typeof a.matchMedia&&"undefined"!=typeof a.matchMedia("(width: 100px)").addListener?!0:!1}(),l=function(){clearTimeout(i),i=setTimeout(m,h)},m=function(){f=p(),n(f)},n=function(a){for(var b=e.length,c=j.length,f=[],h=[],i=[],k=!0,l=d,m=0;b>m;m++){k=!0,l.state=e[m],l.browserWidth=a;for(var n=0;c>n;n++)if("undefined"!=typeof l.state[j[n].name]&&(l.callback=j[n].test,l.callback()===!1)){k=!1;break}k?t(g,e[m])?h=h.concat(e[m].onResize):(g.push(e[m]),i=i.concat(e[m].onEnter)):t(g,e[m])&&(f=f.concat(e[m].onLeave),g=u(g,e[m]))}v(f),v(i),v(h)};d.browserResize=n,d.getBrowserWidth=function(){return f},d.addState=function(a){var b={id:o(),minWidth:0,maxWidth:999999,onEnter:[],onLeave:[],onResize:[]};return a=q(b,a),"function"==typeof a.onEnter&&(a.onEnter=[a.onEnter]),"function"==typeof a.onLeave&&(a.onLeave=[a.onLeave]),"function"==typeof a.onResize&&(a.onResize=[a.onResize]),e.push(a),e=r(e,"minWidth"),this},d.updateState=function(a,b){for(var c=e.length-1;c>=0;c--)e[c].id===a&&(e[c]=q(e[c],b));return this},d.removeState=function(a){for(var b=e.length-1;b>=0;b--)e[b].id===a&&e.splice(b,1);return this},d.removeStates=function(a){for(var b=a.length-1;b>=0;b--)d.removeState(a[b]);return this},d.removeAllStates=function(){return e=g=[],this},d.addStates=function(a){for(var b=a.length-1;b>=0;b--)d.addState(a[b]);return this},d.getStates=function(a){var b=null,c=[];if("undefined"==typeof a)return e;b=a.length;for(var d=0;b>d;d++)c.push(s(a[d]));return c},d.addConfigOption=function(a){var b={name:"",test:null};a=q(b,a),""!==a.name&&null!==a.test&&j.push(a)},d.getConfigOption=function(a){if("string"!=typeof a)return j;for(var b=j.length-1;b>=0;b--)if(j[b].name===a)return j[b]},d.removeConfigOption=function(a){for(var b=j.length-1;b>=0;b--)j[b].name===a&&j.splice(b,1)},d.isActive=function(a){for(var b=0;b<g.length;b++)if(g[b].id===a)return!0;return!1},d.getCurrentStates=function(){return g},d.setResizeTimeout=function(a){h=a},d.getResizeTimeout=function(){return h},d.ready=function(){return f=p(),c===!1&&(a.attachEvent?a.attachEvent("onresize",l):a.addEventListener&&a.addEventListener("resize",l,!0),c=!0),n(f),this};var o=function(){for(var a="",b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",c=0;10>c;c++)a+=b.charAt(Math.floor(Math.random()*b.length));return a},p=function(){var c=0;return k?a.matchMedia("(width:"+a.innerWidth+"px)").matches?c=a.innerWidth:a.matchMedia("(width:"+a.innerWidth+"px)").matches?c=a.outerWidth:a.matchMedia("(width:"+b.body.clientWidth+"px)").matches&&(c=b.body.clientWidth):"number"==typeof b.body.clientWidth?c=b.body.clientWidth:"number"==typeof a.innerWidth?c=a.innerWidth:b.documentElement&&b.documentElement.clientWidth&&(c=b.documentElement.clientWidth),c},q=function(a,b){var c={};for(var d in a)c[d]=a[d];for(var e in b)c[e]=b[e];return c},r=function(a,b){return a.sort(function(a,c){var d=a[b],e=c[b];return e>d?-1:d>e?1:0})},s=function(a){for(var b=e.length-1;b>=0;b--)if(e[b].id===a)return e[b]},t=function(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return!0},u=function(a,b){for(var c=a.length,d=0;c>d;d++)a[d]===b&&a.splice(d,1);return a},v=function(a){for(var b=a.length,c=0;b>c;c++)a[c]()};d.addConfigOption({name:"minWidth",test:function(){return"number"==typeof this.state.minWidth&&this.state.minWidth<=this.browserWidth?!0:!1}}),d.addConfigOption({name:"maxWidth",test:function(){return"number"==typeof this.state.maxWidth&&this.state.maxWidth>=this.browserWidth?!0:!1}}),a.ssm=d,"function"==typeof a.define&&a.define.amd&&a.define("ssm",[],function(){return a.ssm})}(window,document);