(function(){function a(a){function l(){if(g&&d iLimit && fLimitCallback) { bCallLimit = true; fLimitCallback(iInputLimit); } } }); } else if (bAllowFolderDragAndDrop && oItem['isDirectory'] && oItem['createReader']) { var oDirReader = oItem['createReader'](), iIndex = 0, iLen = 0 ; if (oDirReader && oDirReader['readEntries']) { oDirReader['readEntries'](function (aEntries) { if (aEntries && isNonEmptyArray(aEntries)) { for (iIndex = 0, iLen = aEntries.length; iIndex < iLen; iIndex++) { fTraverseFileTree(aEntries[iIndex], sPath + oItem['name'] + '/', fCallback, fLimitCallbackProxy); } } }); } } } } ; bAllowFolderDragAndDrop = isUndefined(bAllowFolderDragAndDrop) ? true : !!bAllowFolderDragAndDrop; bEntry = isUndefined(bEntry) ? false : !!bEntry; iLimit = isUndefined(iLimit) ? Jua.iDefLimit : 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 (bEntry) { if ('file' === oItem['kind'] && oItem['webkitGetAsEntry']) { oEntry = oItem['webkitGetAsEntry'](); if (oEntry) { fTraverseFileTree(oEntry, '', fFileCallback, fLimitCallback); } } } else { if (!bUseLimit || 0 <= --iLimit) { fFileCallback(getDataFromFile(oItem)); } else if (bUseLimit && !bCallLimit) { if (0 > iLimit && fLimitCallback) { bCallLimit = true; fLimitCallback(iInputLimit); } } } } } } } /** * @param {*} oInput * @param {Function} fFileCallback * @param {number=} iLimit = 20 * @param {Function=} fLimitCallback */ function getDataFromInput(oInput, fFileCallback, iLimit, fLimitCallback) { var aFiles = oInput && oInput.files && 0 < oInput.files.length ? oInput.files : null; if (aFiles) { getDataFromFiles(aFiles, fFileCallback, false, false, iLimit, fLimitCallback); } else { fFileCallback({ 'FileName': oInput.value.split('\\').pop().split('/').pop(), 'Size': null, 'Type': null, 'Folder': '', 'File' : null }); } } function eventContainsFiles(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 * @param {boolean=} bAllowFolderDragAndDrop = true */ function getDataFromDragEvent(oEvent, fFileCallback, iLimit, fLimitCallback, bAllowFolderDragAndDrop) { var aItems = null, aFiles = null ; oEvent = getEvent(oEvent); if (oEvent) { aItems = (oEvent.dataTransfer ? getValue(oEvent.dataTransfer, 'items', null) : null) || getValue(oEvent, 'items', null); if (aItems && 0 < aItems.length && aItems[0] && aItems[0]['webkitGetAsEntry']) { getDataFromFiles(aItems, fFileCallback, true, bAllowFolderDragAndDrop, iLimit, fLimitCallback); } else if (eventContainsFiles(oEvent)) { aFiles = (getValue(oEvent, 'files', null) || (oEvent.dataTransfer ? getValue(oEvent.dataTransfer, 'files', null) : null)); if (aFiles && 0 < aFiles.length) { getDataFromFiles(aFiles, fFileCallback, false, false, iLimit, fLimitCallback); } } } } function createNextLabel() { return $('').css({ 'opacity': 0 }); } function createNextInput() { return $(''); } /** * @param {string=} sName * @param {boolean=} bMultiple = true * @return {?Object} */ function getNewInput(sName, bMultiple) { sName = isUndefined(sName) ? '' : sName.toString(); var oLocal = createNextInput(); if (0 < sName.length) { oLocal.attr('name', sName); } if (isUndefined(bMultiple) ? true : bMultiple) { oLocal.prop('multiple', true); } return oLocal; } /** * @param {?} mStringOrFunction * @param {Array=} aFunctionParams * @return {string} */ function getStringOrCallFunction(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 = function () { return 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; } try { var self = this, oXhr = new XMLHttpRequest(), oFormData = new FormData(), sAction = getValue(this.oOptions, 'action', ''), aHidden = 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) { oXhr.upload.onprogress = function (oEvent) { if (oEvent && oEvent.lengthComputable && !isUndefined(oEvent.loaded) && !isUndefined(oEvent.total)) { fProgressFunction(sUid, oEvent.loaded, oEvent.total); } }; } oXhr.onreadystatechange = function () { if (4 === oXhr.readyState && 200 === oXhr.status) { if (fCompleteFunction) { var bResult = false, oResult = null ; try { oResult = $.parseJSON(oXhr.responseText); bResult = true; } catch (oException) { oResult = null; } fCompleteFunction(sUid, bResult, oResult); } if (!isUndefined(self.oXhrs[sUid])) { self.oXhrs[sUid] = null; } fCallback(null, sUid); } else { if (4 === oXhr.readyState) { fCompleteFunction(sUid, false, null); fCallback(null, sUid); } } }; if (fStartFunction) { fStartFunction(sUid); } oFormData.append('jua-post-type', 'ajax'); oFormData.append(getValue(this.oOptions, 'name', 'juaFile'), oFileInfo['File']); $.each(aHidden, function (sKey, sValue) { oFormData.append(sKey, getStringOrCallFunction(sValue, [oFileInfo])); }); oXhr.send(oFormData); this.oXhrs[sUid] = oXhr; return true; } catch (oError) { } fCallback(null, sUid); return false; }; AjaxDriver.prototype.generateNewInput = function (oClickElement) { var self = this, oLabel = null, oInput = null ; if (oClickElement) { oInput = getNewInput('', !getValue(this.oOptions, 'disableMultiple', false)); oLabel = createNextLabel(); oLabel.append(oInput); $(oClickElement).append(oLabel); oInput .on('click', function () { var fOn = self.oJua.getEvent('onDialog'); if (fOn) { fOn(); } }) .on('change', function () { getDataFromInput(this, function (oFile) { self.oJua.addNewFile(oFile); self.generateNewInput(oClickElement); setTimeout(function () { oLabel.remove(); }, 10); }, getValue(self.oOptions, 'multipleSizeLimit', Jua.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; } }; /** * @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], aHidden = getValue(this.oOptions, 'hidden', {}), fStartFunction = this.oJua.getEvent('onStart'), fCompleteFunction = this.oJua.getEvent('onComplete') ; if (oForm) { oForm.append($('').attr('name', 'jua-post-type').val('iframe')); $.each(aHidden, function (sKey, sValue) { oForm.append($('').attr('name', sKey).val(getStringOrCallFunction(sValue, [oFileInfo]))); }); oForm.trigger('submit'); if (fStartFunction) { fStartFunction(sUid); } oForm.find('iframe').on('load', function (oEvent) { var bResult = false, oIframeDoc = null, oResult = {} ; if (fCompleteFunction) { try { oIframeDoc = this.contentDocument ? this.contentDocument: this.contentWindow.document; oResult = $.parseJSON(oIframeDoc.body.innerHTML); bResult = true; } catch (oErr) { oResult = {}; } fCompleteFunction(sUid, bResult, oResult); } 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 = getValue(this.oOptions, 'action', ''), oForm = null ; if (oClickElement) { sUid = getNewUid(); oInput = getNewInput(getValue(this.oOptions, 'name', 'juaFile'), !getValue(this.oOptions, 'disableMultiple', false)); oForm = $('
'); oIframe = $('