summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/io/xhrScriptPlugin.xd.js
blob: 1547ad10a2d79bacada64d16ed9293a2f0c9aa15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
	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
*/


dojo._xdResourceLoaded(function(dojo, dijit, dojox){
return {depends: [["provide", "dojox.io.xhrScriptPlugin"],
["require", "dojox.io.xhrPlugins"],
["require", "dojo.io.script"],
["require", "dojox.io.scriptFrame"]],
defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.io.xhrScriptPlugin"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.io.xhrScriptPlugin"] = true;
dojo.provide("dojox.io.xhrScriptPlugin");
dojo.require("dojox.io.xhrPlugins");
dojo.require("dojo.io.script");
dojo.require("dojox.io.scriptFrame");

dojox.io.xhrScriptPlugin = function(/*String*/url, /*String*/callbackParamName, /*Function?*/httpAdapter){
	// summary:
	//		Adds the script transport (JSONP) as an XHR plugin for the given site. See
	//		dojox.io.script for more information on the transport. Note, that JSONP
	//		is *not* a secure transport, by loading data from a third-party site using JSONP
	//		the site has full access to your JavaScript environment.
	//	url:
	//		Url prefix of the site which can handle JSONP requests.
	// 	httpAdapter: This allows for adapting HTTP requests that could not otherwise be
	// 		sent with JSONP, so you can use a convention for headers and PUT/DELETE methods.
	dojox.io.xhrPlugins.register(
		"script",
		function(method,args){
			 return args.sync !== true &&
				(method == "GET" || httpAdapter) &&
				(args.url.substring(0,url.length) == url);
		},
		function(method,args,hasBody){
			var send = function(){
				args.callbackParamName = callbackParamName;
				if(dojo.body()){
					args.frameDoc = "frame" + Math.random();
				}
				return dojo.io.script.get(args);
			}
			return (httpAdapter ? httpAdapter(send, true) : send)(method, args, hasBody); // use the JSONP transport
		}
	);
};

}

}};});