context: dojo.widget.attachTemplateNodes = function(	/*DomNode*/		rootNode, 											/*Widget*/		targetObj, 											/*Array*/		events ){	// summary:	//		map widget properties and functions to the handlers specified in	//		the dom node and it's descendants. This function iterates over all	//		nodes and looks for these properties:	//			* dojoAttachPoint	//			* dojoAttachEvent		//			* waiRole	//			* waiState	//			* any "dojoOn*" proprties passed in the events array	// rootNode:	//		the node to search for properties. All children will be searched.	// events: a list of properties generated from getDojoEventsFromStr.	// 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 = [];		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){				// 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]));					}				}			}		}		// 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){				if(val.indexOf('-') == -1){ 					dojo.widget.wai.setAttr(baseNode, wai.name, "role", val);				}else{					// this is a state-value pair					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);		}	}}
meta: 4707	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/4707/50c3492c4c3c825dbd3401e134a19ed46799c456/DomWidget.js/clean/www/resources/dojo-ajax/src/widget/DomWidget.js