forked from seajs/seajs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sea.js
29 lines (29 loc) · 10.8 KB
/
sea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
SeaJS - A Module Loader for the Web
v1.3.0-dev | seajs.org | MIT Licensed
*/
this.seajs={_seajs:this.seajs};seajs.version="1.3.0-dev";seajs._util={};seajs._config={debug:"",preload:[]};
(function(a){var c=Object.prototype.toString,d=Array.prototype;a.isString=function(a){return"[object String]"===c.call(a)};a.isFunction=function(a){return"[object Function]"===c.call(a)};a.isRegExp=function(a){return"[object RegExp]"===c.call(a)};a.isObject=function(a){return a===Object(a)};a.isArray=Array.isArray||function(a){return"[object Array]"===c.call(a)};a.indexOf=d.indexOf?function(a,c){return a.indexOf(c)}:function(a,c){for(var b=0;b<a.length;b++)if(a[b]===c)return b;return-1};var b=a.forEach=
d.forEach?function(a,c){a.forEach(c)}:function(a,c){for(var b=0;b<a.length;b++)c(a[b],b,a)};a.map=d.map?function(a,c){return a.map(c)}:function(a,c){var d=[];b(a,function(a,b,e){d.push(c(a,b,e))});return d};a.filter=d.filter?function(a,c){return a.filter(c)}:function(a,c){var d=[];b(a,function(a,b,e){c(a,b,e)&&d.push(a)});return d};var e=a.keys=Object.keys||function(a){var c=[],b;for(b in a)a.hasOwnProperty(b)&&c.push(b);return c};a.unique=function(a){var c={};b(a,function(a){c[a]=1});return e(c)};
a.now=Date.now||function(){return(new Date).getTime()}})(seajs._util);(function(a,c){var d=Array.prototype;a.log=function(){if("undefined"!==typeof console){var a=d.slice.call(arguments),e="log";console[a[a.length-1]]&&(e=a.pop());if("log"!==e||c.debug)a="dir"===e?a[0]:d.join.call(a," "),console[e](a)}}})(seajs._util,seajs._config);
(function(a,c,d){function b(a){a=a.match(m);return(a?a[0]:".")+"/"}function e(a){f.lastIndex=0;f.test(a)&&(a=a.replace(f,"$1/"));if(-1===a.indexOf("."))return a;for(var c=a.split("/"),b=[],d,e=0;e<c.length;e++)if(d=c[e],".."===d){if(0===b.length)throw Error("The path is invalid: "+a);b.pop()}else"."!==d&&b.push(d);return b.join("/")}function n(a){var a=e(a),c=a.charAt(a.length-1);if("/"===c)return a;"#"===c?a=a.slice(0,-1):-1===a.indexOf("?")&&!k.test(a)&&(a+=".js");0<a.indexOf(":80/")&&(a=a.replace(":80/",
"/"));return a}function l(a){if("#"===a.charAt(0))return a.substring(1);var b=c.alias;if(b&&q(a)){var d=a.split("/"),e=d[0];b.hasOwnProperty(e)&&(d[0]=b[e],a=d.join("/"))}return a}function h(a){return 0<a.indexOf("://")||0===a.indexOf("//")}function g(a){return"/"===a.charAt(0)&&"/"!==a.charAt(1)}function q(a){var c=a.charAt(0);return-1===a.indexOf("://")&&"."!==c&&"/"!==c}var m=/.*(?=\/.*$)/,f=/([^:\/])\/\/+/g,k=/\.(?:css|js)$/,i=/^(.*?\w)(?:\/|$)/,j={},d=d.location,o=d.protocol+"//"+d.host+function(a){"/"!==
a.charAt(0)&&(a="/"+a);return a}(d.pathname);0<o.indexOf("\\")&&(o=o.replace(/\\/g,"/"));a.dirname=b;a.realpath=e;a.normalize=n;a.parseAlias=l;a.parseMap=function(b){var d=c.map||[];if(!d.length)return b;for(var e=b,f=0;f<d.length;f++){var h=d[f];if(a.isArray(h)&&2===h.length){var g=h[0];if(a.isString(g)&&-1<e.indexOf(g)||a.isRegExp(g)&&g.test(e))e=e.replace(g,h[1])}else a.isFunction(h)&&(e=h(e))}e!==b&&(j[e]=b);return e};a.unParseMap=function(a){return j[a]||a};a.id2Uri=function(a,d){if(!a)return"";
a=l(a);d||(d=o);var e;h(a)?e=a:0===a.indexOf("./")||0===a.indexOf("../")?(0===a.indexOf("./")&&(a=a.substring(2)),e=b(d)+a):e=g(a)?d.match(i)[1]+a:c.base+"/"+a;return n(e)};a.isAbsolute=h;a.isRoot=g;a.isTopLevel=q;a.pageUri=o})(seajs._util,seajs._config,this);
(function(a,c){function d(a,b){a.onload=a.onerror=a.onreadystatechange=function(){m.test(a.readyState)&&(a.onload=a.onerror=a.onreadystatechange=null,a.parentNode&&!c.debug&&h.removeChild(a),a=void 0,b())}}function b(c,b){j||o?(a.log("Start poll to fetch css"),setTimeout(function(){e(c,b)},1)):c.onload=c.onerror=function(){c.onload=c.onerror=null;c=void 0;b()}}function e(a,c){var b;if(j)a.sheet&&(b=!0);else if(a.sheet)try{a.sheet.cssRules&&(b=!0)}catch(d){"NS_ERROR_DOM_SECURITY_ERR"===d.name&&(b=
!0)}setTimeout(function(){b?c():e(a,c)},1)}function n(){}var l=document,h=l.head||l.getElementsByTagName("head")[0]||l.documentElement,g=h.getElementsByTagName("base")[0],q=/\.css(?:\?|$)/i,m=/loaded|complete|undefined/,f,k;a.fetch=function(c,e,j){var k=q.test(c),i=document.createElement(k?"link":"script");j&&(j=a.isFunction(j)?j(c):j)&&(i.charset=j);e=e||n;"SCRIPT"===i.nodeName?d(i,e):b(i,e);k?(i.rel="stylesheet",i.href=c):(i.async="async",i.src=c);f=i;g?h.insertBefore(i,g):h.appendChild(i);f=null};
a.getCurrentScript=function(){if(f)return f;if(k&&"interactive"===k.readyState)return k;for(var a=h.getElementsByTagName("script"),c=0;c<a.length;c++){var b=a[c];if("interactive"===b.readyState)return k=b}};a.getScriptAbsoluteSrc=function(a){return a.hasAttribute?a.src:a.getAttribute("src",4)};a.importStyle=function(a,c){if(!c||!l.getElementById(c)){var b=l.createElement("style");c&&(b.id=c);h.appendChild(b);b.styleSheet?b.styleSheet.cssText=a:b.appendChild(l.createTextNode(a))}};var i=navigator.userAgent,
j=536>Number(i.replace(/.*AppleWebKit\/(\d+)\..*/,"$1")),o=0<i.indexOf("Firefox")&&!("onload"in document.createElement("link"))})(seajs._util,seajs._config,this);(function(a){var c=/(?:^|[^.$])\brequire\s*\(\s*(["'])([^"'\s\)]+)\1\s*\)/g;a.parseDependencies=function(d){var b=[],e,d=d.replace(/^\s*\/\*[\s\S]*?\*\/\s*$/mg,"").replace(/^\s*\/\/.*$/mg,"");for(c.lastIndex=0;e=c.exec(d);)e[2]&&b.push(e[2]);return a.unique(b)}})(seajs._util);
(function(a,c,d){function b(a,c){this.uri=a;this.status=c||0}function e(a,d){return c.isString(a)?b._resolve(a,d):c.map(a,function(a){return e(a,d)})}function n(a,p){var e=c.parseMap(a);x[e]?(f[a]=f[e],p()):o[e]?t[e].push(p):(o[e]=!0,t[e]=[p],b._fetch(e,function(){x[e]=!0;var b=f[a];b.status===j.FETCHING&&(b.status=j.FETCHED);u&&(l(a,u),u=null);r&&b.status===j.FETCHED&&(f[a]=r,r.realUri=a);r=null;o[e]&&delete o[e];t[e]&&(c.forEach(t[e],function(a){a()}),delete t[e])},d.charset))}function l(a,d){var s=
f[a]||(f[a]=new b(a));s.status<j.SAVED&&(s.id=d.id||a,s.dependencies=e(c.filter(d.dependencies||[],function(a){return!!a}),a),s.factory=d.factory,s.status=j.SAVED);return s}function h(a,c){var b=a(c.require,c.exports,c);void 0!==b&&(c.exports=b)}function g(a){var b=a.realUri||a.uri,e=k[b];e&&(c.forEach(e,function(c){h(c,a)}),delete k[b])}function q(a){var b=a.uri;return c.filter(a.dependencies,function(a){v=[b];if(a=m(f[a],b))v.push(b),c.log("Found circular dependencies:",v.join(" --\> "),void 0);
return!a})}function m(a,b){if(!a||a.status!==j.SAVED)return!1;v.push(a.uri);var e=a.dependencies;if(e.length){if(-1<c.indexOf(e,b))return!0;for(var d=0;d<e.length;d++)if(m(f[e[d]],b))return!0}return!1}var f={},k={},i=[],j={FETCHING:1,FETCHED:2,SAVED:3,READY:4,COMPILING:5,COMPILED:6};b.prototype._use=function(a,b){c.isString(a)&&(a=[a]);var d=e(a,this.uri);this._load(d,function(){var a=c.map(d,function(a){return a?f[a]._compile():null});b&&b.apply(null,a)})};b.prototype._load=function(a,e){function d(a){(a||
{}).status<j.READY&&(a.status=j.READY);0===--i&&e()}var y=c.filter(a,function(a){return a&&(!f[a]||f[a].status<j.READY)}),h=y.length;if(0===h)e();else for(var i=h,g=0;g<h;g++)(function(a){function e(){p=f[a];if(p.status>=j.SAVED){var h=q(p);h.length?b.prototype._load(h,function(){d(p)}):d(p)}else c.log("It is not a valid CMD module: "+a),d()}var p=f[a]||(f[a]=new b(a,j.FETCHING));p.status>=j.FETCHED?e():n(a,e)})(y[g])};b.prototype._compile=function(){function a(c){c=e(c,b.uri);c=f[c];if(!c)return null;
if(c.status===j.COMPILING)return c.exports;c.parent=b;return c._compile()}var b=this;if(b.status===j.COMPILED)return b.exports;if(b.status<j.READY&&!k[b.realUri||b.uri])return null;b.status=j.COMPILING;a.async=function(a,c){b._use(a,c)};a.resolve=function(a){return e(a,b.uri)};a.cache=f;b.require=a;b.exports={};var d=b.factory;c.isFunction(d)?(i.push(b),h(d,b),i.pop()):void 0!==d&&(b.exports=d);b.status=j.COMPILED;g(b);return b.exports};b._define=function(a,b,d){var h=arguments.length;1===h?(d=a,
a=void 0):2===h&&(d=b,b=void 0,c.isArray(a)&&(b=a,a=void 0));!c.isArray(b)&&c.isFunction(d)&&(b=c.parseDependencies(d.toString()));var h={id:a,dependencies:b,factory:d},g;if(document.attachEvent){var i=c.getCurrentScript();i&&(g=c.unParseMap(c.getScriptAbsoluteSrc(i)));g||c.log("Failed to derive URI from interactive script for:",d.toString(),"warn")}if(i=a?e(a):g){if(i===g){var k=f[g];k&&(k.realUri&&k.status===j.SAVED)&&(f[g]=null)}h=l(i,h);if(g){if((f[g]||{}).status===j.FETCHING)f[g]=h,h.realUri=
g}else r||(r=h)}else u=h};b._getCompilingModule=function(){return i[i.length-1]};b._find=function(a){var b=[];c.forEach(c.keys(f),function(d){if(c.isString(a)&&-1<d.indexOf(a)||c.isRegExp(a)&&a.test(d))d=f[d],d.exports&&b.push(d.exports)});var d=b.length;1===d?b=b[0]:0===d&&(b=null);return b};b._modify=function(b,c){var d=e(b),g=f[d];g&&g.status===j.COMPILED?h(c,g):(k[d]||(k[d]=[]),k[d].push(c));return a};b.STATUS=j;b._resolve=c.id2Uri;b._fetch=c.fetch;b.cache=f;var o={},x={},t={},u=null,r=null,v=
[],w=new b(c.pageUri,j.COMPILED);a.use=function(b,c){var e=d.preload;e.length?w._use(e,function(){d.preload=[];w._use(b,c)}):w._use(b,c);return a};a.define=b._define;a.cache=b.cache;a.find=b._find;a.modify=b._modify;a.pluginSDK={Module:b,util:c,config:d}})(seajs,seajs._util,seajs._config);
(function(a,c,d){var b="seajs-ts="+c.now(),e=document.getElementById("seajsnode");e||(e=document.getElementsByTagName("script"),e=e[e.length-1]);var n=c.getScriptAbsoluteSrc(e)||c.pageUri,n=c.dirname(function(a){if(a.indexOf("??")===-1)return a;var b=a.split("??"),a=b[0],b=c.filter(b[1].split(","),function(a){return a.indexOf("sea.js")!==-1});return a+b[0]}(n));c.loaderDir=n;var l=n.match(/^(.+\/)seajs\/[\d\.]+\/$/);l&&(n=l[1]);d.base=n;if(e=e.getAttribute("data-main"))d.main=e;d.charset="utf-8";
a.config=function(e){for(var g in e)if(e.hasOwnProperty(g)){var l=d[g],m=e[g];if(l&&g==="alias")for(var f in m){if(m.hasOwnProperty(f)){var k=l[f],i=m[f];/^\d+\.\d+\.\d+$/.test(i)&&(i=f+"/"+i+"/"+f);k&&k!==i&&c.log("The alias config is conflicted:","key =",'"'+f+'"',"previous =",'"'+k+'"',"current =",'"'+i+'"',"warn");l[f]=i}}else if(l&&(g==="map"||g==="preload")){c.isString(m)&&(m=[m]);c.forEach(m,function(a){a&&l.push(a)})}else d[g]=m}if((e=d.base)&&!c.isAbsolute(e))d.base=c.id2Uri((c.isRoot(e)?
"":"./")+e+"/");if(d.debug===2){d.debug=1;a.config({map:[[/^.*$/,function(a){a.indexOf("seajs-ts=")===-1&&(a=a+((a.indexOf("?")===-1?"?":"&")+b));return a}]]})}if(d.debug)a.debug=!!d.debug;return this};d.debug&&(a.debug=!!d.debug)})(seajs,seajs._util,seajs._config);
(function(a,c,d){a.log=c.log;a.importStyle=c.importStyle;a.config({alias:{seajs:c.loaderDir}});if(-1<d.location.search.indexOf("seajs-debug")||-1<document.cookie.indexOf("seajs=1"))a.config({debug:2}).use("seajs/plugin-debug"),a._use=a.use,a._useArgs=[],a.use=function(){a._useArgs.push(arguments);return a}})(seajs,seajs._util,this);
(function(a,c,d){var b=a._seajs;if(b&&!b.args)d.seajs=a._seajs;else{d.define=a.define;c.main&&a.use(c.main);if(c=(b||0).args){d={"0":"config",1:"use",2:"define"};for(b=0;b<c.length;b+=2)a[d[c[b]]].apply(a,c[b+1])}delete a.define;delete a._util;delete a._config;delete a._seajs}})(seajs,seajs._config,this);