snappymail/vendors/ssm/ssm.min.js
2013-12-30 01:13:35 +04:00

2 lines
No EOL
3.1 KiB
JavaScript

/*! SimpleStateManager | license: MIT | version: 2.1.0 | build date: 2013-12-23 */
!function(a,b){"use strict";var c={},d=[],e=0,f=[],g=10,h=null,i=[],j=function(){clearTimeout(h),h=setTimeout(k,g)},k=function(){e=n(),l(e)},l=function(a){for(var b=d.length,e=i.length,g=[],h=[],j=[],k=!0,l=c,m=0;b>m;m++){k=!0,l.state=d[m],l.browserWidth=a;for(var n=0;e>n;n++)if(l.callback=i[n].test,l.callback()===!1){k=!1;break}k?r(f,d[m])?h.push(d[m].onResize):(f.push(d[m]),j.push(d[m].onEnter)):r(f,d[m])&&(g.push(d[m].onLeave),f=s(f,d[m]))}t(g),t(j),t(h)};c.browserResize=l,c.getBrowserWidth=function(){return e},c.addState=function(a){var b={id:m(),minWidth:0,maxWidth:99999,onEnter:function(){},onLeave:function(){},onResize:function(){}};return a=o(b,a),d.push(a),d=p(d,"minWidth"),this},c.updateState=function(a,b){for(var c=d.length-1;c>=0;c--)d[c].id===a&&(d[c]=o(d[c],b));return this},c.removeState=function(a){for(var b=d.length-1;b>=0;b--)d[b].id===a&&d.splice(b,1);return this},c.removeStates=function(a){for(var b=a.length-1;b>=0;b--)c.removeState(a[b]);return this},c.removeAllStates=function(){return d=f=[],this},c.addStates=function(a){for(var b=a.length-1;b>=0;b--)c.addState(a[b]);return this},c.getStates=function(a){var b=null,c=[];if("undefined"==typeof a)return d;b=a.length;for(var e=0;b>e;e++)c.push(q(a[e]));return c},c.addConfigOption=function(a){var b={name:"",test:null};a=o(b,a),""!==a.name&&null!==a.test&&i.push(a)},c.getConfigOption=function(a){if("string"!=typeof a)return i;for(var b=i.length-1;b>=0;b--)if(i[b].name===a)return i[b]},c.removeConfigOption=function(a){for(var b=i.length-1;b>=0;b--)i[b].name===a&&i.splice(b,1)},c.getCurrentStates=function(){return f},c.setResizeTimeout=function(a){g=a},c.getResizeTimeout=function(){return g},c.ready=function(){return e=n(),a.attachEvent?a.attachEvent("onresize",j):a.addEventListener&&a.addEventListener("resize",j,!0),l(e),this};var m=function(){for(var a="",b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",c=0;10>c;c++)a+=b.charAt(Math.floor(Math.random()*b.length));return a},n=function(){var c=0;return"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},o=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},p=function(a,b){return a.sort(function(a,c){var d=a[b],e=c[b];return e>d?-1:d>e?1:0})},q=function(a){for(var b=d.length-1;b>=0;b--)if(d[b].id===a)return d[b]},r=function(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return!0},s=function(a,b){for(var c=a.length,d=0;c>d;d++)a[d]===b&&a.splice(d,1);return a},t=function(a){for(var b=a.length,c=0;b>c;c++)a[c]()};c.addConfigOption({name:"minWidth",test:function(){return"number"==typeof this.state.minWidth&&this.state.minWidth<=this.browserWidth?!0:!1}}),c.addConfigOption({name:"maxWidth",test:function(){return"number"==typeof this.state.maxWidth&&this.state.maxWidth>=this.browserWidth?!0:!1}}),a.ssm=c,"function"==typeof a.define&&a.define.amd&&a.define("ssm",[],function(){return a.ssm})}(window,document);