📄 loader_xd.js
字号:
var locales = availableFlatLocales.split(","); //Find the best-match locale to load. var jsLoc = dojo.hostenv.normalizeLocale(locale); var bestLocale = ""; for(var i = 0; i < locales.length; i++){ //Locale must match from start of string. if(jsLoc.indexOf(locales[i]) == 0){ if(locales[i].length > bestLocale.length){ bestLocale = locales[i]; } } } var fixedBestLocale = bestLocale.replace('-', '_'); //See if the bundle we are going to use is already loaded. var bundlePackage = dojo.evalObjPath([moduleName, "nls", bundleName].join(".")); if(bundlePackage && bundlePackage[fixedBestLocale]){ bundle[jsLoc.replace('-', '_')] = bundlePackage[fixedBestLocale]; }else{ //Need to remember what locale we wanted and which one we actually use. //Then when we load the one we are actually using, use that bundle for the one //we originally wanted. var mapName = [moduleName, (fixedBestLocale||"root"), bundleName].join("."); var bundleMap = dojo.hostenv.xdBundleMap[mapName]; if(!bundleMap){ bundleMap = dojo.hostenv.xdBundleMap[mapName] = {}; } bundleMap[jsLoc.replace('-', '_')] = true; //Do just a normal dojo.require so the package tracking stuff works as usual. dojo.require(moduleName + ".nls" + (bestLocale ? "." + bestLocale : "") + "." + bundleName); }};(function(){ // Simulate the extra locale work that dojo.requireLocalization does. var extra = djConfig.extraLocale; if(extra){ if(!extra instanceof Array){ extra = [extra]; } dojo._xdReqLoc = dojo.xdRequireLocalization; dojo.xdRequireLocalization = function(m, b, locale, fLocales){ dojo._xdReqLoc(m,b,locale, fLocales); if(locale){return;} for(var i=0; i<extra.length; i++){ dojo._xdReqLoc(m,b,extra[i], fLocales); } }; }})();//This is a bit brittle: it has to know about the dojo methods that deal with dependencies//It would be ideal to intercept the actual methods and do something fancy at that point,//but I have concern about knowing which provide to match to the dependency in that case,//since scripts can load whenever they want, and trigger new calls to dojo.hostenv.packageLoaded().dojo.hostenv.unpackXdDependency = function(dep){ //summary: Internal xd loader function. Determines what to do with a dependency //that was listed in an xd version of a module contents. //Extract the dependency(ies). var newDeps = null; var newAfterDeps = null; switch(dep[0]){ case "requireIf": case "requireAfterIf": case "conditionalRequire": //First arg (dep[1]) is the test. Depedency is dep[2]. if((dep[1] === true)||(dep[1]=="common")||(dep[1] && dojo.render[dep[1]].capable)){ newDeps = [{name: dep[2], content: null}]; } break; case "requireAll": //the arguments are an array, each element a call to require. //Get rid of first item, which is "requireAll". dep.shift(); newDeps = dep; dojo.hostenv.flattenRequireArray(newDeps); break; case "kwCompoundRequire": case "hostenv.conditionalLoadModule": var modMap = dep[1]; var common = modMap["common"]||[]; var newDeps = (modMap[dojo.hostenv.name_]) ? common.concat(modMap[dojo.hostenv.name_]||[]) : common.concat(modMap["default"]||[]); dojo.hostenv.flattenRequireArray(newDeps); break; case "require": case "requireAfter": case "hostenv.loadModule": //Just worry about dep[1] newDeps = [{name: dep[1], content: null}]; break; } //The requireAfterIf or requireAfter needs to be evaluated after the current package is evaluated. if(dep[0] == "requireAfterIf"){ newAfterDeps = newDeps; newDeps = null; } return {requires: newDeps, requiresAfter: newAfterDeps}; //Object}dojo.hostenv.xdWalkReqs = function(){ //summary: Internal xd loader function. //Walks the requires and evaluates package contents in //the right order. var reqChain = null; var req; for(var i = 0; i < this.xdOrderedReqs.length; i++){ req = this.xdOrderedReqs[i]; if(this.xdDepMap[req]){ reqChain = [req]; reqChain[req] = true; //Allow for fast lookup of the req in the array this.xdEvalReqs(reqChain); } }}dojo.hostenv.xdTraceReqs = function(/*Object*/reqs, /*Array*/reqChain){ //summary: Internal xd loader function. //Trace the requires to chain the correct order of required modules. if(reqs && reqs.length > 0){ var nextReq; for(var i = 0; i < reqs.length; i++){ nextReq = reqs[i].name; if(nextReq && !reqChain[nextReq]){ //New req depedency. Follow it down. reqChain.push(nextReq); reqChain[nextReq] = true; this.xdEvalReqs(reqChain); } } }}dojo.hostenv.xdEvalReqs = function(/*Array*/reqChain){ //summary: Internal xd loader function. //Does a depth first, breadth second search and eval of required modules. if(reqChain.length > 0){ var req = reqChain[reqChain.length - 1]; var pkg = this.xdDepMap[req]; if(pkg){ //Trace down any requires for this package. this.xdTraceReqs(pkg.requires, reqChain); //Evaluate the package. var contents = this.xdContents[pkg.contentIndex]; if(!contents.isDefined){ //Evaluate the package to bring it into being. //Pass dojo in so that later, to support multiple versions of dojo //in a page, we can pass which version of dojo to use. contents.content(dojo); contents.isDefined = true; } this.xdDepMap[req] = null; //Trace down any requireAfters for this package.. this.xdTraceReqs(pkg.requiresAfter, reqChain); } //Done with that require. Remove it and go to the next one. reqChain.pop(); this.xdEvalReqs(reqChain); }}dojo.hostenv.clearXdInterval = function(){ //summary: Internal xd loader function. //Clears the interval timer used to check on the //status of in-flight xd module resource requests. clearInterval(this.xdTimer); this.xdTimer = 0;}dojo.hostenv.watchInFlightXDomain = function(){ //summary: Internal xd loader function. //Monitors in-flight requests for xd module resources. //Make sure we haven't waited timed out. var waitInterval = (djConfig.xdWaitSeconds || 30) * 1000; if(this.xdStartTime + waitInterval < (new Date()).getTime()){ this.clearXdInterval(); var noLoads = ""; for(var param in this.xdInFlight){ if(this.xdInFlight[param]){ noLoads += param + " "; } } dojo.raise("Could not load cross-domain packages: " + noLoads); } //If any are true, then still waiting. //Come back later. for(var param in this.xdInFlight){ if(this.xdInFlight[param]){ return; } } //All done loading. Clean up and notify that we are loaded. this.clearXdInterval(); this.xdWalkReqs(); //Evaluate any packages that were not evaled before. //This normally shouldn't happen with proper dojo.provide and dojo.require //usage, but providing it just in case. Note that these may not be executed //in the original order that the developer intended. //Pass dojo in so that later, to support multiple versions of dojo //in a page, we can pass which version of dojo to use. for(var i = 0; i < this.xdContents.length; i++){ var current = this.xdContents[i]; if(current.content && !current.isDefined){ current.content(dojo); } } //Clean up for the next round of xd loading. this.resetXd(); //Clear inflight count so we will finally do finish work. this.inFlightCount = 0; this.callLoaded();}dojo.hostenv.flattenRequireArray = function(/*Array*/target){ //summary: Internal xd loader function. //Flattens an array of arrays into a one-level deep array. //Each result could be an array of 3 elements (the 3 arguments to dojo.require). //We only need the first one. if(target){ for(var i = 0; i < target.length; i++){ if(target[i] instanceof Array){ target[i] = {name: target[i][0], content: null}; }else{ target[i] = {name: target[i], content: null}; } } }}dojo.hostenv.xdHasCalledPreload = false;dojo.hostenv.xdRealCallLoaded = dojo.hostenv.callLoaded;dojo.hostenv.callLoaded = function(){ //summary: Internal xd loader function. Overrides callLoaded() from loader.js //description: The method is overridden because xd loading needs to preload //any flattened i18n bundles before dojo starts executing code, //since xd loading cannot do it synchronously, as the i18n code normally expects. //If getModulePrefix for dojo returns anything other than "src", that means //there is a path registered for dojo, with implies that dojo was xdomain loaded. if(this.xdHasCalledPreload || dojo.hostenv.getModulePrefix("dojo") == "src" || !this.localesGenerated){ this.xdRealCallLoaded(); this.xdHasCalledPreload = true; }else{ if(this.localesGenerated){ this.registerNlsPrefix = function(){ //Need to set the nls prefix to be the xd location. dojo.registerModulePath("nls", dojo.hostenv.getModulePrefix("dojo") + "/../nls"); }; this.preloadLocalizations(); } this.xdHasCalledPreload = true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -