dojo.parser.instantiate
dojo.require("dojo.parser");
defined in dojo/parser.js
Takes array of nodes, and turns them into class instances and potentially calls a layout method to allow them to connect with any children
Usage
function (/*Array*/ nodes) (view source)
var thelist = []; d.forEach(nodes, function(node){ if(!node){ return; } var type = node.getAttribute(dtName); if((!type)||(!type.length)){ return; } var clsInfo = getClassInfo(type); var clazz = clsInfo.cls; var ps = clazz._noScript||clazz.prototype._noScript; // read parameters (ie, attributes). // clsInfo.params lists expected params like {"checked": "boolean", "n": "number"} var params = {}; var attributes = node.attributes; for(var name in clsInfo.params){ var item = attributes.getNamedItem(name); if(!item || (!item.specified && (!dojo.isIE || name.toLowerCase()!="value"))){ continue; } var value = item.value; // Deal with IE quirks for 'class' and 'style' switch(name){ case "class": value = node.className; break; case "style": value = node.style && node.style.cssText; // FIXME: Opera? } var _type = clsInfo.params[name]; params[name] = str2obj(value, _type); } // Process <script type="dojo/*"> script tags // <script type="dojo/method" event="foo"> tags are added to params, and passed to // the widget on instantiation. // <script type="dojo/method"> tags (with no event) are executed after instantiation // <script type="dojo/connect" event="foo"> tags are dojo.connected after instantiation // note: dojo/* script tags cannot exist in self closing widgets, like <input /> if(!ps){ var connects = [], // functions to connect after instantiation calls = []; // functions to call after instantiation d.query("> script[type^='dojo/']", node).orphan().forEach(function(script){ var event = script.getAttribute("event"), type = script.getAttribute("type"), nf = d.parser._functionFromScript(script); if(event){ if(type == "dojo/connect"){ connects.push({event: event, func: nf}); }else{ params[event] = nf; } }else{ calls.push(nf); } }); } var markupFactory = clazz["markupFactory"]; if(!markupFactory && clazz["prototype"]){ markupFactory = clazz.prototype["markupFactory"]; } // create the instance var instance = markupFactory ? markupFactory(params, node, clazz) : new clazz(params, node); thelist.push(instance); // map it to the JS namespace if that makes sense var jsname = node.getAttribute("jsId"); if(jsname){ d.setObject(jsname, instance); } // process connections and startup functions if(!ps){ d.forEach(connects, function(connect){ d.connect(instance, connect.event, null, connect.func); }); d.forEach(calls, function(func){ func.call(instance); }); } }); // Call startup on each top level instance if it makes sense (as for // widgets). Parent widgets will recursively call startup on their // (non-top level) children d.forEach(thelist, function(instance){ if( instance && instance.startup && !instance._started && (!instance.getParent || !instance.getParent()) ){ instance.startup(); } }); return thelist;
parameter | type | description |
---|---|---|
nodes | Array |