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

📄 domwidget.js

📁 初学者
💻 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.html.style");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(), dojoWidgetModuleUri:dojo.uri.moduleUri("dojo.widget"), baseScriptUri:dojo.hostenv.getBaseScriptUri()};dojo.widget.fillFromTemplateCache = function (obj, templatePath, templateString, avoidCache) {	var tpath = templatePath || obj.templatePath;	var tmplts = dojo.widget._templateCache;	if (!tpath && !obj["widgetType"]) {		do {			var dummyName = "__dummyTemplate__" + dojo.widget._templateCache.dummyCount++;		} while (tmplts[dummyName]);		obj.widgetType = dummyName;	}	var wt = tpath ? tpath.toString() : obj.widgetType;	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.templateString) {		obj.templateString = this._sanitizeTemplateString(obj.templateString);	}	if ((!obj.templateNode) && (!avoidCache)) {		obj.templateNode = ts["node"];	}	if ((!obj.templateNode) && (!obj.templateString) && (tpath)) {		var tstring = this._sanitizeTemplateString(dojo.hostenv.getText(tpath));		obj.templateString = tstring;		if (!avoidCache) {			tmplts[wt]["string"] = tstring;		}	}	if ((!ts["string"]) && (!avoidCache)) {		ts.string = obj.templateString;	}};dojo.widget._sanitizeTemplateString = function (tString) {	if (tString) {		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 = "";	}	return tString;};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:"}, waiState:{name:"waiState", "namespace":"http://www.w3.org/2005/07/aaa", alias:"aaa", prefix:""}, setAttr:function (node, ns, attr, value) {	if (dojo.render.html.ie) {		node.setAttribute(this[ns].alias + ":" + attr, this[ns].prefix + value);	} else {		node.setAttributeNS(this[ns]["namespace"], attr, this[ns].prefix + value);	}}, getAttr:function (node, ns, attr) {	if (dojo.render.html.ie) {		return node.getAttribute(this[ns].alias + ":" + attr);	} else {		return node.getAttributeNS(this[ns]["namespace"], attr);	}}, removeAttr:function (node, ns, attr) {	var success = true;	if (dojo.render.html.ie) {		success = node.removeAttribute(this[ns].alias + ":" + attr);	} else {		node.removeAttributeNS(this[ns]["namespace"], attr);	}	return success;}};dojo.widget.attachTemplateNodes = function (rootNode, targetObj, events) {	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;	}	var nodes = rootNode.all || rootNode.getElementsByTagName("*");	var _this = targetObj;	for (var x = -1; x < nodes.length; x++) {		var baseNode = (x == -1) ? rootNode : nodes[x];		var attachPoint = [];		if (!targetObj.widgetsInTemplate || !baseNode.getAttribute("dojoType")) {			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;				}			}			var attachEvent = baseNode.getAttribute(this.eventAttachProperty);			if (attachEvent) {				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) {						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);				}			}			for (var y = 0; y < events.length; y++) {				var evtVal = baseNode.getAttribute(events[y]);				if ((evtVal) && (evtVal.length)) {					var thisFunc = null;					var domEvt = events[y].substr(4);					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);					}				}			}		}		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) {				if (val.indexOf("-") == -1) {					dojo.widget.wai.setAttr(baseNode, wai.name, "role", val);				} else {					var statePair = val.split("-");					dojo.widget.wai.setAttr(baseNode, wai.name, statePair[0], statePair[1]);				}			}		}, this);		var onBuild = baseNode.getAttribute(this.onBuildProperty);		if (onBuild) {			eval("var node = baseNode; var widget = targetObj; " + onBuild);		}	}};dojo.widget.getDojoEventsFromStr = function (str) {	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].length < 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.declare("dojo.widget.DomWidget", dojo.widget.Widget, function () {	if ((arguments.length > 0) && (typeof arguments[0] == "object")) {		this.create(arguments[0]);	}}, {templateNode:null, templateString:null, templateCssString:null, preventClobber:false, domNode:null, containerNode:null, widgetsInTemplate:false, addChild:function (widget, overrideContainerNode, pos, ref, insertIndex) {	if (!this.isContainer) {		dojo.debug("dojo.widget.DomWidget.addChild() attempted on non-container widget");		return null;	} else {		if (insertIndex == undefined) {			insertIndex = this.children.length;		}		this.addWidgetAsDirectChild(widget, overrideContainerNode, pos, ref, insertIndex);		this.registerChild(widget, insertIndex);	}	return widget;}, addWidgetAsDirectChild:function (widget, overrideContainerNode, pos, ref, insertIndex) {	if ((!this.containerNode) && (!overrideContainerNode)) {		this.containerNode = this.domNode;	}	var cn = (overrideContainerNode) ? overrideContainerNode : this.containerNode;	if (!pos) {		pos = "after";	}	if (!ref) {		if (!cn) {

⌨️ 快捷键说明

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