io-upload-iframe-debug.js revision a2d0f15986afef30b833db3884d70718716a6a56
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt SweeneyYUI.add('io-upload-iframe', function(Y) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * Extends the IO base class to enable file uploads, with HTML forms,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * using an iframe as the transport medium.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @module io
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @submodule io-upload-iframe
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var w = Y.config.win,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney d = Y.config.doc,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney _std = (d.documentMode && d.documentMode >= 8),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney _d = decodeURIComponent;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description Parses the POST data object and creates hidden form elements
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * for each key-value, and appends them to the HTML form object.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method appendData
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} f HTML form object.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {string} s The key-value POST data.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {array} e Array of created fields.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _addData(f, s) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var o = [],
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney m = s.split('='),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney i, l;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney for (i = 0, l = m.length - 1; i < l; i++) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney o[i] = d.createElement('input');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney o[i].type = 'hidden';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney o[i].name = _d(m[i].substring(m[i].lastIndexOf('&') + 1));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney o[i].value = (i + 1 === l) ? _d(m[i + 1]) : _d(m[i + 1].substring(0, (m[i + 1].lastIndexOf('&'))));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney f.appendChild(o[i]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.log('key: ' + o[i].name + ' and value: ' + o[i].value + ' added as form data.', 'info', 'io');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return o;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description Removes the custom fields created to pass additional POST
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * data, along with the HTML form fields.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method f
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} f HTML form object.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} o HTML form fields created from configuration.data.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _removeData(f, o) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var i, l;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney for(i = 0, l = o.length; i < l; i++){
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney f.removeChild(o[i]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description Sets the appropriate attributes and values to the HTML
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * form, in preparation of a file upload transaction.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method _setAttrs
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} f HTML form object.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} id The Transaction ID.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} uri Qualified path to transaction resource.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _setAttrs(f, id, uri) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney f.setAttribute('action', uri);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney f.setAttribute('method', 'POST');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney f.setAttribute('target', 'ioupload' + id );
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney f.setAttribute(Y.UA.ie && !_std ? 'encoding' : 'enctype', 'multipart/form-data');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description Sets the appropriate attributes and values to the HTML
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * form, in preparation of a file upload transaction.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method _resetAttrs
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} f HTML form object.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} a Object of original attributes.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _resetAttrs(f, a){
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var p;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney for (p in a) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney if (a.hasOwnProperty(a, p)) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney if (a[p]) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney f.setAttribute(p, f[p]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney else {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney f.removeAttribute(p);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description Starts timeout count if the configuration object
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * has a defined timeout property.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney *
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method _startTimeout
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} o Transaction object generated by _create().
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} c Configuration object passed to YUI.io().
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _startTimeout(o, c) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.io._timeout[o.id] = w.setTimeout(
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var r = { id: o.id, status: 'timeout' };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.io.complete(r, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.io.end(r, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.log('Transaction ' + o.id + ' timeout.', 'info', 'io');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }, c.timeout);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description Clears the timeout interval started by _startTimeout().
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method _clearTimeout
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {number} id - Transaction ID.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _clearTimeout(id) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney w.clearTimeout(Y.io._timeout[id]);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney delete Y.io._timeout[id];
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method _destroy
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {o} o The transaction object
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} uri Qualified path to transaction resource.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} c Configuration object for the transaction.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _destroy(id) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.Event.purgeElement('#ioupload' + id, false);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.one('body').removeChild(Y.one('#ioupload' + id));
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.log('The iframe transport for transaction ' + id + ' has been destroyed.', 'info', 'io');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description Bound to the iframe's Load event and processes
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * the response data.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method _handle
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {o} o The transaction object
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} c Configuration object for the transaction.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _handle(o, c) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var d = Y.one('#ioupload' + o.id).get('contentWindow.document'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney b = d.one('body'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney p;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney if (c.timeout) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney _clearTimeout(o.id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney if (b) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // When a response Content-Type of "text/plain" is used, Firefox and Safari
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // will wrap the response string with <pre></pre>.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney p = b.query('pre:first-child');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney o.c.responseText = p ? p.get('text') : b.get('text');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.log('The responseText value for transaction ' + o.id + ' is: ' + o.c.responseText + '.', 'info', 'io');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney else {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney o.c.responseXML = d._node;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.log('The response for transaction ' + o.id + ' is an XML document.', 'info', 'io');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.io.complete(o, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.io.end(o, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // The transaction is complete, so call _destroy to remove
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // the event listener bound to the iframe transport, and then
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // destroy the iframe.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney w.setTimeout( function() { _destroy(o.id); }, 0);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney /**
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney * @description Creates the iframe transported used in file upload
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney * transactions, and binds the response event handler.
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney *
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney * @method _create
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney * @private
c31e28da00e9fe86d7e9aebaa5ff25933fec30b4Matt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} o Transaction object generated by _create().
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} c Configuration object passed to YUI.io().
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _create(o, c) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var i = Y.Node.create('<iframe id="ioupload' + o.id + '" name="ioupload' + o.id + '" />');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney i._node.style.position = 'absolute';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney i._node.style.top = '-1000px';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney i._node.style.left = '-1000px';
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.one('body').appendChild(i);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // Bind the onload handler to the iframe to detect the file upload response.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.on("load", function() { _handle(o, c); }, '#ioupload' + o.id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney /**
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @description Uploads HTML form data, inclusive of files/attachments,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * using the iframe created in _create to facilitate the transaction.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @method _upload
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @private
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @static
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {o} o The transaction object
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} uri Qualified path to transaction resource.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @param {object} c Configuration object for the transaction.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney * @return {void}
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney */
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney function _send(o, uri, c) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var f = (typeof c.form.id === 'string') ? d.getElementById(c.form.id) : c.form.id,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fields,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // Track original HTML form attribute values.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney attr = {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney action: f.getAttribute('action'),
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney target: f.getAttribute('target')
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // Initialize the HTML form properties in case they are
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // not defined in the HTML form.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney _setAttrs(f, o.id, uri);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney if (c.data) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney fields = _addData(f, c.data);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // Start polling if a callback is present and the timeout
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney // property has been defined.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney if (c.timeout) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney _startTimeout(o, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.log('Transaction timeout started for transaction ' + o.id + '.', 'info', 'io');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney // Start file upload.
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney f.submit();
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney Y.io.start(o.id, c);
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney if (c.data) {
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney _removeData(f, fields);
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney }
82f3694450ab9870df1b580e54d8cb58968869f9Matt Sweeney // Restore HTML form attributes to their original values.
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney _resetAttrs(f, attr);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney id: o.id,
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney abort: function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney var r = { id: o.id, status: 'abort' };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney if (Y.one('#ioupload' + o.id)) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney _destroy(o.id);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.io.complete(r, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.io.end(r, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.log('Transaction ' + o.id + ' aborted.', 'info', 'io');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney else {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.log('Attempted to abort transaction ' + o.id + ' but transaction has completed.', 'warn', 'io');
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return false;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney },
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney isInProgress: function() {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return Y.one('#ioupload' + o.id) ? true : false;
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney };
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney Y.mix(Y.io, {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney upload: function(o, uri, c) {
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney _create(o, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney return _send(o, uri, c);
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney }
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney });
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney}, '@VERSION@' ,{requires:['io-base','node-base']});
fdfbb58f76522ce41b2c8af7f0a9274dcf82cd4aMatt Sweeney