/* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 3.0.0 build: 1549 */ YUI.add('io-upload-iframe', function(Y) { /** * Extends the IO base class to enable file uploads, with HTML forms, * using an iframe as the transport medium. * @module io * @submodule io-upload-iframe */ var w = Y.config.win; /** * @description Parses the POST data object and creates hidden form elements * for each key-value, and appends them to the HTML form object. * @method appendData * @private * @static * @param {object} f HTML form object. * @param {string} s The key-value POST data. * @return {array} e Array of created fields. */ function _addData(f, s) { var o = [], m = s.split('='), i, l; for (i = 0, l = m.length - 1; i < l; i++) { o[i] = document.createElement('input'); o[i].type = 'hidden'; o[i].name = m[i].substring(m[i].lastIndexOf('&') + 1); o[i].value = (i + 1 === l) ? m[i + 1] : m[i + 1].substring(0, (m[i + 1].lastIndexOf('&'))); f.appendChild(o[i]); } return o; } /** * @description Removes the custom fields created to pass additional POST * data, along with the HTML form fields. * @method f * @private * @static * @param {object} f HTML form object. * @param {object} o HTML form fields created from configuration.data. * @return {void} */ function _removeData(f, o) { var i, l; for(i = 0, l = o.length; i < l; i++){ f.removeChild(o[i]); } } /** * @description Sets the appropriate attributes and values to the HTML * form, in preparation of a file upload transaction. * @method _setAttrs * @private * @static * @param {object} f HTML form object. * @param {object} id The Transaction ID. * @param {object} uri Qualified path to transaction resource. * @return {void} */ function _setAttrs(f, id, uri) { var ie8 = (document.documentMode && document.documentMode === 8) ? true : false; f.setAttribute('action', uri); f.setAttribute('method', 'POST'); f.setAttribute('target', 'ioupload' + id ); f.setAttribute(Y.UA.ie && !ie8 ? 'encoding' : 'enctype', 'multipart/form-data'); } /** * @description Sets the appropriate attributes and values to the HTML * form, in preparation of a file upload transaction. * @method _resetAttrs * @private * @static * @param {object} f HTML form object. * @param {object} a Object of original attributes. * @return {void} */ function _resetAttrs(f, a){ var p; for (p in a) { if (a.hasOwnProperty(a, p)) { if (a[p]) { f.setAttribute(p, f[p]); } else { f.removeAttribute(p); } } } } /** * @description Creates the iframe transported used in file upload * transactions, and binds the response event handler. * * @method _create * @private * @static * @param {object} o Transaction object generated by _create(). * @param {object} c Configuration object passed to YUI.io(). * @return {void} */ function _create(o, c) { var i = Y.Node.create('