io-xdr.js revision a23a8b9cc849a2aa697a3820f45e1b0f652f4e53
/**
Extends IO to provide an alternate, Flash transport, for making
cross-domain requests.
@module io-base
@submodule io-xdr
@for IO
**/
/**
Fires when the XDR transport is ready for use.
@event io:xdrReady
**/
/**
Map of stored configuration objects when using
Flash as the transport for cross-domain requests.
@property _cB
@private
@type {Object}
**/
_cB = {},
/**
Map of transaction simulated readyState values
when XDomainRequest is the transport.
@property _rS
@private
@type {Object}
**/
_rS = {},
// Document reference
// Window reference
// XDomainRequest cross-origin request detection
xdr = w && w.XDomainRequest;
/**
Method that creates the Flash transport swf.
@method _swf
@private
@param {String} uri - location of io.swf.
@param {String} yid - YUI sandbox id.
@param {String} yid - IO instance id.
**/
var o = '<object id="io_swf" type="application/x-shockwave-flash" data="' +
uri + '" width="0" height="0">' +
'<param name="allowScriptAccess" value="always">' +
'</object>',
c = d.createElement('div');
d.body.appendChild(c);
c.innerHTML = o;
}
/**
Creates a response object for XDR transactions, for success
and failure cases.
@method _data
@private
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Boolean} u - Configuration xdr.use.
@param {Boolean} d - Configuration xdr.dataType.
@return {Object}
**/
function _data(o, u, d) {
if (u === 'flash') {
}
if (d === 'xml') {
}
return o;
}
/**
Method for intiating an XDR transaction abort.
@method _abort
@private
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
function _abort(o, c) {
}
/**
Method for determining if an XDR transaction has completed
and all data are received.
@method _isInProgress
@private
@param {Object} o - Transaction object generated by _create() in io-base.
**/
function _isInProgress(o) {
}
/**
Map of io transports.
@property _transport
@private
@type {Object}
**/
_transport: {},
/**
Sets event handlers for XDomainRequest transactions.
@method _ieEvt
@private
@static
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
_ieEvt: function(o, c) {
var io = this,
i = o.id,
t = 'timeout';
o.c.onload = function() {
_rS[i] = 4;
};
o.c.onerror = function() {
_rS[i] = 4;
};
if (c[t]) {
o.c.ontimeout = function() {
_rS[i] = 4;
io.xdrResponse(t, o, c);
};
o.c[t] = c[t];
}
},
/**
Method for accessing the transport's interface for making a
cross-domain transaction.
@method xdr
@param {String} uri - qualified path to transaction resource.
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
var io = this;
// The configuration object cannot be serialized safely
// across Flash's ExternalInterface.
w.setTimeout(function() {
try {
}
catch(e) {
}
}
else if (xdr) {
}
else {
}
return {
abort: function() {
return o.c ? _abort(o, c) : false;
},
isInProgress: function() {
return o.c ? _isInProgress(o.id) : false;
},
};
},
/**
Response controller for cross-domain requests when using the
Flash transport or IE8's XDomainRequest object.
@method xdrResponse
@param {String} e Event name
@param {Object} o Transaction object generated by _create() in io-base.
@param {Object} c Configuration object for the transaction.
@return {Object}
**/
xdrResponse: function(e, o, c) {
var io = this,
switch (e) {
case 'start':
break;
//case 'complete':
//This case is not used by Flash or XDomainRequest.
//io.complete(o, c);
//break;
case 'success':
delete m[o.id];
break;
case 'timeout':
case 'abort':
case 'transport error':
case 'failure':
delete m[o.id];
break;
}
},
/**
Fires event "io:xdrReady"
@method _xdrReady
@private
@param {Number} yid - YUI sandbox id.
@param {Number} uid - IO instance id.
**/
},
/**
Initializes the desired transport.
@method transport
@param {Object} o - object of transport configurations.
**/
transport: function(c) {
if (c.id === 'flash') {
}
}
});
/**
Fires event "io:xdrReady"
@method xdrReady
@protected
@static
@param {Number} yid - YUI sandbox id.
@param {Number} uid - IO instance id.
**/
};
Y.io.xdrResponse = function(e, o, c){
};
};
/**
Delay value to calling the Flash transport, in the
event io.swf has not finished loading. Once the E_XDR_READY
event is fired, this value will be set to 0.
@property delay
@static
@type {Number}
**/