io-base.js revision 361214abdd3c8302e5ce0c74cc9200f32bee3516
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync/**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncBase IO functionality. Provides basic XHR transport support.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@module io-base
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@main io-base
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@for IO
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync**/
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncvar // List of events that comprise the IO event lifecycle.
78f327ee942771169c65c91baf789fd10e72b01avboxsync EVENTS = ['start', 'complete', 'end', 'success', 'failure', 'progress'],
78f327ee942771169c65c91baf789fd10e72b01avboxsync
78f327ee942771169c65c91baf789fd10e72b01avboxsync // Whitelist of used XHR response object properties.
78f327ee942771169c65c91baf789fd10e72b01avboxsync XHR_PROPS = ['status', 'statusText', 'responseText', 'responseXML'],
78f327ee942771169c65c91baf789fd10e72b01avboxsync
78f327ee942771169c65c91baf789fd10e72b01avboxsync win = Y.config.win,
78f327ee942771169c65c91baf789fd10e72b01avboxsync uid = 0;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync/**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncThe IO class is a utility that brokers HTTP requests through a simplified
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncinterface. Specifically, it allows JavaScript to make HTTP requests to
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsynca resource without a page reload. The underlying transport for making
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncsame-domain requests is the XMLHttpRequest object. IO can also use
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsyncFlash, if specified as a transport, for cross-domain requests.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@class IO
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@constructor
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@param {Object} config Object of EventTarget's publish method configurations
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync used to configure IO's events.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync**/
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncfunction IO (config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io._uid = 'io:' + uid++;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io._init(config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync Y.io._map[io._uid] = io;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync}
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncIO.prototype = {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync //--------------------------------------
701a45600245e42829e1187817299e812eebdec5vboxsync // Properties
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync //--------------------------------------
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * A counter that increments for each transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @property _id
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @type {Number}
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _id: 0,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Object of IO HTTP headers sent with each transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @property _headers
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @type {Object}
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _headers: {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync 'X-Requested-With' : 'XMLHttpRequest'
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Object that stores timeout values for any transaction with a defined
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "timeout" configuration property.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @property _timeout
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @type {Object}
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _timeout: {},
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync //--------------------------------------
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Methods
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync //--------------------------------------
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _init: function(config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this, i, len;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.cfg = config || {};
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync Y.augment(io, Y.EventTarget);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync for (i = 0, len = EVENTS.length; i < len; ++i) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Publish IO global events with configurations, if any.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // IO global events are set to broadcast by default.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // These events use the "io:" namespace.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.publish('io:' + EVENTS[i], Y.merge({ broadcast: 1 }, config));
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Publish IO transaction events with configurations, if
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // any. These events use the "io-trn:" namespace.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.publish('io-trn:' + EVENTS[i], config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Method that creates a unique transaction object for each request.
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync *
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @method _create
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @param {Object} cfg Configuration object subset to determine if
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * the transaction is an XDR or file upload,
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * requiring an alternate transport.
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @param {Number} id Transaction id
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @return {Object} The transaction object
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _create: function(config, id) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction = {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync id : Y.Lang.isNumber(id) ? id : io._id++,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync uid: io._uid
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync alt = config.xdr ? config.xdr.use : null,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync form = config.form && config.form.upload ? 'iframe' : null,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync use;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (alt === 'native') {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Non-IE can use XHR level 2 and not rely on an
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // external transport.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync alt = Y.UA.ie ? 'xdr' : null;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync use = alt || form;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction = use ? Y.merge(Y.IO.customTransport(use), transaction) :
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync Y.merge(Y.IO.defaultTransport(), transaction);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (transaction.notify) {
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync config.notify = function (e, t, c) { io.notify(e, t, c); };
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (!use) {
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync if (win && win.FormData && config.data instanceof FormData) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c.upload.onprogress = function (e) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.progress(transaction, e, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync };
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync transaction.c.onload = function (e) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.load(transaction, e, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync };
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c.onerror = function (e) {
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync io.error(transaction, e, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync };
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.upload = true;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync }
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync return transaction;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync _destroy: function(transaction) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (win && !transaction.notify && !transaction.xdr) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (XHR && !transaction.upload) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c.onreadystatechange = null;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync } else if (transaction.upload) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c.upload.onprogress = null;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c.onload = null;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c.onerror = null;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync } else if (Y.UA.ie && !transaction.e) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // IE, when using XMLHttpRequest as an ActiveX Object, will throw
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // a "Type Mismatch" error if the event handler is set to "null".
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c.abort();
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction = transaction.c = null;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync /**
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * Method for creating and firing events.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _evt
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {String} eventName Event to be published.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration data subset for event subscription.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _evt: function(eventName, transaction, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this, params,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync args = config['arguments'],
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync emitFacade = io.cfg.emitFacade,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync globalEvent = "io:" + eventName,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync trnEvent = "io-trn:" + eventName;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (transaction.e) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c = { status: 0, statusText: transaction.e };
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Fire event with parameters or an Event Facade.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync params = [ emitFacade ?
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync id: transaction.id,
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync data: transaction.c,
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync cfg: config,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync 'arguments': args
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync } :
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.id
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync ];
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync if (!emitFacade) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (eventName === EVENTS[0] || eventName === EVENTS[2]) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (args) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync params.push(args);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync } else {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (transaction.evt) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync params.push(transaction.evt);
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync } else {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync params.push(transaction.c);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (args) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync params.push(args);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync }
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync params.unshift(globalEvent);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Fire global events.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.fire.apply(io, params);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Fire transaction events, if receivers are defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (config.on) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync params[0] = trnEvent;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.once(trnEvent, config.on[eventName], config.context || Y);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.fire.apply(io, params);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:start" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * start event, if `config.on.start` is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method start
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync start: function(transaction, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Signals the start of an IO request.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:start
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this._evt(EVENTS[0], transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:complete" and creates, fires a
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transaction-specific "complete" event, if config.on.complete is
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method complete
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync complete: function(transaction, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Signals the completion of the request-response phase of a
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transaction. Response status and data are accessible, if
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * available, in this event.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:complete
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this._evt(EVENTS[1], transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:end" and creates, fires a transaction-specific "end"
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * event, if config.on.end is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method end
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync end: function(transaction, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Signals the end of the transaction lifecycle.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:end
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this._evt(EVENTS[2], transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this._destroy(transaction);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:success" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "success" event, if config.on.success is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method success
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync success: function(transaction, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Signals an HTTP response with status in the 2xx range.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires after io:complete.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:success
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this._evt(EVENTS[3], transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this.end(transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:failure" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "failure" event, if config.on.failure is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method failure
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync failure: function(transaction, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Signals an HTTP response with status outside of the 2xx range.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Fires after io:complete.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:failure
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this._evt(EVENTS[4], transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this.end(transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:progress" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "progress" event -- for XMLHttpRequest file upload -- if
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * config.on.progress is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method progress
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} progress event.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync progress: function(transaction, e, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Signals the interactive state during a file upload transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * This event fires after io:start and before io:complete.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:progress
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.evt = e;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this._evt(EVENTS[5], transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync /**
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Fires event "io:complete" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "complete" event -- for XMLHttpRequest file upload -- if
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * config.on.complete is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method load
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} load event.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync load: function (transaction, e, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.evt = e.target;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this._evt(EVENTS[1], transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:failure" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "failure" event -- for XMLHttpRequest file upload -- if
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * config.on.failure is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method error
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} error event.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync error: function (transaction, e, config) {
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync transaction.evt = e;
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync this._evt(EVENTS[4], transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Retry an XDR transaction, using the Flash tranport, if the native
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * transport fails.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync *
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @method _retry
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {String} uri Qualified path to transaction resource.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync */
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync _retry: function(transaction, uri, config) {
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync this._destroy(transaction);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync config.xdr.use = 'flash';
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync return this.send(uri, config, transaction.id);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync /**
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Method that concatenates string data for HTTP GET transactions.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _concat
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {String} uri URI or root data.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {String} data Data to be concatenated onto URI.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @return {String}
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync */
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync _concat: function(uri, data) {
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync uri += (uri.indexOf('?') === -1 ? '?' : '&') + data;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync return uri;
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync },
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync /**
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Stores default client headers for all transactions. If a label is
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * passed with no value argument, the header will be deleted.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync *
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @method setHeader
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @param {String} name HTTP header
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @param {String} value HTTP header value
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync setHeader: function(name, value) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (value) {
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync this._headers[name] = value;
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync } else {
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync delete this._headers[name];
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Method that sets all HTTP headers to be sent in a transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @method _setHeaders
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction - XHR instance for the specific transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} headers - HTTP headers for the specific transaction, as
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * defined in the configuration object passed to YUI.io().
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync */
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync _setHeaders: function(transaction, headers) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync headers = Y.merge(this._headers, headers);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync Y.Object.each(headers, function(value, name) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (value !== 'disable') {
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync transaction.setRequestHeader(name, headers[name]);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync });
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync },
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Starts timeout count if the configuration object has a defined
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * timeout property.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _startTimeout
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object generated by _create().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} timeout Timeout in milliseconds.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _startTimeout: function(transaction, timeout) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io._timeout[transaction.id] = setTimeout(function() {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io._abort(transaction, 'timeout');
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }, timeout);
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync },
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Clears the timeout interval started by _startTimeout().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _clearTimeout
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @param {Number} id - Transaction id.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync */
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync _clearTimeout: function(id) {
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync clearTimeout(this._timeout[id]);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync delete this._timeout[id];
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Method that determines if a transaction response qualifies as success
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * or failure, based on the response HTTP status code, and fires the
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * appropriate success or failure events.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _result
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @static
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object generated by _create().
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * @param {Object} config Configuration object passed to io().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync _result: function(transaction, config) {
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync var status;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Firefox will throw an exception if attempting to access
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync // an XHR object's status property, after a request is aborted.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync try {
329081e295d2a28a39899b3f919f3c65eef227f0vboxsync status = transaction.c.status;
329081e295d2a28a39899b3f919f3c65eef227f0vboxsync } catch(e) {
329081e295d2a28a39899b3f919f3c65eef227f0vboxsync status = 0;
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync }
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // IE reports HTTP 204 as HTTP 1223.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync if (status >= 200 && status < 300 || status === 304 || status === 1223) {
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync this.success(transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync } else {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync this.failure(transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync },
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Event handler bound to onreadystatechange.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _rS
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object generated by _create().
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * @param {Object} config Configuration object passed to YUI.io().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _rS: function(transaction, config) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (transaction.c.readyState === 4) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (config.timeout) {
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync io._clearTimeout(transaction.id);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Yield in the event of request timeout or abort.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync setTimeout(function() {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.complete(transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io._result(transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }, 0);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync },
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * Terminates a transaction due to an explicit abort or timeout.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _abort
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @private
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object generated by _create().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {String} type Identifies timed out or aborted transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync _abort: function(transaction, type) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (transaction && transaction.c) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.e = type;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction.c.abort();
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync }
329081e295d2a28a39899b3f919f3c65eef227f0vboxsync },
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync /**
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * Requests a transaction. `send()` is implemented as `Y.io()`. Each
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transaction may include a configuration object. Its properties are:
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dl>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>method</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>HTTP method verb (e.g., GET or POST). If this property is not
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * not defined, the default value will be GET.</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>data</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>This is the name-value string that will be sent as the
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transaction data. If the request is HTTP GET, the data become
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * part of querystring. If HTTP POST, the data are sent in the
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * message body.</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * <dt>xdr</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>Defines the transport to be used for cross-domain requests.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * By setting this property, the transaction will use the specified
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transport instead of XMLHttpRequest. The properties of the
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transport object are:
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dl>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>use</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>The transport to be used: 'flash' or 'native'</dd>
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * <dt>dataType</dt>
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * <dd>Set the value to 'XML' if that is the expected response
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * content type.</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * </dl></dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>form</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>Form serialization configuration object. Its properties are:
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dl>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>id</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>Node object or id of HTML form</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>useDisabled</dt>
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * <dd>`true` to also serialize disabled form field values
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * (defaults to `false`)</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * </dl></dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>on</dt>
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * <dd>Assigns transaction event subscriptions. Available events are:
329081e295d2a28a39899b3f919f3c65eef227f0vboxsync * <dl>
329081e295d2a28a39899b3f919f3c65eef227f0vboxsync * <dt>start</dt>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dd>Fires when a request is sent to a resource.</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>complete</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>Fires when the transaction is complete.</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>success</dt>
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * <dd>Fires when the HTTP response status is within the 2xx
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * range.</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>failure</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>Fires when the HTTP response status is outside the 2xx
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * range, if an exception occurs, if the transation is aborted,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * or if the transaction exceeds a configured `timeout`.</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dt>end</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>Fires at the conclusion of the transaction
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * lifecycle, after `success` or `failure`.</dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * </dl>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <p>Callback functions for `start` and `end` receive the id of the
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transaction as a first argument. For `complete`, `success`, and
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * `failure`, callbacks receive the id and the response object
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * (usually the XMLHttpRequest instance). If the `arguments`
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * property was included in the configuration object passed to
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * `Y.io()`, the configured data will be passed to all callbacks as
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * the last argument.</p>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * </dd>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync *
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dt>sync</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>Pass `true` to make a same-domain transaction synchronous.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <strong>CAVEAT</strong>: This will negatively impact the user
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * experience. Have a <em>very</em> good reason if you intend to use
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * this.</dd>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync *
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dt>context</dt>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dd>The "`this'" object for all configured event handlers. If a
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * specific context is needed for individual callbacks, bind the
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * callback to a context using `Y.bind()`.</dd>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync *
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dt>headers</dt>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dd>Object map of transaction headers to send to the server. The
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * object keys are the header names and the values are the header
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * values.</dd>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync *
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dt>timeout</dt>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dd>Millisecond threshold for the transaction before being
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * automatically aborted.</dd>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync *
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dt>arguments</dt>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dd>User-defined data passed to all registered event handlers.
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * This value is available as the second argument in the "start" and
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * "end" event handlers. It is the third argument in the "complete",
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * "success", and "failure" event handlers. <strong>Be sure to quote
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * this property name in the transaction configuration as
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * "arguments" is a reserved word in JavaScript</strong> (e.g.
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * `Y.io({ ..., "arguments": stuff })`).</dd>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * </dl>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync *
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @method send
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @public
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @param {String} uri Qualified path to transaction resource.
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @param {Object} config Configuration object for the transaction.
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @param {Number} id Transaction id, if already set.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @return {Object}
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync */
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync send: function(uri, config, id) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var transaction, method, i, len, sync, data,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io = this,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync u = uri,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync response = {};
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync config = config ? Y.Object(config) : {};
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction = io._create(config, id);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync method = config.method ? config.method.toUpperCase() : 'GET';
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync sync = config.sync;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync data = config.data;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Serialize an map object into a key-value string using
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // querystring-stringify-simple.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if ((Y.Lang.isObject(data) && !data.nodeType) && !transaction.upload) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync data = Y.QueryString.stringify(data);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (config.form) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (config.form.upload) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // This is a file upload transaction, calling
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // upload() in io-upload-iframe.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync return io.upload(transaction, uri, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync } else {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Serialize HTML form data into a key-value string.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync data = io._serialize(config.form, data);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync if (data) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync switch (method) {
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync case 'GET':
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync case 'HEAD':
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync case 'DELETE':
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync u = io._concat(u, data);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync data = '';
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync Y.log('HTTP' + method + ' with data. The querystring is: ' + u, 'info', 'io');
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync break;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync case 'POST':
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync case 'PUT':
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // If Content-Type is defined in the configuration object, or
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // or as a default header, it will be used instead of
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // 'application/x-www-form-urlencoded; charset=UTF-8'
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync config.headers = Y.merge({
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }, config.headers);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync break;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (transaction.xdr) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Route data to io-xdr module for flash and XDomainRequest.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync return io.xdr(u, transaction, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync else if (transaction.notify) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Route data to custom transport
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync return transaction.c.send(transaction, uri, config);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync }
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync
if (!sync && !transaction.upload) {
transaction.c.onreadystatechange = function() {
io._rS(transaction, config);
};
}
try {
// Determine if request is to be set as
// synchronous or asynchronous.
transaction.c.open(method, u, !sync, config.username || null, config.password || null);
io._setHeaders(transaction.c, config.headers || {});
io.start(transaction, config);
// Will work only in browsers that implement the
// Cross-Origin Resource Sharing draft.
if (config.xdr && config.xdr.credentials) {
if (!Y.UA.ie) {
transaction.c.withCredentials = true;
}
}
// Using "null" with HTTP POST will result in a request
// with no Content-Length header defined.
transaction.c.send(data);
if (sync) {
// Create a response object for synchronous transactions,
// mixing id and arguments properties with the xhr
// properties whitelist.
for (i = 0, len = XHR_PROPS.length; i < len; ++i) {
response[XHR_PROPS[i]] = transaction.c[XHR_PROPS[i]];
}
response.getAllResponseHeaders = function() {
return transaction.c.getAllResponseHeaders();
};
response.getResponseHeader = function(name) {
return transaction.c.getResponseHeader(name);
};
io.complete(transaction, config);
io._result(transaction, config);
return response;
}
} catch(e) {
if (transaction.xdr) {
// This exception is usually thrown by browsers
// that do not support XMLHttpRequest Level 2.
// Retry the request with the XDR transport set
// to 'flash'. If the Flash transport is not
// initialized or available, the transaction
// will resolve to a transport error.
return io._retry(transaction, uri, config);
} else {
io.complete(transaction, config);
io._result(transaction, config);
}
}
// If config.timeout is defined, and the request is standard XHR,
// initialize timeout polling.
if (config.timeout) {
io._startTimeout(transaction, config.timeout);
Y.log('Configuration timeout set to: ' + config.timeout, 'info', 'io');
}
return {
id: transaction.id,
abort: function() {
return transaction.c ? io._abort(transaction, 'abort') : false;
},
isInProgress: function() {
return transaction.c ? (transaction.c.readyState % 4) : false;
},
io: io
};
}
};
/**
Method for initiating an ajax call. The first argument is the url end
point for the call. The second argument is an object to configure the
transaction and attach event subscriptions. The configuration object
supports the following properties:
<dl>
<dt>method</dt>
<dd>HTTP method verb (e.g., GET or POST). If this property is not
not defined, the default value will be GET.</dd>
<dt>data</dt>
<dd>This is the name-value string that will be sent as the
transaction data. If the request is HTTP GET, the data become
part of querystring. If HTTP POST, the data are sent in the
message body.</dd>
<dt>xdr</dt>
<dd>Defines the transport to be used for cross-domain requests.
By setting this property, the transaction will use the specified
transport instead of XMLHttpRequest. The properties of the
transport object are:
<dl>
<dt>use</dt>
<dd>The transport to be used: 'flash' or 'native'</dd>
<dt>dataType</dt>
<dd>Set the value to 'XML' if that is the expected response
content type.</dd>
</dl></dd>
<dt>form</dt>
<dd>Form serialization configuration object. Its properties are:
<dl>
<dt>id</dt>
<dd>Node object or id of HTML form</dd>
<dt>useDisabled</dt>
<dd>`true` to also serialize disabled form field values
(defaults to `false`)</dd>
</dl></dd>
<dt>on</dt>
<dd>Assigns transaction event subscriptions. Available events are:
<dl>
<dt>start</dt>
<dd>Fires when a request is sent to a resource.</dd>
<dt>complete</dt>
<dd>Fires when the transaction is complete.</dd>
<dt>success</dt>
<dd>Fires when the HTTP response status is within the 2xx
range.</dd>
<dt>failure</dt>
<dd>Fires when the HTTP response status is outside the 2xx
range, if an exception occurs, if the transation is aborted,
or if the transaction exceeds a configured `timeout`.</dd>
<dt>end</dt>
<dd>Fires at the conclusion of the transaction
lifecycle, after `success` or `failure`.</dd>
</dl>
<p>Callback functions for `start` and `end` receive the id of the
transaction as a first argument. For `complete`, `success`, and
`failure`, callbacks receive the id and the response object
(usually the XMLHttpRequest instance). If the `arguments`
property was included in the configuration object passed to
`Y.io()`, the configured data will be passed to all callbacks as
the last argument.</p>
</dd>
<dt>sync</dt>
<dd>Pass `true` to make a same-domain transaction synchronous.
<strong>CAVEAT</strong>: This will negatively impact the user
experience. Have a <em>very</em> good reason if you intend to use
this.</dd>
<dt>context</dt>
<dd>The "`this'" object for all configured event handlers. If a
specific context is needed for individual callbacks, bind the
callback to a context using `Y.bind()`.</dd>
<dt>headers</dt>
<dd>Object map of transaction headers to send to the server. The
object keys are the header names and the values are the header
values.</dd>
<dt>timeout</dt>
<dd>Millisecond threshold for the transaction before being
automatically aborted.</dd>
<dt>arguments</dt>
<dd>User-defined data passed to all registered event handlers.
This value is available as the second argument in the "start" and
"end" event handlers. It is the third argument in the "complete",
"success", and "failure" event handlers. <strong>Be sure to quote
this property name in the transaction configuration as
"arguments" is a reserved word in JavaScript</strong> (e.g.
`Y.io({ ..., "arguments": stuff })`).</dd>
</dl>
@method io
@static
@param {String} url qualified path to transaction resource.
@param {Object} config configuration object for the transaction.
@return {Object}
@for YUI
**/
Y.io = function(url, config) {
// Calling IO through the static interface will use and reuse
// an instance of IO.
var transaction = Y.io._map['io:0'] || new IO();
return transaction.send.apply(transaction, [url, config]);
};
/**
Method for setting and deleting IO HTTP headers to be sent with every
request.
Hosted as a property on the `io` function (e.g. `Y.io.header`).
@method header
@param {String} name HTTP header
@param {String} value HTTP header value
@static
**/
Y.io.header = function(name, value) {
// Calling IO through the static interface will use and reuse
// an instance of IO.
var transaction = Y.io._map['io:0'] || new IO();
transaction.setHeader(name, value);
};
Y.IO = IO;
// Map of all IO instances created.
Y.io._map = {};