This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
kslite-min.js
13 lines (13 loc) · 5.99 KB
/
kslite-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
(function(l,c,o){function B(){if(navigator.userAgent.indexOf("MSIE")<0)return null;for(var a=z.getElementsByTagName("script"),b,d=0,e=a.length;d<e;d++){b=a[d];if(b.readyState==="interactive")return b}return null}var m={lt_pkgs:{test:"../",cc:"../demo/"},lt_v:"0.3.0",lt_t:"1"};m.lt_pkgs.packages="http://a.alimama.cn/kslite/";var q=l.KSLITEonLoad,v=l.KSLITEpkgPaths;if(l[c]===o)l[c]={};c=l[c];var r=l.document,w=Object.prototype.toString,s=function(a,b,d,e){if(!b||!a)return a;if(d===o)d=true;var g,f,
h;if(e&&(h=e.length))for(g=0;g<h;g++){f=e[g];if(f in b)if(d||!(f in a))a[f]=b[f]}else for(f in b)if(d||!(f in a))a[f]=b[f];return a},z=r.getElementsByTagName("head")[0]||r.documentElement,A=4,C=/\.css(?:\?|$)/i,D=r.createElement("script").readyState?function(a,b){var d=a.onreadystatechange;a.onreadystatechange=function(){var e=a.readyState;if(e==="loaded"||e==="complete"){a.onreadystatechange=null;d&&d();b.call(this)}}}:function(a,b){a.addEventListener("load",b,false);a.addEventListener("error",b,
false)};s(c,{version:m.lt_v,_init:function(){function a(e){e=e.split("@");m.lt_pkgs[e[0]]=e[1]}var b,d=r.getElementsByTagName("script");if(!window.KSLITEcurrentScript)for(b=0;b<d.length;b++)if(d[b].kslite){window.KSLITEcurrentScript=d[b];break}b=window.KSLITEcurrentScript||d[d.length-1];window.KSLITEcurrentScript=b;b=b.src.split("/").slice(0,-1).join("/")+"/";c.Env={mods:{},fns:{},_loadQueue:{},_relies:{rq:{},sp:{}}};c.Config={debug:false,base:b,timeout:10,kslite:m};c.mix(c.Config,m);c.declare("kslite",
[],function(e,g){c.mix(g,c,true,["path","log","getScript","substitute","clone","mix","multiAsync","extend","iA","iF","iPO","iS"])});c.provide(["kslite"],function(){c.require("kslite").log("kslite inited")});if(/demo|debug|test/.test(location.href))c.Config.debug=true;if(c.Config.debug)m.lt_t+=(new Date).getTime()+".js";l.KSLITEpkgPaths={push:function(e){a(e)}};if(v&&c.iA(v))for(b=0;b<v.length;b++)a(v[b]);m.lt_t=l.KSLITEtimestamp||m.lt_t;l.KSLITEonLoad={push:function(e){e&&c.iF(e)&&e(c)}};if(q&&c.iA(q))for(b=
0;b<q.length;b++)c.iF(q[b])&&q[b](c)},mix:s,log:function(a,b){if(c.Config.debug)if(l.console!==o&&console.log)console[b&&console[b]?b:"log"](a);return c},clone:function(a){var b=a,d,e;if(a&&((d=c.iA(a))||c.iPO(a))){b=d?[]:{};for(e in a)if(a.hasOwnProperty(e))b[e]=c.clone(a[e])}return b},extend:function(a,b,d,e){if(!b||!a)return a;var g=Object.prototype,f=b.prototype,h=function(i){function k(){}k.prototype=i;return new k}(f);a.prototype=h;h.constructor=a;a.superclass=f;if(b!==Object&&f.constructor===
g.constructor)f.constructor=b;d&&s(h,d);e&&s(a,e);return a},substitute:function(a,b,d,e){if(!c.iS(a)||!c.iPO(b))return a;return a.replace(d||/\\?\{([^{}]+)\}/g,function(g,f){if(g.charAt(0)==="\\")return g.slice(1);return b[f]!==o?b[f]:e?g:""})},getScript:function(a,b,d,e){var g=C.test(a),f=r.createElement(g?"link":"script"),h=b,i,k,j,p;if(c.iPO(h)){b=h.success;i=h.error;k=h.timeout;d=h.charset}if(g){f.href=a;f.rel="stylesheet"}else{f.src=a;f.async=true}if(d)f.charset=d;if(e)for(p in e)f.setAttribute(p,
e[p]);if(c.iF(b))g?b.call(f):D(f,function(){if(j){j.cancel();j=o}b.call(f)});if(c.iF(i))j=setTimeout(function(){j=o;i()},(k||c.Config.timeout)*1E3);z.insertBefore(f,z.firstChild);return f},iF:function(a){return w.call(a)==="[object Function]"},iA:function(a){return w.call(a)==="[object Array]"},iS:function(a){return w.call(a)==="[object String]"},iPO:function(a){return a&&w.call(a)==="[object Object]"&&!a.nodeType&&!a.setInterval},add:function(a,b,d){var e=c.Env.mods;if(!(e[a]&&e[a].status>0)){b=
{name:a,fn:b||null,status:2};if(c.iA(d))d={requires:d};s(b,d);e[a]=b;return c}},use:function(a,b){a=a.split(",");c._aMs(a,function(){b&&b(c)})},_aMs:function(a,b){var d,e={};for(d=0;d<a.length;d++)e[a[d]]={f:c._aM,a:a[d]};c.multiAsync(e,b)},_aM:function(a,b){function d(j){if(j.status!=A){if(j.fn){c.log("attach "+j.name);j.fn(c,c.require(j.name),c._ns(j.name))}else c.log("attach "+j.name+" without expected attach fn!","warn");j.status=A}b()}function e(j){function p(t){i[t]=i[t]||{};k[t]=k[t]||{};return t}
var x,y,u;y=p(j.name);for(x=0;x<j.requires.length;x++){u=p(j.requires[x]);i[y][u]=1;k[u][y]=1;for(n in k[y]){i[n][u]=1;k[u][n]=1}}}var g,f,h=c.Env.mods,i=c.Env._relies.rq,k=c.Env._relies.sp;if((g=h[a])&&g.status!==0){f=g.requires;if(c.iA(f)&&f.length>0){e(g);if(i[a][a])throw new Error("Fatal Error,Loop Reqs:"+g.name);c.log(g.name+" to req: "+f);c._aMs(f,function(){d(g)})}else d(g)}else{g={name:a};c._lM(g,function(){c._aM(a,function(){d(h[a])})})}},_lM:function(a,b){var d=c.Env._loadQueue,e=a.name,
g,f=c.Env.mods;if(d[e]){g=d[e];if(g.c){c.log(e+" is already loaded","warn");b()}else{c.log(e+" is loading,listen to callback");g.fns.push(b)}}else c._gPath(a,function(){d[e]={fns:[b],c:false};f[e]||(f[e]={name:e,status:0});c.getScript(a.fullpath,function(){var h,i=d[e];if(c.__m__){h=c.__m__;c.add(e,h.fn,h.deps);c.__m__=null}if(f[e].status===0)f[e].status=2;for(h=0;h<i.fns.length;h++)i.fns[h]();i.c=true;i.fns=o},null,{mod_name:e})})},path:function(a,b){var d=a.split("-"),e=d[0];a=m.lt_pkgs;c.iS(a[e])?
b(a[e]+d.join("/")):KSLITE.provide(["packages-router"],function(g){g=g("packages-router");b((g[e]||c.Config.base)+d.join("/"))})},_gPath:function(a,b){c.path(a.name,function(d){a.fullpath=d+".js?_t="+m.lt_t+".js";c.log("path "+a.name+": "+a.fullpath);b()})},multiAsync:function(a,b){function d(){var f,h={};for(f in a){if(!a[f].c)return;h[f]=a[f].r}b(h)}var e,g=false;for(e in a)g=true;g||b({});for(e in a)(function(){var f=a[e];f.f.call(f.c||c,f.a,function(h){f.r=h;f.c=true;d()})})()},_ns:function(a){var b=
a.split("-"),d=c.Env.fns;for(a=0;a<b.length;a++){d[b[a]]=d[b[a]]||{};d=d[b[a]]}return d},require:function(a){a=c._ns(a);a.exports=a.exports||{};return a.exports},declare:function(){var a,b,d,e,g;for(a=0;a<arguments.length;a++){b=arguments[a];if(c.iS(b))d=b;else if(c.iA(b))e=b;else if(c.iF(b))g=b}if(!d)if(a=B())d=a.getAttribute("mod_name")||false;if(d)c.add(d,function(f,h,i){g(f.require,h,i)},e);else c.__m__={deps:e,fn:function(f,h,i){g(f.require,h,i)}}},provide:function(a,b){c.use(a.join(","),function(d){b(d.require)})}});
c._init()})(window,"KSLITE");