io-base.js revision 361214abdd3c8302e5ce0c74cc9200f32bee3516
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncBase IO functionality. Provides basic XHR transport support.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@module io-base
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@main io-base
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsyncvar // List of events that comprise the IO event lifecycle.
78f327ee942771169c65c91baf789fd10e72b01avboxsync EVENTS = ['start', 'complete', 'end', 'success', 'failure', 'progress'],
78f327ee942771169c65c91baf789fd10e72b01avboxsync // Whitelist of used XHR response object properties.
78f327ee942771169c65c91baf789fd10e72b01avboxsync XHR_PROPS = ['status', 'statusText', 'responseText', 'responseXML'],
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@constructor
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync@param {Object} config Object of EventTarget's publish method configurations
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync used to configure IO's events.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync //--------------------------------------
701a45600245e42829e1187817299e812eebdec5vboxsync // Properties
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync //--------------------------------------
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * A counter that increments for each transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @property _id
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @type {Number}
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Object of IO HTTP headers sent with each transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @property _headers
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @type {Object}
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Object that stores timeout values for any transaction with a defined
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "timeout" configuration property.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @property _timeout
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @type {Object}
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync //--------------------------------------
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync //--------------------------------------
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 * Method that creates a unique transaction object for each request.
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * @method _create
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 var io = this,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync form = config.form && config.form.upload ? 'iframe' : null,
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Non-IE can use XHR level 2 and not rely on an
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // external transport.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync transaction = use ? Y.merge(Y.IO.customTransport(use), transaction) :
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync config.notify = function (e, t, c) { io.notify(e, t, c); };
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync if (win && win.FormData && config.data instanceof FormData) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (win && !transaction.notify && !transaction.xdr) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // IE, when using XMLHttpRequest as an ActiveX Object, will throw
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // a "Type Mismatch" error if the event handler is set to "null".
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * Method for creating and firing events.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _evt
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 transaction.c = { status: 0, statusText: transaction.e };
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Fire event with parameters or an Event Facade.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync if (eventName === EVENTS[0] || eventName === EVENTS[2]) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Fire global events.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Fire transaction events, if receivers are defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io.once(trnEvent, config.on[eventName], config.context || Y);
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:start" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * start event, if `config.on.start` is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method start
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Signals the start of an IO request.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:start
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:complete" and creates, fires a
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transaction-specific "complete" event, if config.on.complete is
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method complete
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
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 * Fires event "io:end" and creates, fires a transaction-specific "end"
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * event, if config.on.end is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method end
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Signals the end of the transaction lifecycle.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:end
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:success" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "success" event, if config.on.success is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method success
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Signals an HTTP response with status in the 2xx range.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires after io:complete.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:success
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Fires event "io:failure" and creates, fires a transaction-specific
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * "failure" event, if config.on.failure is defined.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method failure
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Signals an HTTP response with status outside of the 2xx range.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Fires after io:complete.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @event io:failure
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 * @method progress
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} progress event.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
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
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 * @method load
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} load event.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} config Configuration object for the transaction.
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 * @method error
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} error event.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @param {Object} config Configuration object for the transaction.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Retry an XDR transaction, using the Flash tranport, if the native
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * transport fails.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @method _retry
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 * Method that concatenates string data for HTTP GET transactions.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _concat
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {String} uri URI or root data.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {String} data Data to be concatenated onto URI.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @return {String}
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync uri += (uri.indexOf('?') === -1 ? '?' : '&') + data;
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * Stores default client headers for all transactions. If a label is
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * passed with no value argument, the header will be deleted.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @method setHeader
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @param {String} name HTTP header
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @param {String} value HTTP header value
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Method that sets all HTTP headers to be sent in a transaction.
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @method _setHeaders
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().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Starts timeout count if the configuration object has a defined
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * timeout property.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _startTimeout
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object generated by _create().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} timeout Timeout in milliseconds.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync io._timeout[transaction.id] = setTimeout(function() {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Clears the timeout interval started by _startTimeout().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _clearTimeout
2c872d5e527386b5202fb36f281a391aecd82c5fvboxsync * @param {Number} id - Transaction id.
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 * @method _result
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object generated by _create().
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * @param {Object} config Configuration object passed to io().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Firefox will throw an exception if attempting to access
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync // an XHR object's status property, after a request is aborted.
329081e295d2a28a39899b3f919f3c65eef227f0vboxsync } catch(e) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // IE reports HTTP 204 as HTTP 1223.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync if (status >= 200 && status < 300 || status === 304 || status === 1223) {
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * Event handler bound to onreadystatechange.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _rS
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object generated by _create().
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * @param {Object} config Configuration object passed to YUI.io().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync var io = this;
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Yield in the event of request timeout or abort.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * Terminates a transaction due to an explicit abort or timeout.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @method _abort
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {Object} transaction Transaction object generated by _create().
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * @param {String} type Identifies timed out or aborted transaction.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * Requests a transaction. `send()` is implemented as `Y.io()`. Each
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * transaction may include a configuration object. Its properties are:
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 * <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>
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 * <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 * <dt>form</dt>
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync * <dd>Form serialization configuration object. Its properties are:
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 * <dt>on</dt>
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync * <dd>Assigns transaction event subscriptions. Available events are:
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 * <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>
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 * <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 * <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 * <dt>timeout</dt>
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * <dd>Millisecond threshold for the transaction before being
e139144ef4fc5f2bbe26be64faf2737cd8ccf413vboxsync * automatically aborted.</dd>
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 * @method send
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}
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync method = config.method ? config.method.toUpperCase() : 'GET';
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 // This is a file upload transaction, calling
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // upload() in io-upload-iframe.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Serialize HTML form data into a key-value string.
e5967534664502b10b4b92306ad9d12a1a95a55evboxsync case 'GET':
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync case 'HEAD':
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync case 'DELETE':
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync Y.log('HTTP' + method + ' with data. The querystring is: ' + u, 'info', 'io');
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 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Route data to io-xdr module for flash and XDomainRequest.
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync // Route data to custom transport
dee9e52b1688c0617890cbbd8a8488f9f315d1b7vboxsync return transaction.c.send(transaction, uri, config);
if (sync) {
return response;
abort: function() {
isInProgress: function() {