Ticket #3961: xhr-rpc-reduction.patch
| File xhr-rpc-reduction.patch, 11.3 kB (added by peller, 14 months ago) |
|---|
-
Users/peller/workspace/trunk2/dojo/rpc/RpcService.js
22 22 throw new Error("Unable to load SMD from " + args); 23 23 }); 24 24 25 }else if(args ["smdStr"]){25 }else if(args.smdStr){ 26 26 this.processSmd(dojo.eval("("+args.smdStr+")")); 27 27 }else{ 28 28 // otherwise we assume it's an arguments object with the following … … 32 32 // - smdStr 33 33 // - smdObj 34 34 35 if(args ["serviceUrl"]){35 if(args.serviceUrl){ 36 36 this.serviceUrl = args.serviceUrl; 37 37 } 38 38 39 if(args["timeout"]){ 40 this.timeout = args.timeout; 41 }else{ 42 this.timeout=3000; 43 } 39 this.timeout = args.timeout || 3000; 44 40 45 if( typeof args["strictArgChecks"] != "undefined"){41 if("strictArgChecks" in args){ 46 42 this.strictArgChecks = args.strictArgChecks; 47 43 } 48 44 -
Users/peller/workspace/trunk2/dojo/rpc/JsonService.js
42 42 //summary: 43 43 // parse the result envelope and pass the results back to to 44 44 // the callback function 45 if(obj==null){ return; } 46 if(obj["Result"]!=null){ 47 return obj["Result"]; 48 }else if(obj["result"]!=null){ 49 return obj["result"]; 50 }else if(obj["ResultSet"]){ 51 return obj["ResultSet"]; 52 }else{ 53 return obj; 54 } 45 if(!obj){ return; } 46 return obj.Result || obj.result || obj.ResultSet || obj; 55 47 } 56 48 } 57 49 ); -
Users/peller/workspace/trunk2/dojo/_base/html.js
28 28 // dojo.doc. Can be used to retreive 29 29 // node references from other documents. 30 30 if(dojo.isString(id)){ 31 var _d = (doc||dojo.doc);31 var _d = doc || dojo.doc; 32 32 var te = _d.getElementById(id); 33 33 // attributes.id.value is better than just id in case the 34 34 // user has a name=id inside a form 35 if( (te) && (te.attributes.id.value == id)){35 if(te && te.attributes.id.value == id){ 36 36 return te; 37 37 }else{ 38 38 var eles = _d.all[id]; … … 40 40 if(!eles.length){ return eles; } 41 41 // if more than 1, choose first with the correct id 42 42 var i=0; 43 while( te=eles[i++]){43 while((te=eles[i++])){ 44 44 if(te.attributes.id.value == id){ return te; } 45 45 } 46 46 } … … 63 63 // dojo.doc. Can be used to retreive 64 64 // node references from other documents. 65 65 if(dojo.isString(id)){ 66 return (doc ||dojo.doc).getElementById(id);66 return (doc || dojo.doc).getElementById(id); 67 67 }else{ 68 68 return id; // DomNode 69 69 } … … 120 120 // summary: enable or disable selection on a node 121 121 node = dojo.byId(node); 122 122 if(dojo.isMozilla){ 123 node.style.MozUserSelect = (selectable)? "" : "none";123 node.style.MozUserSelect = selectable ? "" : "none"; 124 124 }else if(dojo.isKhtml){ 125 node.style.KhtmlUserSelect = (selectable)? "auto" : "none";125 node.style.KhtmlUserSelect = selectable ? "auto" : "none"; 126 126 }else if(dojo.isIE){ 127 node.unselectable = (selectable)? "" : "on";127 node.unselectable = selectable ? "" : "on"; 128 128 dojo.query("*", node).forEach(function(descendant){ 129 descendant.unselectable = (selectable)? "" : "on";129 descendant.unselectable = selectable ? "" : "on"; 130 130 }); 131 131 } 132 132 //FIXME: else? Opera? … … 167 167 // "first" and "last" indicate positions as children of refNode. 168 168 169 169 // FIXME: need to write tests for this!!!! 170 if( (!node)||(!refNode)||(typeof position == "undefined")){170 if(!node || !refNode || position === undefined){ 171 171 return false; // boolean 172 172 } 173 173 node = dojo.byId(node); 174 174 refNode = dojo.byId(refNode); 175 175 if(typeof position == "number"){ 176 176 var cn = refNode.childNodes; 177 if(( (position == 0)&&(cn.length == 0)) ||178 (cn.length == position)){177 if((position == 0 && cn.length == 0) || 178 cn.length == position){ 179 179 refNode.appendChild(node); return true; 180 180 } 181 181 if(position == 0){ … … 272 272 s = dv.getComputedStyle(node, null); 273 273 } 274 274 return s || {}; 275 } 275 }; 276 276 }else if(dojo.isIE){ 277 277 gcs = function(node){ 278 278 return node.currentStyle; 279 } 279 }; 280 280 }else{ 281 281 gcs = function(node){ 282 282 return dv.getComputedStyle(node, null); 283 } 283 }; 284 284 } 285 285 dojo.getComputedStyle = gcs; 286 286 … … 292 292 } 293 293 }else{ 294 294 dojo._toPixelValue = function(element, avalue){ 295 if(!avalue){ return 0;}295 if(!avalue){ return 0; } 296 296 // on IE7, medium is usually 4 pixels 297 if(avalue=="medium"){ return 4;};297 if(avalue=="medium"){ return 4; } 298 298 // style values can be floats, client code may 299 299 // want to round this value for integer pixels. 300 300 if(avalue.slice && (avalue.slice(-2)=='px')){ return parseFloat(avalue); } … … 671 671 // For whatever reason, TABLE and BUTTON are always border-box by default. 672 672 // If you have assigned a different box to either one via CSS then 673 673 // box functions will break. 674 return (dojo.boxModel=="border-box")||(n=="TABLE")||(n=="BUTTON"); // boolean674 return dojo.boxModel=="border-box" || n=="TABLE" || n=="BUTTON"; // boolean 675 675 } 676 676 677 677 dojo._setContentSize = function(/*DomNode*/node, /*Number*/widthPx, /*Number*/heightPx, /*Object*/computedStyle){ … … 787 787 788 788 dojo._isBodyLtr = function(){ 789 789 //FIXME: could check html and body tags directly instead of computed style? need to ignore case, accept empty values 790 return typeof dojo._bodyLtr == "undefined"?791 (dojo._bodyLtr = dojo.getComputedStyle(dojo.body()).direction == "ltr"):792 dojo._bodyLtr; // Boolean790 return !("_bodyLtr" in dojo) ? 791 dojo._bodyLtr = dojo.getComputedStyle(dojo.body()).direction == "ltr" : 792 dojo._bodyLtr; // Boolean 793 793 } 794 794 795 795 dojo._getIeDocumentElementOffset = function(){ … … 964 964 // Pass a boolean condition if you want to explicitly add or remove. 965 965 // condition: 966 966 // If passed, true means to add the class, false means to remove. 967 if( typeof condition == "undefined"){967 if(condition === undefined){ 968 968 condition = !dojo.hasClass(node, classStr); 969 969 } 970 970 dojo[condition ? "addClass" : "removeClass"](node, classStr); -
Users/peller/workspace/trunk2/dojo/_base/xhr.js
59 59 }).forEach(function(item){ 60 60 var _in = item.name; 61 61 var type = (item.type||"").toLowerCase(); 62 if( (type == "radio")||(type == "checkbox")){62 if(type == "radio" || type == "checkbox"){ 63 63 if(item.checked){ setValue(ret, _in, item.value); } 64 64 }else if(item.multiple){ 65 65 ret[_in] = []; … … 114 114 } 115 115 } 116 116 } 117 if( (ret.length)&&(ret.charAt(ret.length-1)== "&")){117 if(ret.length && ret.charAt(ret.length-1) == "&"){ 118 118 ret = ret.substr(0, ret.length-1); 119 119 } 120 120 return ret; // string … … 208 208 "text": function(xhr){ return xhr.responseText; }, 209 209 "json": function(xhr){ 210 210 if(!djConfig.usePlainJson){ 211 console.debug(" pleaseconsider using a mimetype of text/json-comment-filtered"211 console.debug("consider using a mimetype of text/json-comment-filtered" 212 212 + " to avoid potential security issues with JSON endpoints" 213 213 + " (use djConfig.usePlainJson=true to turn off this message)"); 214 214 } 215 215 return dojo.fromJson(xhr.responseText); 216 216 }, 217 "json-comment-optional": function(xhr){218 // NOTE: we provide the json-comment-filtered option as one solution to219 // the "JavaScript Hijacking" issue noted by Fortify and others. It is220 // not appropriate for all circumstances.221 var value = xhr.responseText;222 var cStartIdx = value.indexOf("\/*");223 var cEndIdx = value.lastIndexOf("*\/");224 if((cStartIdx == -1)||(cEndIdx == -1)){225 return dojo.fromJson(xhr.responseText);226 }227 return dojo.fromJson(value.substring(cStartIdx+2, cEndIdx));228 },229 217 "json-comment-filtered": function(xhr){ 230 218 // NOTE: we provide the json-comment-filtered option as one solution to 231 219 // the "JavaScript Hijacking" issue noted by Fortify and others. It is 232 220 // not appropriate for all circumstances. 233 var value = xhr.responseText; 234 var cStartIdx = value.indexOf("\/*"); 235 var cEndIdx = value.lastIndexOf("*\/"); 236 if((cStartIdx == -1)||(cEndIdx == -1)){ 237 // FIXME: throw exception instead? 238 console.debug("your JSON wasn't comment filtered!"); 239 return ""; 221 var match = xhr.responseText.match(/\/\*(.*)\*\//); 222 if(!match){ 223 throw new Error("your JSON wasn't comment filtered!"); 240 224 } 241 return dojo.fromJson( value.substring(cStartIdx+2, cEndIdx));225 return dojo.fromJson(match[1]); 242 226 }, 243 227 "javascript": function(xhr){ 244 228 // FIXME: try Moz and IE specific eval variants? … … 260 244 } 261 245 }; 262 246 247 dojo._contentHandlers["json-comment-optional"] = function(xhr){ 248 var handlers = dojo._contentHandlers; 249 try{ 250 return handlers["json-comment-filtered"](xhr); 251 }catch(e){ 252 return handlers["json"](xhr); 253 } 254 }; 255 263 256 (function(){ 264 257 265 258 dojo._ioSetArgs = function(/*Object*/args, … … 350 343 // to do cleanup on an error. It will receive two arguments: error (the 351 344 // Error object) and dfd, the Deferred object returned from this function. 352 345 353 var ioArgs = {}; 354 ioArgs.args = args; 346 var ioArgs = {args: args, url: args.url}; 355 347 356 348 //Get values from form if requestd. 357 349 var formObject = null; … … 360 352 //IE requires going through getAttributeNode instead of just getAttribute in some form cases, 361 353 //so use it for all. See #2844 362 354 var actnNode = form.getAttributeNode("action"); 363 ioArgs.url = args.url || (actnNode ? actnNode.value : null);355 ioArgs.url = ioArgs.url || (actnNode ? actnNode.value : null); 364 356 formObject = dojo.formToObject(form); 365 }else{366 ioArgs.url = args.url;367 357 } 368 358 369 359 // set up the query params … … 386 376 ioArgs.handleAs = args.handleAs || "text"; 387 377 var d = new dojo.Deferred(canceller); 388 378 d.addCallbacks(okHandler, function(error){ 389 return errHandler(error, d);379 return errHandler(error, d); 390 380 }); 391 381 392 382 //Support specifying load, error and handle callback functions from the args. … … 417 407 // FIXME: need to wire up the xhr object's abort method to something 418 408 // analagous in the Deferred 419 409 return d; 420 421 410 } 422 411 423 412 var _deferredCancel = function(/*Deferred*/dfd){ … … 431 420 } 432 421 var _deferredOk = function(/*Deferred*/dfd){ 433 422 //summary: okHandler function for dojo._ioSetArgs call. 434 423 435 424 return dojo._contentHandlers[dfd.ioArgs.handleAs](dfd.ioArgs.xhr); 436 425 } 437 426 var _deferError = function(/*Error*/error, /*Deferred*/dfd){ … … 564 553 // workaround for IE6's apply() "issues" 565 554 var ioArgs = dfd.ioArgs; 566 555 var args = ioArgs.args; 567 ioArgs.xhr.open(type, ioArgs.url, (args.sync !== true), (args.user ? args.user : undefined), (args.password ? args.password: undefined));556 ioArgs.xhr.open(type, ioArgs.url, args.sync !== true, args.user || undefined, args.password || undefined); 568 557 if(args.headers){ 569 558 for(var hdr in args.headers){ 570 559 if(hdr.toLowerCase() === "content-type" && !args.contentType){