| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844 |
- /*
- Copyright (c) 2010, Yahoo! Inc. All rights reserved.
- Code licensed under the BSD License:
- http://developer.yahoo.com/yui/license.html
- version: 3.4.0
- build: nightly
- */
- YUI.add('io-base', function(Y) {
-
- /**
- Base IO functionality. Provides basic XHR transport support.
- @module io-base
- @main io-base
- @for IO
- **/
-
- var isNumber = Y.Lang.isNumber,
- isObject = Y.Lang.isObject,
-
- // List of events that comprise the IO event lifecycle.
- EVENTS = ['start', 'complete', 'end', 'success', 'failure'],
-
- // Whitelist of used XHR response object properties.
- XHR_PROPS = ['status', 'statusText', 'responseText', 'responseXML'],
-
- win = Y.config.win,
- NativeXHR = win.XMLHttpRequest,
- NativeXDR = win.XDomainRequest,
- uid = 0;
-
- /**
- The IO class is a utility that brokers HTTP requests through a simplified
- interface. Specifically, it allows JavaScript to make HTTP requests to
- a resource without a page reload. The underlying transport for making
- same-domain requests is the XMLHttpRequest object. IO can also use
- Flash, if specified as a transport, for cross-domain requests.
-
- @class IO
- @constructor
- @param {Object} config Object of EventTarget's publish method configurations
- used to configure IO's events.
- **/
- function IO (config) {
- var io = this;
-
- io._uid = 'io:' + uid++;
- io._init(config);
- Y.io._map[io._uid] = io;
- }
-
- IO.prototype = {
- //--------------------------------------
- // Properties
- //--------------------------------------
-
- /**
- * A counter that increments for each transaction.
- *
- * @property _id
- * @private
- * @type {Number}
- */
- _id: 0,
-
- /**
- * Object of IO HTTP headers sent with each transaction.
- *
- * @property _headers
- * @private
- * @type {Object}
- */
- _headers: {
- 'X-Requested-With' : 'XMLHttpRequest'
- },
-
- /**
- * Object that stores timeout values for any transaction with a defined
- * "timeout" configuration property.
- *
- * @property _timeout
- * @private
- * @type {Object}
- */
- _timeout: {},
-
- //--------------------------------------
- // Methods
- //--------------------------------------
-
- _init: function(config) {
- var io = this, i;
-
- io.cfg = config || {};
-
- Y.augment(io, Y.EventTarget);
- for (i = 0; i < 5; i++) {
- // Publish IO global events with configurations, if any.
- // IO global events are set to broadcast by default.
- // These events use the "io:" namespace.
- io.publish('io:' + EVENTS[i], Y.merge({ broadcast: 1 }, config));
- // Publish IO transaction events with configurations, if
- // any. These events use the "io-trn:" namespace.
- io.publish('io-trn:' + EVENTS[i], config);
- }
- },
-
- /**
- * Method that creates a unique transaction object for each request.
- *
- * @method _create
- * @private
- * @param {Object} config Configuration object subset to determine if
- * the transaction is an XDR or file upload,
- * requiring an alternate transport.
- * @param {Number} id Transaction id
- * @return {Object} The transaction object
- */
- _create: function(config, id) {
- var io = this,
- transaction = {
- id : isNumber(id) ? id : io._id++,
- uid: io._uid
- },
- xdrConfig = config.xdr,
- use = xdrConfig && xdrConfig.use,
- ie = (xdrConfig && xdrConfig.use === 'native' && NativeXDR),
- transport = io._transport;
-
- if (!use) {
- use = (config.form && config.form.upload) ? 'iframe' : 'xhr';
- }
-
- switch (use) {
- case 'native':
- case 'xhr':
- transaction.c = ie ?
- new NativeXDR() :
- NativeXHR ?
- new NativeXHR() :
- new ActiveXObject('Microsoft.XMLHTTP');
- transaction.t = ie ? true : false;
- break;
- default:
- transaction.c = (transport && transport[use]) || {};
- transaction.t = true;
- }
-
- return transaction;
- },
-
- _destroy: function(transaction) {
- if (win && !transaction.t) {
- if (NativeXHR) {
- transaction.c.onreadystatechange = null;
- } else if (Y.UA.ie && !transaction.e) {
- // IE, when using XMLHttpRequest as an ActiveX Object, will throw
- // a "Type Mismatch" error if the event handler is set to "null".
- transaction.c.abort();
- }
- }
-
- transaction = transaction.c = null;
- },
-
- /**
- * Method for creating and firing events.
- *
- * @method _evt
- * @private
- * @param {String} eventName Event to be published.
- * @param {Object} transaction Transaction object.
- * @param {Object} config Configuration data subset for event subscription.
- */
- _evt: function(eventName, transaction, config) {
- var io = this, params,
- args = config['arguments'],
- emitFacade = io.cfg.emitFacade,
- globalEvent = "io:" + eventName,
- trnEvent = "io-trn:" + eventName;
-
- if (transaction.e) {
- transaction.c = { status: 0, statusText: transaction.e };
- }
-
- // Fire event with parameters or an Event Facade.
- params = [(emitFacade) ?
- {
- id: transaction.id,
- data: transaction.c,
- cfg: config,
- 'arguments': args
- } :
- transaction.id
- ];
-
- if (!emitFacade) {
- if (eventName === EVENTS[0] || eventName === EVENTS[2]) {
- if (args) {
- params.push(args);
- }
- } else {
- params.push(transaction.c);
- if (args) {
- params.push(args);
- }
- }
- }
-
- params.unshift(globalEvent);
- // Fire global events.
- io.fire.apply(io, params);
- // Fire transaction events, if receivers are defined.
- if (config.on) {
- params[0] = trnEvent;
- io.once(trnEvent, config.on[eventName], config.context || Y);
- io.fire.apply(io, params);
- }
- },
-
- /**
- * Fires event "io:start" and creates, fires a transaction-specific
- * start event, if `config.on.start` is defined.
- *
- * @method start
- * @param {Object} transaction Transaction object.
- * @param {Object} config Configuration object for the transaction.
- */
- start: function(transaction, config) {
- /**
- * Signals the start of an IO request.
- * @event io:start
- */
- this._evt(EVENTS[0], transaction, config);
- },
-
- /**
- * Fires event "io:complete" and creates, fires a
- * transaction-specific "complete" event, if config.on.complete is
- * defined.
- *
- * @method complete
- * @param {Object} transaction Transaction object.
- * @param {Object} config Configuration object for the transaction.
- */
- complete: function(transaction, config) {
- /**
- * Signals the completion of the request-response phase of a
- * transaction. Response status and data are accessible, if
- * available, in this event.
- * @event io:complete
- */
- this._evt(EVENTS[1], transaction, config);
- },
-
- /**
- * Fires event "io:end" and creates, fires a transaction-specific "end"
- * event, if config.on.end is defined.
- *
- * @method end
- * @param {Object} transaction Transaction object.
- * @param {Object} config Configuration object for the transaction.
- */
- end: function(transaction, config) {
- /**
- * Signals the end of the transaction lifecycle.
- * @event io:end
- */
- this._evt(EVENTS[2], transaction, config);
- this._destroy(transaction);
- },
-
- /**
- * Fires event "io:success" and creates, fires a transaction-specific
- * "success" event, if config.on.success is defined.
- *
- * @method success
- * @param {Object} transaction Transaction object.
- * @param {Object} config Configuration object for the transaction.
- */
- success: function(transaction, config) {
- /**
- * Signals an HTTP response with status in the 2xx range.
- * Fires after io:complete.
- * @event io:success
- */
- this._evt(EVENTS[3], transaction, config);
- this.end(transaction, config);
- },
-
- /**
- * Fires event "io:failure" and creates, fires a transaction-specific
- * "failure" event, if config.on.failure is defined.
- *
- * @method failure
- * @param {Object} transaction Transaction object.
- * @param {Object} config Configuration object for the transaction.
- */
- failure: function(transaction, config) {
- /**
- * Signals an HTTP response with status outside of the 2xx range.
- * Fires after io:complete.
- * @event io:failure
- */
- this._evt(EVENTS[4], transaction, config);
- this.end(transaction, config);
- },
-
- /**
- * Retry an XDR transaction, using the Flash tranport, if the native
- * transport fails.
- *
- * @method _retry
- * @private
- * @param {Object} transaction Transaction object.
- * @param {String} uri Qualified path to transaction resource.
- * @param {Object} config Configuration object for the transaction.
- */
- _retry: function(transaction, uri, config) {
- this._destroy(transaction);
- config.xdr.use = 'flash';
- return this.send(uri, config, transaction.id);
- },
-
- /**
- * Method that concatenates string data for HTTP GET transactions.
- *
- * @method _concat
- * @private
- * @param {String} uri URI or root data.
- * @param {String} data Data to be concatenated onto URI.
- * @return {String}
- */
- _concat: function(uri, data) {
- uri += (uri.indexOf('?') === -1 ? '?' : '&') + data;
- return uri;
- },
-
- /**
- * Stores default client headers for all transactions. If a label is
- * passed with no value argument, the header will be deleted.
- *
- * @method setHeader
- * @param {String} name HTTP header
- * @param {String} value HTTP header value
- */
- setHeader: function(name, value) {
- if (value) {
- this._headers[name] = value;
- } else {
- delete this._headers[name];
- }
- },
-
- /**
- * Method that sets all HTTP headers to be sent in a transaction.
- *
- * @method _setHeaders
- * @private
- * @param {Object} transaction - XHR instance for the specific transaction.
- * @param {Object} headers - HTTP headers for the specific transaction, as
- * defined in the configuration object passed to YUI.io().
- */
- _setHeaders: function(transaction, headers) {
- headers = Y.merge(this._headers, headers);
- Y.Object.each(headers, function(value, name) {
- if (value !== 'disable') {
- transaction.setRequestHeader(name, headers[name]);
- }
- });
- },
-
- /**
- * Starts timeout count if the configuration object has a defined
- * timeout property.
- *
- * @method _startTimeout
- * @private
- * @param {Object} transaction Transaction object generated by _create().
- * @param {Object} timeout Timeout in milliseconds.
- */
- _startTimeout: function(transaction, timeout) {
- var io = this;
-
- io._timeout[transaction.id] = win.setTimeout(function() {
- io._abort(transaction, 'timeout');
- }, timeout);
- },
-
- /**
- * Clears the timeout interval started by _startTimeout().
- *
- * @method _clearTimeout
- * @private
- * @param {Number} id - Transaction id.
- */
- _clearTimeout: function(id) {
- win.clearTimeout(this._timeout[id]);
- delete this._timeout[id];
- },
-
- /**
- * Method that determines if a transaction response qualifies as success
- * or failure, based on the response HTTP status code, and fires the
- * appropriate success or failure events.
- *
- * @method _result
- * @private
- * @static
- * @param {Object} transaction Transaction object generated by _create().
- * @param {Object} config Configuration object passed to io().
- */
- _result: function(transaction, config) {
- var status;
- // Firefox will throw an exception if attempting to access
- // an XHR object's status property, after a request is aborted.
- try {
- status = transaction.c.status;
- } catch(e) {
- status = 0;
- }
-
- // IE reports HTTP 204 as HTTP 1223.
- if (status >= 200 && status < 300 || status === 304 || status === 1223) {
- this.success(transaction, config);
- } else {
- this.failure(transaction, config);
- }
- },
-
- /**
- * Event handler bound to onreadystatechange.
- *
- * @method _rS
- * @private
- * @param {Object} transaction Transaction object generated by _create().
- * @param {Object} config Configuration object passed to YUI.io().
- */
- _rS: function(transaction, config) {
- var io = this;
-
- if (transaction.c.readyState === 4) {
- if (config.timeout) {
- io._clearTimeout(transaction.id);
- }
-
- // Yield in the event of request timeout or abort.
- win.setTimeout(function() {
- io.complete(transaction, config);
- io._result(transaction, config);
- }, 0);
- }
- },
-
- /**
- * Terminates a transaction due to an explicit abort or timeout.
- *
- * @method _abort
- * @private
- * @param {Object} transaction Transaction object generated by _create().
- * @param {String} type Identifies timed out or aborted transaction.
- */
- _abort: function(transaction, type) {
- if (transaction && transaction.c) {
- transaction.e = type;
- transaction.c.abort();
- }
- },
-
- /**
- * Requests a transaction. `send()` is implemented as `Y.io()`. Each
- * transaction may include a configuration object. Its properties are:
- *
- * <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 send
- * @public
- * @param {String} uri Qualified path to transaction resource.
- * @param {Object} config Configuration object for the transaction.
- * @param {Number} id Transaction id, if already set.
- * @return {Object}
- */
- send: function(uri, config, id) {
- var transaction, method, i, len, sync, data,
- io = this,
- u = uri,
- response = {};
-
- config = config ? Y.Object(config) : {};
- transaction = io._create(config, id);
- method = config.method ? config.method.toUpperCase() : 'GET';
- sync = config.sync;
- data = config.data;
-
- // Serialize an object into a key-value string using
- // querystring-stringify-simple.
- if (isObject(data)) {
- data = Y.QueryString.stringify(data);
- }
-
- if (config.form) {
- if (config.form.upload) {
- // This is a file upload transaction, calling
- // upload() in io-upload-iframe.
- return io.upload(transaction, uri, config);
- } else {
- // Serialize HTML form data into a key-value string.
- data = io._serialize(config.form, data);
- }
- }
-
- if (data) {
- switch (method) {
- case 'GET':
- case 'HEAD':
- case 'DELETE':
- u = io._concat(u, data);
- data = '';
- Y.log('HTTP' + method + ' with data. The querystring is: ' + u, 'info', 'io');
- break;
- case 'POST':
- case 'PUT':
- // If Content-Type is defined in the configuration object, or
- // or as a default header, it will be used instead of
- // 'application/x-www-form-urlencoded; charset=UTF-8'
- config.headers = Y.merge({
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
- }, config.headers);
- break;
- }
- }
-
- if (transaction.t) {
- // Cross-domain request or custom transport configured.
- return io.xdr(u, transaction, config);
- }
-
- if (!sync) {
- 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.t) {
- // 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 = {};
-
-
-
- }, '3.4.0' ,{requires:['event-custom-base', 'querystring-stringify-simple']});
|