/* Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ if(!dojo._hasResource["dojo.parser"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. dojo._hasResource["dojo.parser"] = true; dojo.provide("dojo.parser"); dojo.require("dojo.date.stamp"); new Date("X"); // workaround for #11279, new Date("") == NaN dojo.parser = new function(){ // summary: The Dom/Widget parsing package var d = dojo; this._attrName = d._scopeName + "Type"; this._query = "[" + this._attrName + "]"; function val2type(/*Object*/ value){ // summary: // Returns name of type of given value. if(d.isString(value)){ return "string"; } if(typeof value == "number"){ return "number"; } if(typeof value == "boolean"){ return "boolean"; } if(d.isFunction(value)){ return "function"; } if(d.isArray(value)){ return "array"; } // typeof [] == "object" if(value instanceof Date) { return "date"; } // assume timestamp if(value instanceof d._Url){ return "url"; } return "object"; } function str2obj(/*String*/ value, /*String*/ type){ // summary: // Convert given string value to given type switch(type){ case "string": return value; case "number": return value.length ? Number(value) : NaN; case "boolean": // for checked/disabled value might be "" or "checked". interpret as true. return typeof value == "boolean" ? value : !(value.toLowerCase()=="false"); case "function": if(d.isFunction(value)){ // IE gives us a function, even when we say something like onClick="foo" // (in which case it gives us an invalid function "function(){ foo }"). // Therefore, convert to string value=value.toString(); value=d.trim(value.substring(value.indexOf('{')+1, value.length-1)); } try{ if(value === "" || value.search(/[^\w\.]+/i) != -1){ // The user has specified some text for a function like "return x+5" return new Function(value); }else{ // The user has specified the name of a function like "myOnClick" // or a single word function "return" return d.getObject(value, false) || new Function(value); } }catch(e){ return new Function(); } case "array": return value ? value.split(/\s*,\s*/) : []; case "date": switch(value){ case "": return new Date(""); // the NaN of dates case "now": return new Date(); // current date default: return d.date.stamp.fromISOString(value); } case "url": return d.baseUrl + value; default: return d.fromJson(value); } } var instanceClasses = { // map from fully qualified name (like "dijit.Button") to structure like // { cls: dijit.Button, params: {label: "string", disabled: "boolean"} } }; // Widgets like BorderContainer add properties to _Widget via dojo.extend(). // If BorderContainer is loaded after _Widget's parameter list has been cached, // we need to refresh that parameter list (for _Widget and all widgets that extend _Widget). dojo.connect(dojo, "extend", function(){ instanceClasses = {}; }); function getClassInfo(/*String*/ className){ // className: // fully qualified name (like "dijit.form.Button") // returns: // structure like // { // cls: dijit.Button, // params: { label: "string", disabled: "boolean"} // } if(!instanceClasses[className]){ // get pointer to widget class var cls = d.getObject(className); if(!cls){ return null; } // class not defined [yet] var proto = cls.prototype; // get table of parameter names & types var params = {}, dummyClass = {}; for(var name in proto){ if(name.charAt(0)=="_"){ continue; } // skip internal properties if(name in dummyClass){ continue; } // skip "constructor" and "toString" var defVal = proto[name]; params[name]=val2type(defVal); } instanceClasses[className] = { cls: cls, params: params }; } return instanceClasses[className]; } this._functionFromScript = function(script){ var preamble = ""; var suffix = ""; var argsStr = script.getAttribute("args"); if(argsStr){ d.forEach(argsStr.split(/\s*,\s*/), function(part, idx){ preamble += "var "+part+" = arguments["+idx+"]; "; }); } var withStr = script.getAttribute("with"); if(withStr && withStr.length){ d.forEach(withStr.split(/\s*,\s*/), function(part){ preamble += "with("+part+"){"; suffix += "}"; }); } return new Function(preamble+script.innerHTML+suffix); } this.instantiate = function(/* Array */nodes, /* Object? */mixin, /* Object? */args){ // summary: // Takes array of nodes, and turns them into class instances and // potentially calls a startup method to allow them to connect with // any children. // nodes: Array // Array of nodes or objects like // | { // | type: "dijit.form.Button", // | node: DOMNode, // | scripts: [ ... ], // array of