| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/json", |
| 4 |
"dojo/_base/xhr", |
| 5 |
"dojox/io/xhrPlugins", |
| 6 |
"dojox/io/windowName", |
| 7 |
"dojox/io/httpParse", |
| 8 |
"dojox/secure/capability" |
| 9 |
], function(dojo, json, xhr, xhrPlugins, windowName, httpParse, capability){ |
| 10 |
dojo.getObject("io.xhrWindowNamePlugin", true, dojox); |
| 11 |
|
| 12 |
dojox.io.xhrWindowNamePlugin = function(url, httpAdapter, trusted){ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
xhrPlugins.register( |
| 22 |
"windowName", |
| 23 |
function(method,args){ |
| 24 |
return args.sync !== true && |
| 25 |
(method == "GET" || method == "POST" || httpAdapter) && |
| 26 |
(args.url.substring(0,url.length) == url); |
| 27 |
}, |
| 28 |
function(method,args,hasBody){ |
| 29 |
var send = windowName.send; |
| 30 |
var load = args.load; |
| 31 |
args.load = undefined; |
| 32 |
var dfd = (httpAdapter ? httpAdapter(send, true) : send)(method, args, hasBody); |
| 33 |
dfd.addCallback(function(result){ |
| 34 |
var ioArgs = dfd.ioArgs; |
| 35 |
ioArgs.xhr = { |
| 36 |
getResponseHeader: function(name){ |
| 37 |
|
| 38 |
return dojo.queryToObject(ioArgs.hash.match(/[^#]*$/)[0])[name]; |
| 39 |
} |
| 40 |
}; |
| 41 |
|
| 42 |
if(ioArgs.handleAs == 'json'){ |
| 43 |
|
| 44 |
if(!trusted){ |
| 45 |
capability.validate(result,["Date"],{}); |
| 46 |
} |
| 47 |
return dojo.fromJson(result); |
| 48 |
} |
| 49 |
return dojo._contentHandlers[ioArgs.handleAs || "text"]({responseText:result}); |
| 50 |
}); |
| 51 |
args.load = load; |
| 52 |
if(load){ |
| 53 |
dfd.addCallback(load); |
| 54 |
} |
| 55 |
return dfd; |
| 56 |
} |
| 57 |
); |
| 58 |
}; |
| 59 |
|
| 60 |
return dojox.io.xhrWindowNamePlugin; |
| 61 |
}); |