cloudcmd/modules/load/load.min.js
2015-01-15 06:11:12 -05:00

1 line
1.4 KiB
JavaScript

!function(e){"use strict";function n(){function e(t,r){var s=n(t);switch(s){case".js":e.js(t,r);break;case".css":e.css(t,r);break;case".json":e.json(t,r);break;default:e.ajax(t,r)}}function n(e){var n,t="",r="string"==typeof e;return r&&(n=e.lastIndexOf("."),~n&&(t=e.substr(n))),t}function t(e){var n,t,r,s="string"==typeof e;if(s)for(~e.indexOf(":")&&(e+="-join"),n=e.lastIndexOf("/")+1,t=e.substr(e,n),r=e.replace(t,"");r.indexOf(".")>0;)r=r.replace(".","-");return r}return e.js=function(e,n){var r=t(e),s=document.getElementById(r);return s?n():(s=document.createElement("script"),s.id=r,s.src=e,s.addEventListener("load",function(e){n(null,e)}),s.addEventListener("error",n),document.body.appendChild(s)),s},e.css=function(e,n){var r=t(e),s=document.getElementById(r);return s?n():(s=document.createElement("link"),s.id=t(e),s.rel="stylesheet",s.href=e,s.addEventListener("load",function(e){n(null,e)}),s.addEventListener("error",n),document.head.appendChild(s)),s},e.ajax=function(e,n){var t=new XMLHttpRequest;t.open("GET",e,!0),t.addEventListener("load",function(){var e;t.status>=200&&t.status<400&&(e=t.responseText,n(null,e))}),t.addEventListener("error",n),t.send()},e.json=function(n,t){e.ajax(n,function(e,n){var r;e||(r=JSON.parse(n)),t(e,r||n)})},e.series=function(n,t){var r=n.shift();r?e(r,function(){e.series(n,t)}):t()},e.parallel=function(n,t){var r=n.length,s=function(){--r,r||t()};n.forEach(function(n){e(n,s)})},e}e.load=new n}(window);