From 81bea17aefb26859f825b9293c7c99192874806e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 8 Nov 2011 20:40:44 +0400 Subject: upgrade Dojo to 1.6.1 --- lib/dojo/parser.js | 302 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 206 insertions(+), 96 deletions(-) (limited to 'lib/dojo/parser.js') diff --git a/lib/dojo/parser.js b/lib/dojo/parser.js index 7ae035691..bd52030e0 100644 --- a/lib/dojo/parser.js +++ b/lib/dojo/parser.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, 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 */ @@ -10,14 +10,14 @@ 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 + // summary: + // The Dom/Widget parsing package var d = dojo; - this._attrName = d._scopeName + "Type"; - this._query = "[" + this._attrName + "]"; function val2type(/*Object*/ value){ // summary: @@ -42,13 +42,13 @@ dojo.parser = new function(){ case "number": return value.length ? Number(value) : NaN; case "boolean": - // for checked/disabled value might be "" or "checked". interpret as true. + // 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 + // (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)); } @@ -77,7 +77,7 @@ dojo.parser = new function(){ } } - var instanceClasses = { + var dummyClass = {}, instanceClasses = { // map from fully qualified name (like "dijit.Button") to structure like // { cls: dijit.Button, params: {label: "string", disabled: "boolean"} } }; @@ -85,45 +85,70 @@ dojo.parser = new function(){ // 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(){ + // TODO: remove this in 2.0, when we stop caching parameters. + d.connect(d, "extend", function(){ instanceClasses = {}; }); - function getClassInfo(/*String*/ className){ + function getProtoInfo(cls, params){ + // cls: A prototype + // The prototype of the class to check props on + // params: Object + // The parameters object to mix found parameters onto. + for(var name in cls){ + if(name.charAt(0)=="_"){ continue; } // skip internal properties + if(name in dummyClass){ continue; } // skip "constructor" and "toString" + params[name] = val2type(cls[name]); + } + return params; + } + + function getClassInfo(/*String*/ className, /*Boolean*/ skipParamsLookup){ + // summary: + // Maps a widget name string like "dijit.form.Button" to the widget constructor itself, + // and a list of that widget's parameters and their types // className: // fully qualified name (like "dijit.form.Button") // returns: // structure like - // { - // cls: dijit.Button, + // { + // cls: dijit.Button, // params: { label: "string", disabled: "boolean"} // } - if(!instanceClasses[className]){ + var c = instanceClasses[className]; + if(!c){ // get pointer to widget class - var cls = d.getObject(className); + var cls = d.getObject(className), params = null; 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); + if(!skipParamsLookup){ // from fastpath, we don't need to lookup the attrs on the proto because they are explicit + params = getProtoInfo(cls.prototype, {}) } - - instanceClasses[className] = { cls: cls, params: params }; + c = { cls: cls, params: params }; + + }else if(!skipParamsLookup && !c.params){ + // if we're calling getClassInfo and have a cls proto, but no params info, scan that cls for params now + // and update the pointer in instanceClasses[className]. This happens when a widget appears in another + // widget's template which still uses dojoType, but an instance of the widget appears prior with a data-dojo-type, + // skipping this lookup the first time. + c.params = getProtoInfo(c.cls.prototype, {}); } - return instanceClasses[className]; + + return c; } - this._functionFromScript = function(script){ + this._functionFromScript = function(script, attrData){ + // summary: + // Convert a + // into a function + // script: DOMNode + // The