io-xdr.js revision 9ee7d7be8c50e583fa263893bb39ee912f5684da
0N/A /*
3909N/A * Extends the IO base class to provide an alternate, Flash transport, for making
0N/A * cross-domain requests.
0N/A * @module io-base
0N/A * @submodule io-xdr
0N/A */
2362N/A
0N/A /**
2362N/A * @event io:xdrReady
0N/A * @description This event is fired by YUI.io when the specified transport is
0N/A * ready for use.
0N/A * @type Event Custom
0N/A */
0N/A var E_XDR_READY = 'io:xdrReady';
0N/A
0N/A /**
0N/A * @description Method that creates the Flash transport swf.
0N/A *
0N/A * @method _swf
0N/A * @private
2362N/A * @static
2362N/A * @param {string} uri - location of IO.swf.
2362N/A * @param {string} yid - YUI instance id.
0N/A * @return void
0N/A */
0N/A function _swf(uri, yid) {
0N/A var XDR_SWF = '<object id="yuiIoSwf" type="application/x-shockwave-flash" data="' + uri + '" width="0" height="0">' +
0N/A '<param name="movie" value="' + uri + '">' +
0N/A '<param name="FlashVars" value="yid=' + yid + '">' +
0N/A '<param name="allowScriptAccess" value="sameDomain">' +
0N/A '</object>';
0N/A Y.get('body').appendChild(Y.Node.create(XDR_SWF))
0N/A };
0N/A
0N/A Y.mix(Y.io, {
0N/A
0N/A /**
0N/A * @description Map of IO transports.
0N/A *
0N/A * @property _transportMap
0N/A * @private
0N/A * @static
0N/A * @type object
0N/A */
0N/A _transportMap: {},
0N/A
0N/A /**
0N/A * @description Object that stores callback handlers for cross-domain requests
0N/A * when using Flash as the transport.
0N/A *
0N/A * @property _fn
0N/A * @private
0N/A * @static
0N/A * @type object
0N/A */
0N/A _fn: {},
0N/A
0N/A /**
0N/A * @description Method for accessing the transport's interface for making a
0N/A * cross-domain transaction.
0N/A *
0N/A * @method _xdr
0N/A * @private
0N/A * @static
0N/A * @param {string} uri - qualified path to transaction resource.
0N/A * @param {object} o - Transaction object generated by _create() in io-base.
0N/A * @param {object} c - configuration object for the transaction.
0N/A * @return object
0N/A */
0N/A _xdr: function(uri, o, c){
0N/A if (c.on) {
0N/A this._fn[o.id] = c.on;
0N/A }
0N/A o.c.send(uri, c, o.id);
0N/A
0N/A return o;
0N/A },
0N/A
0N/A
0N/A /**
0N/A * @description Fires event "io:xdrReady"
0N/A *
0N/A * @method xdrReady
0N/A * @private
0N/A * @static
0N/A * @param {number} id - transaction id
0N/A * @param {object} c - configuration object for the transaction.
0N/A *
0N/A * @return void
0N/A */
0N/A xdrReady: function(id) {
0N/A Y.fire(E_XDR_READY, id);
0N/A },
0N/A
0N/A /**
0N/A * @description Method to initialize the desired transport.
0N/A *
0N/A * @method transport
0N/A * @public
0N/A * @static
0N/A * @param {object} o - object of transport configurations.
0N/A * @return void
0N/A */
0N/A transport: function(o) {
0N/A switch (o.id) {
0N/A case 'flash':
0N/A _swf(o.src, o.yid);
0N/A this._transportMap.flash = Y.config.doc.getElementById('yuiIoSwf');
0N/A break;
0N/A }
0N/A }
0N/A });