io-xdr.js revision 68b67a7ca77bd6e51a6d67602d38a4cceede1676
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Extends the IO base class to provide an alternate, Flash transport, for making
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * cross-domain requests.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @module io
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @submodule io-xdr
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @event io:xdrReady
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description This event is fired by YUI.io when the specified transport is
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * ready for use.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @type Event Custom
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith var E_XDR_READY = Y.publish('io:xdrReady', { fireOnce: true }),
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Map of stored configuration objects when using
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Flash as the transport for cross-domain requests.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @property _cB
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @type object
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _cB = {},
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Map of transaction simulated readyState values
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * when XDomainRequest is the transport.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @property _rS
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @type object
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _rS = {},
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // Document reference
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith d = Y.config.doc,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // Window reference
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith w = Y.config.win,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // XDomainRequest cross-origin request detection
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith xdr = w && w.XDomainRequest;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Method that creates the Flash transport swf.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method _swf
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {string} uri - location of io.swf.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {string} yid - YUI instance id.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @return void
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith function _swf(uri, yid) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith var o = '<object id="io_swf" type="application/x-shockwave-flash" data="' +
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith uri + '" width="0" height="0">' +
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith '<param name="movie" value="' + uri + '">' +
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith '<param name="FlashVars" value="yid=' + yid + '">' +
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith '<param name="allowScriptAccess" value="always">' +
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith '</object>',
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith c = d.createElement('div');
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith d.body.appendChild(c);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith c.innerHTML = o;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Sets event handlers for XDomainRequest transactions.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method _evt
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} o - Transaction object generated by _create() in io-base.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} c - configuration object for the transaction.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @return void
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith function _evt(o, c) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith var io = this,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith i = o.id,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith p = 'xdrResponse',
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith t = 'timeout';
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.onprogress = function() { _rS[i] = 3; };
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.onload = function() {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _rS[i] = 4;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io[p](o, c, 'success');
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith };
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.onerror = function() {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _rS[i] = 4;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io[p](o, c, 'failure');
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith };
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (c.timeout) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.ontimeout = function() {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _rS[i] = 4;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io[p](o, c, t);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith };
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c[t] = c[t];
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Creates a response object for XDR transactions, for success
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * and failure cases.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method _data
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} o - Transaction object generated by _create() in io-base.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {boolean} u - Configuration xdr.use.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {boolean} d - Configuration xdr.dataType.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @return object
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith function _data(o, u, d) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (u === 'flash') {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.responseText = decodeURI(o.c.responseText);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (d === 'xml') {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.responseXML = Y.DataType.XML.parse(o.c.responseXML);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith return o;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Method for intiating an XDR transaction abort.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method _abort
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} o - Transaction object generated by _create() in io-base.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} c - configuration object for the transaction.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith function _abort(o, c) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith return o.c.abort(o.id, c);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Method for determining if an XDR transaction has completed
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * and all data are received.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method _isInProgress.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} o - Transaction object generated by _create() in io-base.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith function _isInProgress(o) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith return xdr ? _rS[o.id] !== 4 : o.c.isInProgress(o.id);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith Y.mix(Y.IO.prototype, {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Map of io transports.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @property _transport
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @type object
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _transport: {},
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Method for accessing the transport's interface for making a
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * cross-domain transaction.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method xdr
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {string} uri - qualified path to transaction resource.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} o - Transaction object generated by _create() in io-base.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} c - configuration object for the transaction.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith xdr: function(uri, o, c) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith var io = this;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (c.xdr.use === 'flash') {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // The configuration object cannot be serialized safely
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith // across Flash's ExternalInterface.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _cB[o.id] = c;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith w.setTimeout(function() {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (o.c.send) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.send(uri, { id: o.id,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith uid: o.uid,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith method: c.method,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith data: c.data,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith headers: c.headers });
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith else {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io.xdrResponse(o, c, 'transport error');
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith delete _cB[o.id];
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }, Y.io.xdr.delay);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith else if (xdr) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _evt(o, c);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.open(c.method || 'GET', uri);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.send(c.data);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith else {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.c.send(uri, o, c);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith return {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith id: o.id,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith abort: function() {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith return o.c ? _abort(o, c) : false;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith },
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith isInProgress: function() {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith return o.c ? _isInProgress(o.id) : false;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith },
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith conn: io
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith };
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith },
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Response controller for cross-domain requests when using the
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Flash transport or IE8's XDomainRequest object.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method xdrResponse
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {string} e - Event name
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} o - Transaction object generated by _create() in io-base.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} c - configuration object for the transaction.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @return object
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith xdrResponse: function(e, o, c) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith c = _cB[o.id] ? _cB[o.id] : c;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith var io = this,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith m = xdr ? _rS : _cB,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith u = c.xdr.use,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith d = c.xdr.dataType;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith switch (e) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith case 'start':
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io.start(o, c);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith break;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith //case 'complete':
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith //This case is not used by Flash or XDomainRequest.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith //io.complete(o, c);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith //break;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith case 'success':
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io.success(_data(o, u, d), c);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith delete m[o.id];
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith break;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith case 'timeout':
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith case 'abort':
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith case 'transport error':
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith o.e = e;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith case 'failure':
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io.failure(_data(o, u, d), c);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith delete m[o.id];
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith break;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith },
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Fires event "io:xdrReady"
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method xdrReady
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @private
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {number} id - transaction id
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @return void
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith xdrReady: function(yid, uid) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith Y.io.xdr.delay = 0;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith Y.fire(E_XDR_READY, yid);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith },
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Method to initialize the desired transport.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @method transport
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @public
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @param {object} o - object of transport configurations.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @return void
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith transport: function(o) {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith if (o.id === 'flash') {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith _swf(Y.UA.ie ? o.src + '?d=' + new Date().valueOf().toString() : o.src, Y.id);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith this._transport[o.id] = (o.id === 'flash') ? d.getElementById('io_swf') : o.src;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith }
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith });
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith Y.io.xdrResponse = function(e, o, c){
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith var io = Y.io._map[o.uid];
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io.xdrResponse.apply(io, [e, o, c]);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith };
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith Y.io.transport = function(c){
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith var io = Y.io._map['io:0'] || new Y.IO();
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith io.transport.apply(io, [c]);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith };
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /**
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @description Delay value to calling the Flash transport, in the
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * event io.swf has not finished loading. Once the E_XDR_READY
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * event is fired, this value will be set to 0.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @property delay
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @public
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @static
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * @type number
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith Y.io.xdr = { delay : 100 };