io-xdr.js revision 660dff9afbc1d7ccf08d01da7eb04bc291f3abf0
/**
* Extends IO to provide an alternate, Flash transport, for making
* cross-domain requests.
* @module io-base
* @submodule io-xdr
* @for IO
*/
/**
* @event io:xdrReady
* @description This event is fired by YUI.io when the specified transport is
* ready for use.
* @type Event Custom
*/
/**
* @description Map of stored configuration objects when using
* Flash as the transport for cross-domain requests.
*
* @property _cB
* @private
* @type object
*/
_cB = {},
/**
* @description 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;
/**
* @description 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.
* @return void
*/
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;
}
/**
* @description 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;
}
/**
* @description 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) {
}
/**
* @description 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) {
}
/**
* @description Map of io transports.
*
* @property _transport
* @private
* @type object
*/
_transport: {},
/**
* @description 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.
* @return void
*/
_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];
}
},
/**
* @description Method for accessing the transport's interface for making a
* cross-domain transaction.
*
* @method xdr
* @public
* @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;
},
};
},
/**
* @description Response controller for cross-domain requests when using the
* Flash transport or IE8's XDomainRequest object.
*
* @method xdrResponse
* @public
* @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;
}
},
/**
* @description Fires event "io:xdrReady"
*
* @method _xdrReady
* @private
* @param {number} yid - YUI sandbox id.
* @param {number} uid - IO instance id.
*
* @return void
*/
},
/**
* @description Method to initialize the desired transport.
*
* @method transport
* @public
* @param {object} o - object of transport configurations.
* @return void
*/
transport: function(c) {
if (c.id === 'flash') {
}
}
});
/**
* @description Fires event "io:xdrReady"
*
* @method xdrReady
* @protected
* @static
* @param {number} yid - YUI sandbox id.
* @param {number} uid - IO instance id.
*
* @return void
*/
};
Y.io.xdrResponse = function(e, o, c){
};
};
/**
* @description 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
* @public
* @static
* @type number
*/