dhxmvp
Version:
A complete boilerplate for building online, offline and syncable MVP Single Page Applications using DHTMLX.
1 lines • 7.65 kB
JavaScript
!function(r){"use strict"}(window.$dhx=window.$dhx||{}),function(r){"use strict"}($dhx.crypt=$dhx.crypt||{SHA1:function(r){var e,t,n,o,a,c,h,i,f,d=function(r,e){var t=r<<e|r>>>32-e;return t},u=function(r){var e,t,n="";for(e=7;e>=0;e--)t=r>>>4*e&15,n+=t.toString(16);return n},C=function(r){r=r.replace(/\r\n/g,"\n");for(var e="",t=0;t<r.length;t++){var n=r.charCodeAt(t);n<128?e+=String.fromCharCode(n):n>127&&n<2048?(e+=String.fromCharCode(n>>6|192),e+=String.fromCharCode(63&n|128)):(e+=String.fromCharCode(n>>12|224),e+=String.fromCharCode(n>>6&63|128),e+=String.fromCharCode(63&n|128))}return e},A=new Array(80),s=1732584193,g=4023233417,S=2562383102,b=271733878,m=3285377520;r=C(r);var p=r.length,w=[];for(t=0;t<p-3;t+=4)n=r.charCodeAt(t)<<24|r.charCodeAt(t+1)<<16|r.charCodeAt(t+2)<<8|r.charCodeAt(t+3),w.push(n);switch(p%4){case 0:t=2147483648;break;case 1:t=r.charCodeAt(p-1)<<24|8388608;break;case 2:t=r.charCodeAt(p-2)<<24|r.charCodeAt(p-1)<<16|32768;break;case 3:t=r.charCodeAt(p-3)<<24|r.charCodeAt(p-2)<<16|r.charCodeAt(p-1)<<8|128}for(w.push(t);w.length%16!=14;)w.push(0);for(w.push(p>>>29),w.push(p<<3&4294967295),e=0;e<w.length;e+=16){for(t=0;t<16;t++)A[t]=w[e+t];for(t=16;t<=79;t++)A[t]=d(A[t-3]^A[t-8]^A[t-14]^A[t-16],1);for(o=s,a=g,c=S,h=b,i=m,t=0;t<=19;t++)f=d(o,5)+(a&c|~a&h)+i+A[t]+1518500249&4294967295,i=h,h=c,c=d(a,30),a=o,o=f;for(t=20;t<=39;t++)f=d(o,5)+(a^c^h)+i+A[t]+1859775393&4294967295,i=h,h=c,c=d(a,30),a=o,o=f;for(t=40;t<=59;t++)f=d(o,5)+(a&c|a&h|c&h)+i+A[t]+2400959708&4294967295,i=h,h=c,c=d(a,30),a=o,o=f;for(t=60;t<=79;t++)f=d(o,5)+(a^c^h)+i+A[t]+3395469782&4294967295,i=h,h=c,c=d(a,30),a=o,o=f;s=s+o&4294967295,g=g+a&4294967295,S=S+c&4294967295,b=b+h&4294967295,m=m+i&4294967295}return f=u(s)+u(g)+u(S)+u(b)+u(m),f.toLowerCase()},SHA2:function(r){function e(r,e){var t=(65535&r)+(65535&e),n=(r>>16)+(e>>16)+(t>>16);return n<<16|65535&t}function t(r,e){return r>>>e|r<<32-e}function n(r,e){return r>>>e}function o(r,e,t){return r&e^~r&t}function a(r,e,t){return r&e^r&t^e&t}function c(r){return t(r,2)^t(r,13)^t(r,22)}function h(r){return t(r,6)^t(r,11)^t(r,25)}function i(r){return t(r,7)^t(r,18)^n(r,3)}function f(r){return t(r,17)^t(r,19)^n(r,10)}function d(r,t){var n,d,u,C,A,s,g,S,b,m,p=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),w=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),v=new Array(64);r[t>>5]|=128<<24-t%32,r[(t+64>>9<<4)+15]=t;for(var y=0;y<r.length;y+=16){n=w[0],d=w[1],u=w[2],C=w[3],A=w[4],s=w[5],g=w[6],S=w[7];for(var l=0;l<64;l++)l<16?v[l]=r[l+y]:v[l]=e(e(e(f(v[l-2]),v[l-7]),i(v[l-15])),v[l-16]),b=e(e(e(e(S,h(A)),o(A,s,g)),p[l]),v[l]),m=e(c(n),a(n,d,u)),S=g,g=s,s=A,A=e(C,b),C=u,u=d,d=n,n=e(b,m);w[0]=e(n,w[0]),w[1]=e(d,w[1]),w[2]=e(u,w[2]),w[3]=e(C,w[3]),w[4]=e(A,w[4]),w[5]=e(s,w[5]),w[6]=e(g,w[6]),w[7]=e(S,w[7])}return w}function u(r){for(var e=Array(),t=(1<<s)-1,n=0;n<r.length*s;n+=s)e[n>>5]|=(r.charCodeAt(n/s)&t)<<24-n%32;return e}function C(r){r=r.replace(/\r\n/g,"\n");for(var e="",t=0;t<r.length;t++){var n=r.charCodeAt(t);n<128?e+=String.fromCharCode(n):n>127&&n<2048?(e+=String.fromCharCode(n>>6|192),e+=String.fromCharCode(63&n|128)):(e+=String.fromCharCode(n>>12|224),e+=String.fromCharCode(n>>6&63|128),e+=String.fromCharCode(63&n|128))}return e}function A(r){for(var e=g?"0123456789ABCDEF":"0123456789abcdef",t="",n=0;n<4*r.length;n++)t+=e.charAt(r[n>>2]>>8*(3-n%4)+4&15)+e.charAt(r[n>>2]>>8*(3-n%4)&15);return t}var s=8,g=0;return r=C(r),A(d(u(r),r.length*s))},base64_encode:function(r){return base64.encode(r)},base64_decode:function(r){return base64.decode(r)},Base64:{_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(r){var e,t,n,o,a,c,h,i="",f=0;for(r=Base64._utf8_encode(r);f<r.length;)e=r.charCodeAt(f++),t=r.charCodeAt(f++),n=r.charCodeAt(f++),o=e>>2,a=(3&e)<<4|t>>4,c=(15&t)<<2|n>>6,h=63&n,isNaN(t)?c=h=64:isNaN(n)&&(h=64),i=i+this._keyStr.charAt(o)+this._keyStr.charAt(a)+this._keyStr.charAt(c)+this._keyStr.charAt(h);return i},decode:function(r){var e,t,n,o,a,c,h,i="",f=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");f<r.length;)o=this._keyStr.indexOf(r.charAt(f++)),a=this._keyStr.indexOf(r.charAt(f++)),c=this._keyStr.indexOf(r.charAt(f++)),h=this._keyStr.indexOf(r.charAt(f++)),e=o<<2|a>>4,t=(15&a)<<4|c>>2,n=(3&c)<<6|h,i+=String.fromCharCode(e),64!=c&&(i+=String.fromCharCode(t)),64!=h&&(i+=String.fromCharCode(n));return i=Base64._utf8_decode(i)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var e="",t=0;t<r.length;t++){var n=r.charCodeAt(t);n<128?e+=String.fromCharCode(n):n>127&&n<2048?(e+=String.fromCharCode(n>>6|192),e+=String.fromCharCode(63&n|128)):(e+=String.fromCharCode(n>>12|224),e+=String.fromCharCode(n>>6&63|128),e+=String.fromCharCode(63&n|128))}return e},_utf8_decode:function(r){for(var e="",t=0,n=0,o=0;t<r.length;)n=r.charCodeAt(t),n<128?(e+=String.fromCharCode(n),t++):n>191&&n<224?(o=r.charCodeAt(t+1),e+=String.fromCharCode((31&n)<<6|63&o),t+=2):(o=r.charCodeAt(t+1),c3=r.charCodeAt(t+2),e+=String.fromCharCode((15&n)<<12|(63&o)<<6|63&c3),t+=3);return e}},setRSA64:function(r){return $dhx.crypt.Base64.encode(r)},getRSA64:function(r){return $dhx.crypt.Base64.decode(r)}}),window.base64={},base64.PADCHAR="=",base64.ALPHA="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64.makeDOMException=function(){try{return new DOMException(DOMException.INVALID_CHARACTER_ERR)}catch(r){var e=new Error("DOM Exception 5");return e.code=e.number=5,e.name=e.description="INVALID_CHARACTER_ERR",e.toString=function(){return"Error: "+e.name+": "+e.message},e}},base64.getbyte64=function(r,e){var t=base64.ALPHA.indexOf(r.charAt(e));if(t===-1)throw base64.makeDOMException();return t},base64.decode=function(r){r=""+r;var e,t,n,o=base64.getbyte64,a=r.length;if(0===a)return r;if(a%4!==0)throw base64.makeDOMException();e=0,r.charAt(a-1)===base64.PADCHAR&&(e=1,r.charAt(a-2)===base64.PADCHAR&&(e=2),a-=4);var c=[];for(t=0;t<a;t+=4)n=o(r,t)<<18|o(r,t+1)<<12|o(r,t+2)<<6|o(r,t+3),c.push(String.fromCharCode(n>>16,n>>8&255,255&n));switch(e){case 1:n=o(r,t)<<18|o(r,t+1)<<12|o(r,t+2)<<6,c.push(String.fromCharCode(n>>16,n>>8&255));break;case 2:n=o(r,t)<<18|o(r,t+1)<<12,c.push(String.fromCharCode(n>>16))}return c.join("")},base64.getbyte=function(r,e){var t=r.charCodeAt(e);if(t>255)throw base64.makeDOMException();return t},base64.encode=function(r){if(1!==arguments.length)throw new SyntaxError("Not enough arguments");var e,t,n=base64.PADCHAR,o=base64.ALPHA,a=base64.getbyte,c=[];r=""+r;var h=r.length-r.length%3;if(0===r.length)return r;for(e=0;e<h;e+=3)t=a(r,e)<<16|a(r,e+1)<<8|a(r,e+2),c.push(o.charAt(t>>18)),c.push(o.charAt(t>>12&63)),c.push(o.charAt(t>>6&63)),c.push(o.charAt(63&t));switch(r.length-h){case 1:t=a(r,e)<<16,c.push(o.charAt(t>>18)+o.charAt(t>>12&63)+n+n);break;case 2:t=a(r,e)<<16|a(r,e+1)<<8,c.push(o.charAt(t>>18)+o.charAt(t>>12&63)+o.charAt(t>>6&63)+n)}return c.join("")},window.btoa||(window.btoa=base64.encode),window.atob||(window.atob=base64.decode);