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

📄 domwidget.js

📁 dojo与json创建无限级树的时候,当在父结点下添加了一个新结点,我怎么让父亲结点重新调用json加载一下子结点内容.
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*	Copyright (c) 2004-2006, The Dojo Foundation	All Rights Reserved.	Licensed under the Academic Free License version 2.1 or above OR the	modified BSD license. For more information on Dojo licensing, see:		http://dojotoolkit.org/community/licensing.shtml*/dojo.provide("dojo.widget.DomWidget");dojo.require("dojo.event.*");dojo.require("dojo.widget.Widget");dojo.require("dojo.dom");dojo.require("dojo.xml.Parse");dojo.require("dojo.uri.*");dojo.require("dojo.lang.func");dojo.require("dojo.lang.extras");dojo.widget._cssFiles = {};dojo.widget._cssStrings = {};dojo.widget._templateCache = {};dojo.widget.defaultStrings = {	dojoRoot: dojo.hostenv.getBaseScriptUri(),	baseScriptUri: dojo.hostenv.getBaseScriptUri()};dojo.widget.buildFromTemplate = function() {	dojo.lang.forward("fillFromTemplateCache");}// static method to build from a template w/ or w/o a real widget in placedojo.widget.fillFromTemplateCache = function(obj, templatePath, templateCssPath, templateString, avoidCache){	// dojo.debug("avoidCache:", avoidCache);	var tpath = templatePath || obj.templatePath;	var cpath = templateCssPath || obj.templateCssPath;	// DEPRECATED: use Uri objects, not strings	if (tpath && !(tpath instanceof dojo.uri.Uri)) {		tpath = dojo.uri.dojoUri(tpath);		dojo.deprecated("templatePath should be of type dojo.uri.Uri", null, "0.4");	}	if (cpath && !(cpath instanceof dojo.uri.Uri)) {		cpath = dojo.uri.dojoUri(cpath);		dojo.deprecated("templateCssPath should be of type dojo.uri.Uri", null, "0.4");	}		var tmplts = dojo.widget._templateCache;	if(!obj["widgetType"]) { // don't have a real template here		do {			var dummyName = "__dummyTemplate__" + dojo.widget._templateCache.dummyCount++;		} while(tmplts[dummyName]);		obj.widgetType = dummyName;	}	var wt = obj.widgetType;	if(cpath && !dojo.widget._cssFiles[cpath.toString()]){		if((!obj.templateCssString)&&(cpath)){			obj.templateCssString = dojo.hostenv.getText(cpath);			obj.templateCssPath = null;		}		if((obj["templateCssString"])&&(!obj.templateCssString["loaded"])){			dojo.style.insertCssText(obj.templateCssString, null, cpath);			if(!obj.templateCssString){ obj.templateCssString = ""; }			obj.templateCssString.loaded = true;		}		dojo.widget._cssFiles[cpath.toString()] = true;	}	var ts = tmplts[wt];	if(!ts){		tmplts[wt] = { "string": null, "node": null };		if(avoidCache){			ts = {};		}else{			ts = tmplts[wt];		}	}	if((!obj.templateString)&&(!avoidCache)){		obj.templateString = templateString || ts["string"];	}	if((!obj.templateNode)&&(!avoidCache)){		obj.templateNode = ts["node"];	}	if((!obj.templateNode)&&(!obj.templateString)&&(tpath)){		// fetch a text fragment and assign it to templateString		// NOTE: we rely on blocking IO here!		var tstring = dojo.hostenv.getText(tpath);		if(tstring){			// strip <?xml ...?> declarations so that external SVG and XML			// documents can be added to a document without worry			tstring = tstring.replace(/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im, "");			var matches = tstring.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);			if(matches){				tstring = matches[1];			}		}else{			tstring = "";		}		obj.templateString = tstring;		if(!avoidCache){			tmplts[wt]["string"] = tstring;		}	}	if((!ts["string"])&&(!avoidCache)){		ts.string = obj.templateString;	}}dojo.widget._templateCache.dummyCount = 0;dojo.widget.attachProperties = ["dojoAttachPoint", "id"];dojo.widget.eventAttachProperty = "dojoAttachEvent";dojo.widget.onBuildProperty = "dojoOnBuild";dojo.widget.waiNames  = ["waiRole", "waiState"];dojo.widget.wai = {	waiRole: { 	name: "waiRole", 				namespace: "http://www.w3.org/TR/xhtml2", 				alias: "x2",				prefix: "wairole:",				nsName: "role"	},	waiState: { name: "waiState", 				namespace: "http://www.w3.org/2005/07/aaa" , 				alias: "aaa",				prefix: "",				nsName: "state"	},	setAttr: function(node, attr, value){		if(dojo.render.html.ie){			node.setAttribute(this[attr].alias+":"+this[attr].nsName, this[attr].prefix+value);		}else{			node.setAttributeNS(this[attr].namespace, this[attr].nsName, this[attr].prefix+value);		}	}};dojo.widget.attachTemplateNodes = function(rootNode, targetObj, events){	// FIXME: this method is still taking WAAAY too long. We need ways of optimizing:	//	a.) what we are looking for on each node	//	b.) the nodes that are subject to interrogation (use xpath instead?)	//	c.) how expensive event assignment is (less eval(), more connect())	// var start = new Date();	var elementNodeType = dojo.dom.ELEMENT_NODE;	function trim(str){		return str.replace(/^\s+|\s+$/g, "");	}	if(!rootNode){ 		rootNode = targetObj.domNode;	}	if(rootNode.nodeType != elementNodeType){		return;	}	// alert(events.length);	var nodes = rootNode.all || rootNode.getElementsByTagName("*");	var _this = targetObj;	for(var x=-1; x<nodes.length; x++){		var baseNode = (x == -1) ? rootNode : nodes[x];		// FIXME: is this going to have capitalization problems?  Could use getAttribute(name, 0); to get attributes case-insensitve		var attachPoint = [];		for(var y=0; y<this.attachProperties.length; y++){			var tmpAttachPoint = baseNode.getAttribute(this.attachProperties[y]);			if(tmpAttachPoint){				attachPoint = tmpAttachPoint.split(";");				for(var z=0; z<attachPoint.length; z++){					if(dojo.lang.isArray(targetObj[attachPoint[z]])){						targetObj[attachPoint[z]].push(baseNode);					}else{						targetObj[attachPoint[z]]=baseNode;					}				}				break;			}		}		// continue;		// FIXME: we need to put this into some kind of lookup structure		// instead of direct assignment		var tmpltPoint = baseNode.getAttribute(this.templateProperty);		if(tmpltPoint){			targetObj[tmpltPoint]=baseNode;		}		dojo.lang.forEach(dojo.widget.waiNames, function(name){			var wai = dojo.widget.wai[name];			var val = baseNode.getAttribute(wai.name);			if(val){				dojo.widget.wai.setAttr(baseNode, wai.name, val);			}		}, this);		var attachEvent = baseNode.getAttribute(this.eventAttachProperty);		if(attachEvent){			// NOTE: we want to support attributes that have the form			// "domEvent: nativeEvent; ..."			var evts = attachEvent.split(";");			for(var y=0; y<evts.length; y++){				if((!evts[y])||(!evts[y].length)){ continue; }				var thisFunc = null;				var tevt = trim(evts[y]);				if(evts[y].indexOf(":") >= 0){					// oh, if only JS had tuple assignment					var funcNameArr = tevt.split(":");					tevt = trim(funcNameArr[0]);					thisFunc = trim(funcNameArr[1]);				}				if(!thisFunc){					thisFunc = tevt;				}				var tf = function(){ 					var ntf = new String(thisFunc);					return function(evt){						if(_this[ntf]){							_this[ntf](dojo.event.browser.fixEvent(evt, this));						}					};				}();				dojo.event.browser.addListener(baseNode, tevt, tf, false, true);				// dojo.event.browser.addListener(baseNode, tevt, dojo.lang.hitch(_this, thisFunc));			}		}		for(var y=0; y<events.length; y++){			//alert(events[x]);			var evtVal = baseNode.getAttribute(events[y]);			if((evtVal)&&(evtVal.length)){				var thisFunc = null;				var domEvt = events[y].substr(4); // clober the "dojo" prefix				thisFunc = trim(evtVal);				var funcs = [thisFunc];				if(thisFunc.indexOf(";")>=0){					funcs = dojo.lang.map(thisFunc.split(";"), trim);				}				for(var z=0; z<funcs.length; z++){					if(!funcs[z].length){ continue; }					var tf = function(){ 						var ntf = new String(funcs[z]);						return function(evt){							if(_this[ntf]){								_this[ntf](dojo.event.browser.fixEvent(evt, this));							}						}					}();					dojo.event.browser.addListener(baseNode, domEvt, tf, false, true);					// dojo.event.browser.addListener(baseNode, domEvt, dojo.lang.hitch(_this, funcs[z]));				}			}		}		var onBuild = baseNode.getAttribute(this.onBuildProperty);		if(onBuild){			eval("var node = baseNode; var widget = targetObj; "+onBuild);		}	}}dojo.widget.getDojoEventsFromStr = function(str){	// var lstr = str.toLowerCase();	var re = /(dojoOn([a-z]+)(\s?))=/gi;	var evts = str ? str.match(re)||[] : [];	var ret = [];	var lem = {};	for(var x=0; x<evts.length; x++){		if(evts[x].legth < 1){ continue; }		var cm = evts[x].replace(/\s/, "");		cm = (cm.slice(0, cm.length-1));		if(!lem[cm]){			lem[cm] = true;			ret.push(cm);		}	}	return ret;}/*dojo.widget.buildAndAttachTemplate = function(obj, templatePath, templateCssPath, templateString, targetObj) {	this.buildFromTemplate(obj, templatePath, templateCssPath, templateString);	var node = dojo.dom.createNodesFromText(obj.templateString, true)[0];	this.attachTemplateNodes(node, targetObj||obj, dojo.widget.getDojoEventsFromStr(templateString));	return node;}*/dojo.declare("dojo.widget.DomWidget", dojo.widget.Widget, {	initializer: function() {		if((arguments.length>0)&&(typeof arguments[0] == "object")){			this.create(arguments[0]);		}	},								 

⌨️ 快捷键说明

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