Changeset 9936
- Timestamp:
- 08/03/07 04:55:10 (16 months ago)
- Files:
-
- 1 modified
-
dojo/trunk/parser.js (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dojo/trunk/parser.js
r9747 r9936 4 4 dojo.parser = new function(){ 5 5 6 var d = dojo; 7 6 8 function val2type(/*Object*/ value){ 7 9 // summary: 8 10 // Returns name of type of given value. 9 11 10 if(d ojo.isString(value)){ return "string"; }12 if(d.isString(value)){ return "string"; } 11 13 if(typeof value == "number"){ return "number"; } 12 14 if(typeof value == "boolean"){ return "boolean"; } 13 if(d ojo.isFunction(value)){ return "function"; }14 if(d ojo.isArray(value)){ return "array"; } // typeof [] == "object"15 if(d.isFunction(value)){ return "function"; } 16 if(d.isArray(value)){ return "array"; } // typeof [] == "object" 15 17 if(value instanceof Date) { return "date"; } // assume timestamp 16 if(value instanceof d ojo._Url){ return "url"; }18 if(value instanceof d._Url){ return "url"; } 17 19 return "object"; 18 20 } … … 29 31 return typeof value == "boolean" ? value : !(value.toLowerCase()=="false"); 30 32 case "function": 31 if(d ojo.isFunction(value)){33 if(d.isFunction(value)){ 32 34 // IE gives us a function, even when we say something like onClick="foo" 33 35 // (in which case it gives us an invalid function "function(){ foo }"). 34 36 // Therefore, convert to string 35 37 value=value.toString(); 36 value=d ojo.trim(value.substring(value.indexOf('{')+1, value.length-1));38 value=d.trim(value.substring(value.indexOf('{')+1, value.length-1)); 37 39 } 38 40 try{ 39 41 if(value.search(/[^\w\.]+/i) != -1){ 40 42 // TODO: "this" here won't work 41 value = d ojo.parser._nameAnonFunc(new Function(value), this);43 value = d.parser._nameAnonFunc(new Function(value), this); 42 44 } 43 return d ojo.getObject(value, false);45 return d.getObject(value, false); 44 46 }catch(e){ return new Function(); } 45 47 case "array": 46 48 return value.split(/\s*,\s*/); 47 49 case "date": 48 return d ojo.date.stamp.fromISOString(value);50 return d.date.stamp.fromISOString(value); 49 51 case "url": 50 return d ojo.baseUrl + value;52 return d.baseUrl + value; 51 53 default: 52 return d ojo.fromJson(value);54 return d.fromJson(value); 53 55 } 54 56 } … … 71 73 if(!instanceClasses[className]){ 72 74 // get pointer to widget class 73 var cls = d ojo.getObject(className);74 if(!d ojo.isFunction(cls)){75 var cls = d.getObject(className); 76 if(!d.isFunction(cls)){ 75 77 throw new Error("Could not load class '" + className + 76 78 "'. Did you spell the name correctly and use a full path, like 'dijit.form.Button'?"); … … 96 98 var argsStr = script.getAttribute("args"); 97 99 if(argsStr){ 98 d ojo.forEach(argsStr.split(/\s*,\s*/), function(part, idx){100 d.forEach(argsStr.split(/\s*,\s*/), function(part, idx){ 99 101 preamble += "var "+part+" = arguments["+idx+"]; "; 100 102 }); … … 102 104 var withStr = script.getAttribute("with"); 103 105 if(withStr && withStr.length){ 104 d ojo.forEach(withStr.split(/\s*,\s*/), function(part){106 d.forEach(withStr.split(/\s*,\s*/), function(part){ 105 107 preamble += "with("+part+"){"; 106 108 suffix += "}"; … … 118 120 if(mode && (mode == "connect")){ 119 121 // FIXME: need to implement EL here!! 120 d ojo.connect(instance, source, instance, nf);122 d.connect(instance, source, instance, nf); 121 123 }else{ 122 124 instance[source] = nf; … … 133 135 // any children 134 136 var thelist = []; 135 d ojo.forEach(nodes, function(node){137 d.forEach(nodes, function(node){ 136 138 if(!node){ return; } 137 139 var type = node.getAttribute("dojoType"); … … 141 143 for(var attrName in clsInfo.params){ 142 144 var attrValue = node.getAttribute(attrName); 143 if(attrValue && !d ojo.isAlien(attrValue)){ // see bug#3074; ignore builtin attributes145 if(attrValue && !d.isAlien(attrValue)){ // see bug#3074; ignore builtin attributes 144 146 var attrType = clsInfo.params[attrName]; 145 147 var val = str2obj(attrValue, attrType); … … 156 158 157 159 // preambles are magic. Handle it. 158 var preambles = d ojo.query("> script[type='dojo/method'][event='preamble']", node).orphan();160 var preambles = d.query("> script[type='dojo/method'][event='preamble']", node).orphan(); 159 161 if(preambles.length){ 160 162 // we only support one preamble. So be it. 161 params.preamble = d ojo.parser._functionFromScript(preambles[0]);163 params.preamble = d.parser._functionFromScript(preambles[0]); 162 164 } 163 165 164 166 // grab the rest of the scripts for processing later 165 var scripts = d ojo.query("> script[type='dojo/method']", node).orphan();167 var scripts = d.query("> script[type='dojo/method']", node).orphan(); 166 168 167 169 var clazz = clsInfo.cls; … … 177 179 var jsname = node.getAttribute("jsId"); 178 180 if(jsname){ 179 d ojo.setObject(jsname, instance);181 d.setObject(jsname, instance); 180 182 } 181 183 182 184 // check to see if we need to hook up events for non-declare()-built classes 183 185 scripts.forEach(function(script){ 184 d ojo.parser._wireUpMethod(instance, script);186 d.parser._wireUpMethod(instance, script); 185 187 }); 186 188 }); … … 189 191 // widgets). Parent widgets will recursively call startup on their 190 192 // (non-top level) children 191 d ojo.forEach(thelist, function(instance){193 d.forEach(thelist, function(instance){ 192 194 if( instance && 193 195 (instance.startup) && … … 205 207 // and instantiate them Searches for 206 208 // dojoType="qualified.class.name" 207 var list = d ojo.query('[dojoType]', rootNode);209 var list = d.query('[dojoType]', rootNode); 208 210 // go build the object instances 209 211 var instances = this.instantiate(list); … … 211 213 // FIXME: clean up any dangling scripts that we may need to run 212 214 /* 213 var scripts = d ojo.query("script[type='dojo/method']", rootNode).orphan();215 var scripts = d.query("script[type='dojo/method']", rootNode).orphan(); 214 216 scripts.forEach(function(script){ 215 217 wireUpMethod(instance, script);