From c9d444250fbb83f30dd6141429d0716167c7663f Mon Sep 17 00:00:00 2001 From: djmaze Date: Mon, 27 Jul 2020 16:58:04 +0200 Subject: [PATCH] Strip webpack and iframe support from Jua.js (only use xmlhttprequest) --- README.md | 8 +- vendors/jua/jua.js | 2063 +++++++++++++++++----------------------- vendors/jua/jua.min.js | 2 +- 3 files changed, 872 insertions(+), 1201 deletions(-) diff --git a/README.md b/README.md index 6961cfaa2..7a5a196ae 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Things might work in Edge 15-18, Firefox 47-62 and Chrome 54-68 due to one polyf |admin.js |2.130.942 |1.359.501 | | |app.js |4.184.455 |3.127.807 | | |boot.js | 671.522 | 120.319 | | -|libs.js | 647.614 | 511.296 | | +|libs.js | 647.614 | 508.324 | | |polyfills.js | 325.834 | 0 | | |TOTAL js |7.960.367 |5.119.409 | | @@ -70,11 +70,11 @@ Things might work in Edge 15-18, Firefox 47-62 and Chrome 54-68 due to one polyf |admin.js | 252.147 | 177.094 | | |app.js | 511.202 | 409.778 | | |boot.js | 66.007 | 14.697 | | -|libs.js | 572.545 | 468.224 | | +|libs.js | 572.545 | 465.247 | | |polyfills.js | 32.452 | 0 | | -|TOTAL js/min |1.434.353 |1.069.793 |364.560 | +|TOTAL js/min |1.434.353 |1.066.816 |367.537 | -364.560 bytes is not much, but it feels faster. +367.537 bytes is not much, but it feels faster. ### PHP73 branch diff --git a/vendors/jua/jua.js b/vendors/jua/jua.js index 15f8a9e0e..8fa19e381 100644 --- a/vendors/jua/jua.js +++ b/vendors/jua/jua.js @@ -1,1022 +1,788 @@ /* RainLoop Webmail (c) RainLoop Team | MIT */ -(function(){function a(a){function l(){if(g&&d{ + 'use strict'; -/******/ // The require function -/******/ function __webpack_require__(moduleId) { + var + Globals = {}, + Utils = {}, + $ = jQuery; -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; + Globals.iDefLimit = 20; -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; + /** + * @param {*} mValue + * @return {boolean} + */ + Utils.isUndefined = function (mValue) + { + return 'undefined' === typeof mValue; + }; -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - (function () { - 'use strict'; - __webpack_require__(1).Jua = __webpack_require__(7); - }()); - -/***/ }, -/* 1 */ -/***/ function(module, exports, __webpack_require__) { - - module.exports = window; - -/***/ }, -/* 2 */ -/***/ function(module, exports, __webpack_require__) { - - - (function () { - - 'use strict'; - - var Globals = {}; - - Globals.iDefLimit = 20; - - module.exports = Globals; - - }()); - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - module.exports = jQuery; - -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { - - - (function () { - - 'use strict'; - - var - Utils = {}, - - window = __webpack_require__(1), - $ = __webpack_require__(3), - - Globals = __webpack_require__(2) - ; - - /** - * @param {*} mValue - * @return {boolean} - */ - Utils.isUndefined = function (mValue) + /** + * @param {Object} mObjectFirst + * @param {Object=} mObjectSecond + * @return {Object} + */ + Utils.extend = function (mObjectFirst, mObjectSecond) + { + if (mObjectSecond) { - return 'undefined' === typeof mValue; - }; - - /** - * @param {Object} mObjectFirst - * @param {Object=} mObjectSecond - * @return {Object} - */ - Utils.extend = function (mObjectFirst, mObjectSecond) - { - if (mObjectSecond) + for (var sProp in mObjectSecond) { - for (var sProp in mObjectSecond) + if (mObjectSecond.hasOwnProperty(sProp)) { - if (mObjectSecond.hasOwnProperty(sProp)) - { - mObjectFirst[sProp] = mObjectSecond[sProp]; - } + mObjectFirst[sProp] = mObjectSecond[sProp]; } } + } - return mObjectFirst; - }; + return mObjectFirst; + }; - /** - * @param {*} oParent - * @param {*} oDescendant - * - * @return {boolean} - */ - Utils.contains = function (oParent, oDescendant) + /** + * @param {*} oParent + * @param {*} oDescendant + * + * @return {boolean} + */ + Utils.contains = function (oParent, oDescendant) + { + var bResult = false; + if (oParent && oDescendant) { - var bResult = false; - if (oParent && oDescendant) + if (oParent === oDescendant) { - if (oParent === oDescendant) - { - bResult = true; - } - else if (oParent.contains) - { - bResult = oParent.contains(oDescendant); - } - else - { - /*jshint bitwise: false*/ - bResult = oDescendant.compareDocumentPosition ? - !!(oDescendant.compareDocumentPosition(oParent) & 8) : false; - /*jshint bitwise: true*/ - } + bResult = true; } - - return bResult; - }; - - Utils.mainClearTimeout = function(iTimer) - { - if (0 < iTimer) + else if (oParent.contains) { - clearTimeout(iTimer); - } - - iTimer = 0; - }; - - /** - * @param {Event} oEvent - * @return {?Event} - */ - Utils.getEvent = function(oEvent) - { - oEvent = (oEvent && (oEvent.originalEvent ? - oEvent.originalEvent : oEvent)) || window.event; - - return oEvent.dataTransfer ? oEvent : null; - }; - - /** - * @param {Object} oValues - * @param {string} sKey - * @param {?} mDefault - * @return {?} - */ - Utils.getValue = function (oValues, sKey, mDefault) - { - return (!oValues || !sKey || Utils.isUndefined(oValues[sKey])) ? mDefault : oValues[sKey]; - }; - - /** - * @param {Object} oOwner - * @param {string} sPublicName - * @param {*} mObject - */ - Utils.setValue = function(oOwner, sPublicName, mObject) - { - oOwner[sPublicName] = mObject; - }; - - /** - * @param {*} aData - * @return {boolean} - */ - Utils.isNonEmptyArray = function (aData) - { - return aData && aData.length && 0 < aData.length ? true : false; - }; - - /** - * @param {*} mValue - * @return {number} - */ - Utils.pInt = function (mValue) - { - return parseInt(mValue || 0, 10); - }; - - /** - * @param {Function} fFunction - * @param {Object=} oScope - * @return {Function} - */ - Utils.scopeBind = function (fFunction, oScope) - { - return function () { - return fFunction.apply(Utils.isUndefined(oScope) ? null : oScope, - Array.prototype.slice.call(arguments)); - }; - }; - - /** - * @param {number=} iLen - * @return {string} - */ - Utils.fakeMd5 = function (iLen) - { - var - sResult = '', - sLine = '0123456789abcdefghijklmnopqrstuvwxyz' - ; - - iLen = Utils.isUndefined(iLen) ? 32 : Utils.pInt(iLen); - - while (sResult.length < iLen) - { - sResult += sLine.substr(window.Math.round(window.Math.random() * sLine.length), 1); - } - - return sResult; - }; - - /** - * @return {string} - */ - Utils.getNewUid = function () - { - return 'jua-uid-' + Utils.fakeMd5(16) + '-' + (new window.Date()).getTime().toString(); - }; - - /** - * @param {*} oFile - * @return {Object} - */ - Utils.getDataFromFile = function (oFile) - { - var - sFileName = Utils.isUndefined(oFile.fileName) ? (Utils.isUndefined(oFile.name) ? null : oFile.name) : oFile.fileName, - iSize = Utils.isUndefined(oFile.fileSize) ? (Utils.isUndefined(oFile.size) ? null : oFile.size) : oFile.fileSize, - sType = Utils.isUndefined(oFile.type) ? null : oFile.type - ; - - if (sFileName.charAt(0) === '/') - { - sFileName = sFileName.substr(1); - } - - if ('' === sType && 0 === iSize) - { - return null; // Folder - } - - return { - 'FileName': sFileName, - 'Size': iSize, - 'Type': sType, - 'Folder': '', - 'File' : oFile - }; - }; - - /** - * @param {*} aItems - * @param {Function} fFileCallback - * @param {number=} iLimit = 20 - * @param {Function=} fLimitCallback - */ - Utils.getDataFromFiles = function (aItems, fFileCallback, iLimit, fLimitCallback) - { - var - iInputLimit = 0, - iLen = 0, - iIndex = 0, - oItem = null, - oFile = null, - bUseLimit = false, - bCallLimit = false - ; - - iLimit = Utils.isUndefined(iLimit) ? Globals.iDefLimit : Utils.pInt(iLimit); - iInputLimit = iLimit; - bUseLimit = 0 < iLimit; - - aItems = aItems && 0 < aItems.length ? aItems : null; - if (aItems) - { - for (iIndex = 0, iLen = aItems.length; iIndex < iLen; iIndex++) - { - oItem = aItems[iIndex]; - if (oItem) - { - if (!bUseLimit || 0 <= --iLimit) - { - oFile = Utils.getDataFromFile(oItem); - if (oFile) - { - fFileCallback(oFile); - } - } - else if (bUseLimit && !bCallLimit) - { - if (0 > iLimit && fLimitCallback) - { - bCallLimit = true; - fLimitCallback(iInputLimit); - } - } - } - } - } - }; - - /** - * @param {*} oInput - * @param {Function} fFileCallback - * @param {number=} iLimit = 20 - * @param {Function=} fLimitCallback - */ - Utils.getDataFromInput = function (oInput, fFileCallback, iLimit, fLimitCallback) - { - var aFiles = oInput && oInput.files && 0 < oInput.files.length ? oInput.files : null; - if (aFiles) - { - Utils.getDataFromFiles(aFiles, fFileCallback, iLimit, fLimitCallback); + bResult = oParent.contains(oDescendant); } else { - fFileCallback({ - 'FileName': oInput.value.split('\\').pop().split('/').pop(), - 'Size': null, - 'Type': null, - 'Folder': '', - 'File' : null - }); + /*jshint bitwise: false*/ + bResult = oDescendant.compareDocumentPosition ? + !!(oDescendant.compareDocumentPosition(oParent) & 8) : false; + /*jshint bitwise: true*/ } - }; - - Utils.eventContainsFiles = function (oEvent) - { - var bResult = false; - if (oEvent && oEvent.dataTransfer && oEvent.dataTransfer.types && oEvent.dataTransfer.types.length) - { - var - iIindex = 0, - iLen = oEvent.dataTransfer.types.length - ; - - for (; iIindex < iLen; iIindex++) - { - if (oEvent.dataTransfer.types[iIindex].toLowerCase() === 'files') - { - bResult = true; - break; - } - } - } - - return bResult; - }; - - /** - * @param {Event} oEvent - * @param {Function} fFileCallback - * @param {number=} iLimit = 20 - * @param {Function=} fLimitCallback - */ - Utils.getDataFromDragEvent = function (oEvent, fFileCallback, iLimit, fLimitCallback) - { - var aFiles = null; - - oEvent = Utils.getEvent(oEvent); - if (oEvent && Utils.eventContainsFiles(oEvent)) - { - aFiles = (Utils.getValue(oEvent, 'files', null) || (oEvent.dataTransfer ? - Utils.getValue(oEvent.dataTransfer, 'files', null) : null)); - - if (aFiles && 0 < aFiles.length) - { - Utils.getDataFromFiles(aFiles, fFileCallback, iLimit, fLimitCallback); - } - } - }; - - Utils.createNextLabel = function () - { - return $('').css({ - 'opacity': 0 - }); - }; - - Utils.createNextInput = function () - { - return $(''); - }; - - /** - * @param {string=} sName - * @param {boolean=} bMultiple = true - * @return {?Object} - */ - Utils.getNewInput = function (sName, bMultiple) - { - sName = Utils.isUndefined(sName) ? '' : sName.toString(); - - var oLocal = Utils.createNextInput(); - if (0 < sName.length) - { - oLocal.attr('name', sName); - } - - if (Utils.isUndefined(bMultiple) ? true : bMultiple) - { - oLocal.prop('multiple', true); - } - - return oLocal; - }; - - /** - * @param {?} mStringOrFunction - * @param {Array=} aFunctionParams - * @return {string} - */ - Utils.getStringOrCallFunction = function (mStringOrFunction, aFunctionParams) - { - return $.isFunction(mStringOrFunction) ? - mStringOrFunction.apply(null, $.isArray(aFunctionParams) ? aFunctionParams : []).toString() : - mStringOrFunction.toString(); - }; - - module.exports = Utils; - - }()); - -/***/ }, -/* 5 */ -/***/ function(module, exports, __webpack_require__) { - - - (function () { - - 'use strict'; - - var - $ = __webpack_require__(3), - - Globals = __webpack_require__(2), - Utils = __webpack_require__(4) - ; - - /** - * @constructor - * @param {Jua} oJua - * @param {Object} oOptions - */ - function AjaxDriver(oJua, oOptions) - { - this.oXhrs = {}; - this.oUids = {}; - this.oJua = oJua; - this.oOptions = oOptions; } - /** - * @type {Object} - */ - AjaxDriver.prototype.oXhrs = {}; + return bResult; + }; - /** - * @type {Object} - */ - AjaxDriver.prototype.oUids = {}; - - /** - * @type {?Jua} - */ - AjaxDriver.prototype.oJua = null; - - /** - * @type {Object} - */ - AjaxDriver.prototype.oOptions = {}; - - /** - * @return {boolean} - */ - AjaxDriver.prototype.isDragAndDropSupported = function () + Utils.mainClearTimeout = function(iTimer) + { + if (0 < iTimer) { - return true; + clearTimeout(iTimer); + } + + iTimer = 0; + }; + + /** + * @param {Event} oEvent + * @return {?Event} + */ + Utils.getEvent = function(oEvent) + { + oEvent = (oEvent && (oEvent.originalEvent ? + oEvent.originalEvent : oEvent)) || window.event; + + return oEvent.dataTransfer ? oEvent : null; + }; + + /** + * @param {Object} oValues + * @param {string} sKey + * @param {?} mDefault + * @return {?} + */ + Utils.getValue = function (oValues, sKey, mDefault) + { + return (!oValues || !sKey || Utils.isUndefined(oValues[sKey])) ? mDefault : oValues[sKey]; + }; + + /** + * @param {Object} oOwner + * @param {string} sPublicName + * @param {*} mObject + */ + Utils.setValue = function(oOwner, sPublicName, mObject) + { + oOwner[sPublicName] = mObject; + }; + + /** + * @param {*} aData + * @return {boolean} + */ + Utils.isNonEmptyArray = function (aData) + { + return aData && aData.length && 0 < aData.length ? true : false; + }; + + /** + * @param {*} mValue + * @return {number} + */ + Utils.pInt = function (mValue) + { + return parseInt(mValue || 0, 10); + }; + + /** + * @param {Function} fFunction + * @param {Object=} oScope + * @return {Function} + */ + Utils.scopeBind = function (fFunction, oScope) + { + return function () { + return fFunction.apply(Utils.isUndefined(oScope) ? null : oScope, + Array.prototype.slice.call(arguments)); }; + }; - /** - * @param {string} sUid - */ - AjaxDriver.prototype.regTaskUid = function (sUid) + /** + * @param {number=} iLen + * @return {string} + */ + Utils.fakeMd5 = function (iLen) + { + var + sResult = '', + sLine = '0123456789abcdefghijklmnopqrstuvwxyz' + ; + + iLen = Utils.isUndefined(iLen) ? 32 : Utils.pInt(iLen); + + while (sResult.length < iLen) { - this.oUids[sUid] = true; + sResult += sLine.substr(window.Math.round(window.Math.random() * sLine.length), 1); + } + + return sResult; + }; + + /** + * @return {string} + */ + Utils.getNewUid = function () + { + return 'jua-uid-' + Utils.fakeMd5(16) + '-' + (new window.Date()).getTime().toString(); + }; + + /** + * @param {*} oFile + * @return {Object} + */ + Utils.getDataFromFile = function (oFile) + { + var + sFileName = Utils.isUndefined(oFile.fileName) ? (Utils.isUndefined(oFile.name) ? null : oFile.name) : oFile.fileName, + iSize = Utils.isUndefined(oFile.fileSize) ? (Utils.isUndefined(oFile.size) ? null : oFile.size) : oFile.fileSize, + sType = Utils.isUndefined(oFile.type) ? null : oFile.type + ; + + if (sFileName.charAt(0) === '/') + { + sFileName = sFileName.substr(1); + } + + if ('' === sType && 0 === iSize) + { + return null; // Folder + } + + return { + 'FileName': sFileName, + 'Size': iSize, + 'Type': sType, + 'Folder': '', + 'File' : oFile }; + }; - /** - * @param {string} sUid - * @param {?} oFileInfo - * @param {Function} fCallback - */ - AjaxDriver.prototype.uploadTask = function (sUid, oFileInfo, fCallback) + /** + * @param {*} aItems + * @param {Function} fFileCallback + * @param {number=} iLimit = 20 + * @param {Function=} fLimitCallback + */ + Utils.getDataFromFiles = function (aItems, fFileCallback, iLimit, fLimitCallback) + { + var + iInputLimit = 0, + iLen = 0, + iIndex = 0, + oItem = null, + oFile = null, + bUseLimit = false, + bCallLimit = false + ; + + iLimit = Utils.isUndefined(iLimit) ? Globals.iDefLimit : Utils.pInt(iLimit); + iInputLimit = iLimit; + bUseLimit = 0 < iLimit; + + aItems = aItems && 0 < aItems.length ? aItems : null; + if (aItems) { - if (false === this.oUids[sUid] || !oFileInfo || !oFileInfo['File']) + for (iIndex = 0, iLen = aItems.length; iIndex < iLen; iIndex++) { - fCallback(null, sUid); - return false; - } - - try - { - var - self = this, - oXhr = new XMLHttpRequest(), - oFormData = new FormData(), - sAction = Utils.getValue(this.oOptions, 'action', ''), - aHidden = Utils.getValue(this.oOptions, 'hidden', {}), - fStartFunction = this.oJua.getEvent('onStart'), - fCompleteFunction = this.oJua.getEvent('onComplete'), - fProgressFunction = this.oJua.getEvent('onProgress') - ; - - oXhr.open('POST', sAction, true); - - if (fProgressFunction && oXhr.upload) + oItem = aItems[iIndex]; + if (oItem) { - oXhr.upload.onprogress = function (oEvent) { - if (oEvent && oEvent.lengthComputable && !Utils.isUndefined(oEvent.loaded) && !Utils.isUndefined(oEvent.total)) - { - fProgressFunction(sUid, oEvent.loaded, oEvent.total); - } - }; - } - - oXhr.onreadystatechange = function () { - if (4 === oXhr.readyState && 200 === oXhr.status) + if (!bUseLimit || 0 <= --iLimit) { - if (fCompleteFunction) + oFile = Utils.getDataFromFile(oItem); + if (oFile) { - var - bResult = false, - oResult = null - ; - - try - { - oResult = $.parseJSON(oXhr.responseText); - bResult = true; - } - catch (oException) - { - oResult = null; - } - - fCompleteFunction(sUid, bResult, oResult); - } - - if (!Utils.isUndefined(self.oXhrs[sUid])) - { - self.oXhrs[sUid] = null; - } - - fCallback(null, sUid); - } - else - { - if (4 === oXhr.readyState) - { - fCompleteFunction(sUid, false, null); - fCallback(null, sUid); + fFileCallback(oFile); + } + } + else if (bUseLimit && !bCallLimit) + { + if (0 > iLimit && fLimitCallback) + { + bCallLimit = true; + fLimitCallback(iInputLimit); } } - }; - - if (fStartFunction) - { - fStartFunction(sUid); } - - oFormData.append('jua-post-type', 'ajax'); - oFormData.append(Utils.getValue(this.oOptions, 'name', 'juaFile'), oFileInfo['File']); - $.each(aHidden, function (sKey, sValue) { - oFormData.append(sKey, Utils.getStringOrCallFunction(sValue, [oFileInfo])); - }); - - oXhr.send(oFormData); - - this.oXhrs[sUid] = oXhr; - return true; } - catch (oError) + } + }; + + /** + * @param {*} oInput + * @param {Function} fFileCallback + * @param {number=} iLimit = 20 + * @param {Function=} fLimitCallback + */ + Utils.getDataFromInput = function (oInput, fFileCallback, iLimit, fLimitCallback) + { + var aFiles = oInput && oInput.files && 0 < oInput.files.length ? oInput.files : null; + if (aFiles) + { + Utils.getDataFromFiles(aFiles, fFileCallback, iLimit, fLimitCallback); + } + else + { + fFileCallback({ + 'FileName': oInput.value.split('\\').pop().split('/').pop(), + 'Size': null, + 'Type': null, + 'Folder': '', + 'File' : null + }); + } + }; + + Utils.eventContainsFiles = function (oEvent) + { + var bResult = false; + if (oEvent && oEvent.dataTransfer && oEvent.dataTransfer.types && oEvent.dataTransfer.types.length) + { + var + iIindex = 0, + iLen = oEvent.dataTransfer.types.length + ; + + for (; iIindex < iLen; iIindex++) { + if (oEvent.dataTransfer.types[iIindex].toLowerCase() === 'files') + { + bResult = true; + break; + } } + } + return bResult; + }; + + /** + * @param {Event} oEvent + * @param {Function} fFileCallback + * @param {number=} iLimit = 20 + * @param {Function=} fLimitCallback + */ + Utils.getDataFromDragEvent = function (oEvent, fFileCallback, iLimit, fLimitCallback) + { + var aFiles = null; + + oEvent = Utils.getEvent(oEvent); + if (oEvent && Utils.eventContainsFiles(oEvent)) + { + aFiles = (Utils.getValue(oEvent, 'files', null) || (oEvent.dataTransfer ? + Utils.getValue(oEvent.dataTransfer, 'files', null) : null)); + + if (aFiles && 0 < aFiles.length) + { + Utils.getDataFromFiles(aFiles, fFileCallback, iLimit, fLimitCallback); + } + } + }; + + Utils.createNextLabel = function () + { + return $('').css({ + 'opacity': 0 + }); + }; + + Utils.createNextInput = function () + { + return $(''); + }; + + /** + * @param {string=} sName + * @param {boolean=} bMultiple = true + * @return {?Object} + */ + Utils.getNewInput = function (sName, bMultiple) + { + sName = Utils.isUndefined(sName) ? '' : sName.toString(); + + var oLocal = Utils.createNextInput(); + if (0 < sName.length) + { + oLocal.attr('name', sName); + } + + if (Utils.isUndefined(bMultiple) ? true : bMultiple) + { + oLocal.prop('multiple', true); + } + + return oLocal; + }; + + /** + * @param {?} mStringOrFunction + * @param {Array=} aFunctionParams + * @return {string} + */ + Utils.getStringOrCallFunction = function (mStringOrFunction, aFunctionParams) + { + return $.isFunction(mStringOrFunction) ? + mStringOrFunction.apply(null, $.isArray(aFunctionParams) ? aFunctionParams : []).toString() : + mStringOrFunction.toString(); + }; + + + /** + * @constructor + * @param {Jua} oJua + * @param {Object} oOptions + */ + function AjaxDriver(oJua, oOptions) + { + this.oXhrs = {}; + this.oUids = {}; + this.oJua = oJua; + this.oOptions = oOptions; + } + + /** + * @type {Object} + */ + AjaxDriver.prototype.oXhrs = {}; + + /** + * @type {Object} + */ + AjaxDriver.prototype.oUids = {}; + + /** + * @type {?Jua} + */ + AjaxDriver.prototype.oJua = null; + + /** + * @type {Object} + */ + AjaxDriver.prototype.oOptions = {}; + + /** + * @return {boolean} + */ + AjaxDriver.prototype.isDragAndDropSupported = () => true; + + /** + * @param {string} sUid + */ + AjaxDriver.prototype.regTaskUid = function (sUid) + { + this.oUids[sUid] = true; + }; + + /** + * @param {string} sUid + * @param {?} oFileInfo + * @param {Function} fCallback + */ + AjaxDriver.prototype.uploadTask = function (sUid, oFileInfo, fCallback) + { + if (false === this.oUids[sUid] || !oFileInfo || !oFileInfo['File']) + { fCallback(null, sUid); return false; - }; + } - AjaxDriver.prototype.generateNewInput = function (oClickElement) + try { var self = this, - oLabel = null, - oInput = null - ; - - if (oClickElement) - { - oInput = Utils.getNewInput('', !Utils.getValue(this.oOptions, 'disableMultiple', false)); - oLabel = Utils.createNextLabel(); - oLabel.append(oInput); - - $(oClickElement).append(oLabel); - - oInput - .on('click', function () { - var fOn = self.oJua.getEvent('onDialog'); - if (fOn) - { - fOn(); - } - }) - .on('change', function () { - Utils.getDataFromInput(this, function (oFile) { - self.oJua.addNewFile(oFile); - self.generateNewInput(oClickElement); - - setTimeout(function () { - oLabel.remove(); - }, 10); - }, - Utils.getValue(self.oOptions, 'multipleSizeLimit', Globals.iDefLimit), - self.oJua.getEvent('onLimitReached') - ); - }) - ; - } - }; - - AjaxDriver.prototype.cancel = function (sUid) - { - this.oUids[sUid] = false; - if (this.oXhrs[sUid]) - { - try - { - if (this.oXhrs[sUid].abort) - { - this.oXhrs[sUid].abort(); - } - } - catch (oError) - { - } - - this.oXhrs[sUid] = null; - } - }; - - module.exports = AjaxDriver; - - }()); - - -/***/ }, -/* 6 */ -/***/ function(module, exports, __webpack_require__) { - - - (function () { - - 'use strict'; - - var - window = __webpack_require__(1), - $ = __webpack_require__(3), - - Globals = __webpack_require__(2), - Utils = __webpack_require__(4) - ; - - /** - * @constructor - * @param {Jua} oJua - * @param {Object} oOptions - */ - function IframeDriver(oJua, oOptions) - { - this.oUids = {}; - this.oForms = {}; - this.oJua = oJua; - this.oOptions = oOptions; - } - - /** - * @type {Object} - */ - IframeDriver.prototype.oUids = {}; - - /** - * @type {Object} - */ - IframeDriver.prototype.oForms = {}; - - /** - * @type {?Jua} - */ - IframeDriver.prototype.oJua = null; - - /** - * @type {Object} - */ - IframeDriver.prototype.oOptions = {}; - - /** - * @return {boolean} - */ - IframeDriver.prototype.isDragAndDropSupported = function () - { - return false; - }; - - /** - * @param {string} sUid - */ - IframeDriver.prototype.regTaskUid = function (sUid) - { - this.oUids[sUid] = true; - }; - - /** - * @param {string} sUid - * @param {?} oFileInfo - * @param {Function} fCallback - */ - IframeDriver.prototype.uploadTask = function (sUid, oFileInfo, fCallback) - { - if (false === this.oUids[sUid]) - { - fCallback(null, sUid); - return false; - } - - var - oForm = this.oForms[sUid], + oXhr = new XMLHttpRequest(), + oFormData = new FormData(), + sAction = Utils.getValue(this.oOptions, 'action', ''), aHidden = Utils.getValue(this.oOptions, 'hidden', {}), fStartFunction = this.oJua.getEvent('onStart'), - fCompleteFunction = this.oJua.getEvent('onComplete') + fCompleteFunction = this.oJua.getEvent('onComplete'), + fProgressFunction = this.oJua.getEvent('onProgress') ; - if (oForm) + oXhr.open('POST', sAction, true); + + if (fProgressFunction && oXhr.upload) { - oForm.append($('').attr('name', 'jua-post-type').val('iframe')); - $.each(aHidden, function (sKey, sValue) { - oForm.append($('').attr('name', sKey).val(Utils.getStringOrCallFunction(sValue, [oFileInfo]))); - }); + oXhr.upload.onprogress = function (oEvent) { + if (oEvent && oEvent.lengthComputable && !Utils.isUndefined(oEvent.loaded) && !Utils.isUndefined(oEvent.total)) + { + fProgressFunction(sUid, oEvent.loaded, oEvent.total); + } + }; + } - oForm.trigger('submit'); - if (fStartFunction) + oXhr.onreadystatechange = function () { + if (4 === oXhr.readyState && 200 === oXhr.status) { - fStartFunction(sUid); - } - - oForm.find('iframe').on('load', function () { - - var - bResult = false, - oIframeDoc = null, - oResult = {} - ; - if (fCompleteFunction) { + var + bResult = false, + oResult = null + ; + try { - oIframeDoc = this.contentDocument ? this.contentDocument: this.contentWindow.document; - oResult = $.parseJSON(oIframeDoc.body.innerHTML); + oResult = $.parseJSON(oXhr.responseText); bResult = true; } - catch (oErr) + catch (oException) { - oResult = {}; + oResult = null; } fCompleteFunction(sUid, bResult, oResult); } + if (!Utils.isUndefined(self.oXhrs[sUid])) + { + self.oXhrs[sUid] = null; + } + fCallback(null, sUid); - - window.setTimeout(function () { - oForm.remove(); - }, 100); - }); - } - else - { - fCallback(null, sUid); - } - - return true; - }; - - IframeDriver.prototype.generateNewInput = function (oClickElement) - { - var - self = this, - sUid = '', - oInput = null, - oIframe = null, - sAction = Utils.getValue(this.oOptions, 'action', ''), - oForm = null - ; - - if (oClickElement) - { - sUid = Utils.getNewUid(); - - oInput = Utils.getNewInput(Utils.getValue(this.oOptions, 'name', 'juaFile'), !Utils.getValue(this.oOptions, 'disableMultiple', false)); - - oForm = $('
'); - - oIframe = $('