⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loader_xd.js

📁 ajax框架原吗,dojo目前很流行的,希望大家多多学习啊
💻 JS
📖 第 1 页 / 共 2 页
字号:
if(!dojo._hasResource["dojo._base._loader.loader_xd"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojo._base._loader.loader_xd"] = true;//Cross-domain resource loader.dojo.provide("dojo._base._loader.loader_xd");dojo._xdReset = function(){	//summary: Internal xd loader function. Resets the xd state.	//This flag indicates where or not we have crossed into xdomain territory. Once any resource says	//it is cross domain, then the rest of the resources have to be treated as xdomain because we need	//to evaluate resources in order. If there is a xdomain resource followed by a xhr resource, we can't load	//the xhr resource until the one before it finishes loading. The text of the xhr resource will be converted	//to match the format for a xd resource and put in the xd load queue.	this._isXDomain = djConfig.useXDomain || false;	this._xdTimer = 0;	this._xdInFlight = {};	this._xdOrderedReqs = [];	this._xdDepMap = {};	this._xdContents = [];	this._xdDefList = [];}//Call reset immediately to set the state.dojo._xdReset();dojo._xdCreateResource = function(/*String*/contents, /*String*/resourceName, /*String*/resourcePath){	//summary: Internal xd loader function. Creates an xd module source given an	//non-xd module contents.	//Remove comments. Not perfect, but good enough for dependency resolution.	var depContents = contents.replace(/(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg , "");	//Find dependencies.	var deps = [];    var depRegExp = /dojo.(require|requireIf|provide|requireAfterIf|platformRequire|requireLocalization)\(([\w\W]*?)\)/mg;    var match;	while((match = depRegExp.exec(depContents)) != null){		if(match[1] == "requireLocalization"){			//Need to load the local bundles asap, since they are not			//part of the list of modules watched for loading.			eval(match[0]);		}else{			deps.push('"' + match[1] + '", ' + match[2]);		}	}	//Create resource object and the call to _xdResourceLoaded.	var output = [];	output.push("dojo._xdResourceLoaded({\n");	//Add dependencies	if(deps.length > 0){		output.push("depends: [");		for(var i = 0; i < deps.length; i++){			if(i > 0){				output.push(",\n");			}			output.push("[" + deps[i] + "]");		}		output.push("],");	}	//Add the contents of the file inside a function.	//Pass in dojo as an argument to the function to help with	//allowing multiple versions of dojo in a page.	output.push("\ndefineResource: function(dojo){");		//Don't put in the contents in the debugAtAllCosts case	//since the contents may have syntax errors. Let those	//get pushed up when the script tags are added to the page	//in the debugAtAllCosts case.	if(!djConfig["debugAtAllCosts"] || resourceName == "dojo._base._loader.loader_debug"){		output.push(contents);	}	//Add isLocal property so we know if we have to do something different	//in debugAtAllCosts situations.	output.push("\n}, resourceName: '" + resourceName + "', resourcePath: '" + resourcePath + "'});");		return output.join(""); //String}dojo._xdIsXDomainPath = function(/*string*/relpath) {    //summary: Figure out whether the path is local or x-domain	//If there is a colon before the first / then, we have a URL with a protocol.    	var colonIndex = relpath.indexOf(":");	var slashIndex = relpath.indexOf("/");	if(colonIndex > 0 && colonIndex < slashIndex){		return true;	}else{		//Is the base script URI-based URL a cross domain URL?		//If so, then the relpath will be evaluated relative to		//baseUrl, and therefore qualify as xdomain.		//Only treat it as xdomain if the page does not have a		//host (file:// url) or if the baseUrl does not match the		//current window's domain.		var url = this.baseUrl;		colonIndex = url.indexOf(":");		slashIndex = url.indexOf("/");		if(colonIndex > 0 && colonIndex < slashIndex && (!location.host || url.indexOf("http://" + location.host) != 0)){			return true;		}	}    return false;     }dojo._loadPath = function(/*String*/relpath, /*String?*/module, /*Function?*/cb){	//summary: Internal xd loader function. Overrides loadPath() from loader.js.	//xd loading requires slightly different behavior from loadPath().	var currentIsXDomain = this._xdIsXDomainPath(relpath);    this._isXDomain |= currentIsXDomain;	var uri = this.baseUrl + relpath;	if(currentIsXDomain){        // check whether the relpath is an absolute URL itself. If so, we         // ignore baseUrl    	var colonIndex = relpath.indexOf(":");    	var slashIndex = relpath.indexOf("/");        if(colonIndex > 0 && colonIndex < slashIndex){ 		    uri = relpath;    	}    }	if(djConfig.cacheBust && dojo.isBrowser) { uri += "?" + String(djConfig.cacheBust).replace(/\W+/g,""); }	try{		return ((!module || this._isXDomain) ? this._loadUri(uri, cb, currentIsXDomain, module) : this._loadUriAndCheck(uri, module, cb)); //Boolean	}catch(e){		console.debug(e);		return false; //Boolean	}}dojo._loadUri = function(/*String*/uri, /*Function?*/cb, /*boolean*/currentIsXDomain, /*String?*/module){	//summary: Internal xd loader function. Overrides loadUri() from loader.js.	//		xd loading requires slightly different behavior from loadPath().	//description: Wanted to override getText(), but it is used by	//		the widget code in too many, synchronous ways right now.	if(this._loadedUrls[uri]){		return 1; //Boolean	}	//Add the module (resource) to the list of modules.	//Only do this work if we have a modlue name. Otherwise, 	//it is a non-xd i18n bundle, which can load immediately and does not 	//need to be tracked. Also, don't track dojo.i18n, since it is a prerequisite	//and will be loaded correctly if we load it right away: it has no dependencies.	if(this._isXDomain && module && module != "dojo.i18n"){		this._xdOrderedReqs.push(module);		//Add to waiting resources if it is an xdomain resource.		//Don't add non-xdomain i18n bundles, those get evaled immediately.		if(currentIsXDomain || uri.indexOf("/nls/") == -1){			this._xdInFlight[module] = true;			//Increment inFlightCount			//This will stop the modulesLoaded from firing all the way.			this._inFlightCount++;		}		//Start timer		if(!this._xdTimer){			this._xdTimer = setInterval("dojo._xdWatchInFlight();", 100);		}		this._xdStartTime = (new Date()).getTime();	}	if (currentIsXDomain){		//Fix name to be a .xd.fileextension name.		var lastIndex = uri.lastIndexOf('.');		if(lastIndex <= 0){			lastIndex = uri.length - 1;		}		var xdUri = uri.substring(0, lastIndex) + ".xd";		if(lastIndex != uri.length - 1){			xdUri += uri.substring(lastIndex, uri.length);		}		//Add to script src		var element = document.createElement("script");		element.type = "text/javascript";		element.src = xdUri;		if(!this.headElement){			this._headElement = document.getElementsByTagName("head")[0];			//Head element may not exist, particularly in html			//html 4 or tag soup cases where the page does not			//have a head tag in it. Use html element, since that will exist.			//Seems to be an issue mostly with Opera 9 and to lesser extent Safari 2			if(!this._headElement){				this._headElement = document.getElementsByTagName("html")[0];			}		}		this._headElement.appendChild(element);	}else{		var contents = this._getText(uri, null, true);		if(contents == null){ return 0; /*boolean*/}				//If this is not xdomain, or if loading a i18n resource bundle, then send it down		//the normal eval/callback path.		if(this._isXDomain			&& uri.indexOf("/nls/") == -1			&& module != "dojo.i18n"){			var res = this._xdCreateResource(contents, module, uri);			dojo.eval(res);		}else{			if(cb){ contents = '('+contents+')'; }			var value = dojo.eval(contents);			if(cb){				cb(value);			}		}	}	//These steps are done in the non-xd loader version of this function.	//Maintain these steps to fit in with the existing system.	this._loadedUrls[uri] = true;	this._loadedUrls.push(uri);	return true; //Boolean}dojo._xdResourceLoaded = function(/*Object*/res){	//summary: Internal xd loader function. Called by an xd module resource when	//it has been loaded via a script tag.	var deps = res.depends;	var requireList = null;	var requireAfterList = null;	var provideList = [];	if(deps && deps.length > 0){		var dep = null;		var insertHint = 0;		var attachedResource = false;		for(var i = 0; i < deps.length; i++){			dep = deps[i];			//Look for specific dependency indicators.			if (dep[0] == "provide"){				provideList.push(dep[1]);			}else{				if(!requireList){					requireList = [];				}				if(!requireAfterList){					requireAfterList = [];				}				var unpackedDeps = this._xdUnpackDependency(dep);				if(unpackedDeps.requires){					requireList = requireList.concat(unpackedDeps.requires);				}				if(unpackedDeps.requiresAfter){					requireAfterList = requireAfterList.concat(unpackedDeps.requiresAfter);				}			}			//Call the dependency indicator to allow for the normal dojo setup.			//Only allow for one dot reference, for the i18n._preloadLocalizations calls			//(and maybe future, one-dot things).			var depType = dep[0];			var objPath = depType.split(".");			if(objPath.length == 2){				dojo[objPath[0]][objPath[1]].apply(dojo[objPath[0]], dep.slice(1));			}else{				dojo[depType].apply(dojo, dep.slice(1));			}		}		//If loading the debugAtAllCosts module, eval it right away since we need		//its functions to properly load the other modules.		if(provideList.length == 1 && provideList[0] == "dojo._base._loader.loader_debug"){			res.defineResource(dojo);		}else{			//Save off the resource contents for definition later.			var contentIndex = this._xdContents.push({					content: res.defineResource,					resourceName: res["resourceName"],					resourcePath: res["resourcePath"],					isDefined: false				}) - 1;				//Add provide/requires to dependency map.			for(var i = 0; i < provideList.length; i++){				this._xdDepMap[provideList[i]] = { requires: requireList, requiresAfter: requireAfterList, contentIndex: contentIndex };			}		}		//Now update the inflight status for any provided resources in this loaded resource.		//Do this at the very end (in a *separate* for loop) to avoid shutting down the 		//inflight timer check too soon.		for(var i = 0; i < provideList.length; i++){			this._xdInFlight[provideList[i]] = false;		}	}}dojo._xdLoadFlattenedBundle = function(/*String*/moduleName, /*String*/bundleName, /*String?*/locale, /*Object*/bundleData){	//summary: Internal xd loader function. Used when loading	//a flattened localized bundle via a script tag.	locale = locale || "root";	var jsLoc = dojo.i18n.normalizeLocale(locale).replace('-', '_'); 	var bundleResource = [moduleName, "nls", bundleName].join(".");	var bundle = dojo["provide"](bundleResource);	bundle[jsLoc] = bundleData;		//Assign the bundle for the original locale(s) we wanted.	var mapName = [moduleName, jsLoc, bundleName].join(".");	var bundleMap = dojo._xdBundleMap[mapName];	if(bundleMap){		for(var param in bundleMap){			bundle[param] = bundleData;		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -