<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
- <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
- <script type="text/javascript" src="../prettify/prettify.js"></script>
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
</span> * @class Ext.data.JsonP
* @singleton
* This class is used to create JSONP requests. JSONP is a mechanism that allows for making
- * requests for data cross domain. More information is available here:
- * http://en.wikipedia.org/wiki/JSONP
+ * requests for data cross domain. More information is available <a href="http://en.wikipedia.org/wiki/JSONP">here</a>.
*/
Ext.define('Ext.data.JsonP', {
-
+
/* Begin Definitions */
-
+
singleton: true,
-
+
statics: {
requestCount: 0,
requests: {}
},
-
+
/* End Definitions */
-
+
<span id='Ext-data-JsonP-property-timeout'> /**
</span> * @property timeout
* @type Number
* failure callback will be fired. The timeout is in ms. Defaults to <tt>30000</tt>.
*/
timeout: 30000,
-
+
<span id='Ext-data-JsonP-property-disableCaching'> /**
</span> * @property disableCaching
* @type Boolean
* True to add a unique cache-buster param to requests. Defaults to <tt>true</tt>.
*/
disableCaching: true,
-
+
<span id='Ext-data-JsonP-property-disableCachingParam'> /**
-</span> * @property disableCachingParam
+</span> * @property disableCachingParam
* @type String
* Change the parameter which is sent went disabling caching through a cache buster. Defaults to <tt>'_dc'</tt>.
*/
disableCachingParam: '_dc',
-
+
<span id='Ext-data-JsonP-property-callbackKey'> /**
</span> * @property callbackKey
* @type String
* url?callback=Ext.data.JsonP.callback1
*/
callbackKey: 'callback',
-
+
<span id='Ext-data-JsonP-method-request'> /**
</span> * Makes a JSONP request.
* @param {Object} options An object which may contain the following properties. Note that options will
* <li><b>disableCachingParam</b> : String (Optional) <div class="sub-desc">See {@link #disableCachingParam}</div></li>
* <li><b>success</b> : Function (Optional) <div class="sub-desc">A function to execute if the request succeeds.</div></li>
* <li><b>failure</b> : Function (Optional) <div class="sub-desc">A function to execute if the request fails.</div></li>
- * <li><b>callback</b> : Function (Optional) <div class="sub-desc">A function to execute when the request
+ * <li><b>callback</b> : Function (Optional) <div class="sub-desc">A function to execute when the request
* completes, whether it is a success or failure.</div></li>
* <li><b>scope</b> : Object (Optional)<div class="sub-desc">The scope in
* which to execute the callbacks: The "this" object for the callback function. Defaults to the browser window.</div></li>
*/
request: function(options){
options = Ext.apply({}, options);
-
+
//<debug>
if (!options.url) {
Ext.Error.raise('A url must be specified for a JSONP request.');
}
//</debug>
-
- var me = this,
- disableCaching = Ext.isDefined(options.disableCaching) ? options.disableCaching : me.disableCaching,
- cacheParam = options.disableCachingParam || me.disableCachingParam,
- id = ++me.statics().requestCount,
- callbackName = options.callbackName || 'callback' + id,
- callbackKey = options.callbackKey || me.callbackKey,
- timeout = Ext.isDefined(options.timeout) ? options.timeout : me.timeout,
- params = Ext.apply({}, options.params),
+
+ var me = this,
+ disableCaching = Ext.isDefined(options.disableCaching) ? options.disableCaching : me.disableCaching,
+ cacheParam = options.disableCachingParam || me.disableCachingParam,
+ id = ++me.statics().requestCount,
+ callbackName = options.callbackName || 'callback' + id,
+ callbackKey = options.callbackKey || me.callbackKey,
+ timeout = Ext.isDefined(options.timeout) ? options.timeout : me.timeout,
+ params = Ext.apply({}, options.params),
url = options.url,
- request,
+ name = Ext.isSandboxed ? Ext.getUniqueGlobalNamespace() : 'Ext',
+ request,
script;
-
- params[callbackKey] = 'Ext.data.JsonP.' + callbackName;
+
+ params[callbackKey] = name + '.data.JsonP.' + callbackName;
if (disableCaching) {
params[cacheParam] = new Date().getTime();
}
-
+
script = me.createScript(url, params);
-
+
me.statics().requests[id] = request = {
url: url,
params: params,
callback: options.callback,
callbackName: callbackName
};
-
+
if (timeout > 0) {
request.timeout = setTimeout(Ext.bind(me.handleTimeout, me, [request]), timeout);
}
-
+
me.setupErrorHandling(request);
me[callbackName] = Ext.bind(me.handleResponse, me, [request], true);
Ext.getHead().appendChild(script);
return request;
},
-
+
<span id='Ext-data-JsonP-method-abort'> /**
</span> * Abort a request. If the request parameter is not specified all open requests will
* be aborted.
abort: function(request){
var requests = this.statics().requests,
key;
-
+
if (request) {
if (!request.id) {
request = requests[request];
}
}
},
-
+
<span id='Ext-data-JsonP-method-setupErrorHandling'> /**
</span> * Sets up error handling for the script
* @private
setupErrorHandling: function(request){
request.script.onerror = Ext.bind(this.handleError, this, [request]);
},
-
+
<span id='Ext-data-JsonP-method-handleAbort'> /**
</span> * Handles any aborts when loading the script
* @private
request.errorType = 'abort';
this.handleResponse(null, request);
},
-
+
<span id='Ext-data-JsonP-method-handleError'> /**
</span> * Handles any script errors when loading the script
* @private
request.errorType = 'error';
this.handleResponse(null, request);
},
-
+
<span id='Ext-data-JsonP-method-cleanupErrorHandling'> /**
</span> * Cleans up anu script handling errors
* @private
cleanupErrorHandling: function(request){
request.script.onerror = null;
},
-
+
<span id='Ext-data-JsonP-method-handleTimeout'> /**
</span> * Handle any script timeouts
* @private
request.errorType = 'timeout';
this.handleResponse(null, request);
},
-
+
<span id='Ext-data-JsonP-method-handleResponse'> /**
</span> * Handle a successful response
* @private
* @param {Object} request The request
*/
handleResponse: function(result, request){
-
+
var success = true;
-
+
if (request.timeout) {
clearTimeout(request.timeout);
}
delete this.statics()[request.id];
this.cleanupErrorHandling(request);
Ext.fly(request.script).remove();
-
+
if (request.errorType) {
success = false;
Ext.callback(request.failure, request.scope, [request.errorType]);
}
Ext.callback(request.callback, request.scope, [success, result, request.errorType]);
},
-
+
<span id='Ext-data-JsonP-method-createScript'> /**
</span> * Create the script tag
* @private