mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Code refactoring
This commit is contained in:
parent
78ce33e77c
commit
2545ce3cd9
17 changed files with 946 additions and 1034 deletions
858
vendors/jua/_/jua.js
vendored
858
vendors/jua/_/jua.js
vendored
|
|
@ -1,435 +1,435 @@
|
|||
(function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d;if(i)return;a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.2"})();(function ($, window, queue) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @param {*} mValue
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isUndefined(mValue)
|
||||
{
|
||||
return 'undefined' === typeof mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} mObjectFirst
|
||||
* @param {Object=} mObjectSecond
|
||||
* @return {Object}
|
||||
*/
|
||||
function extend(mObjectFirst, mObjectSecond)
|
||||
{
|
||||
if (mObjectSecond)
|
||||
{
|
||||
for (var sProp in mObjectSecond)
|
||||
{
|
||||
if (mObjectSecond.hasOwnProperty(sProp))
|
||||
{
|
||||
mObjectFirst[sProp] = mObjectSecond[sProp];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mObjectFirst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} oParent
|
||||
* @param {*} oDescendant
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
function contains(oParent, oDescendant)
|
||||
{
|
||||
var bResult = false;
|
||||
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*/
|
||||
}
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
function mainClearTimeout(iTimer)
|
||||
{
|
||||
if (0 < iTimer)
|
||||
{
|
||||
clearTimeout(iTimer);
|
||||
}
|
||||
|
||||
iTimer = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Event} oEvent
|
||||
* @return {?Event}
|
||||
*/
|
||||
function getEvent(oEvent)
|
||||
{
|
||||
oEvent = (oEvent && (oEvent.originalEvent ?
|
||||
oEvent.originalEvent : oEvent)) || window.event;
|
||||
|
||||
return oEvent.dataTransfer ? oEvent : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} oValues
|
||||
* @param {string} sKey
|
||||
* @param {?} mDefault
|
||||
* @return {?}
|
||||
*/
|
||||
function getValue(oValues, sKey, mDefault)
|
||||
{
|
||||
return (!oValues || !sKey || isUndefined(oValues[sKey])) ? mDefault : oValues[sKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} oOwner
|
||||
* @param {string} sPublicName
|
||||
* @param {*} mObject
|
||||
*/
|
||||
function setValue(oOwner, sPublicName, mObject)
|
||||
{
|
||||
oOwner[sPublicName] = mObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} aData
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isNonEmptyArray(aData)
|
||||
{
|
||||
return aData && aData.length && 0 < aData.length ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} mValue
|
||||
* @return {number}
|
||||
*/
|
||||
function pInt(mValue)
|
||||
{
|
||||
return parseInt(mValue || 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} fFunction
|
||||
* @param {Object=} oScope
|
||||
* @return {Function}
|
||||
*/
|
||||
function scopeBind(fFunction, oScope)
|
||||
{
|
||||
return function () {
|
||||
return fFunction.apply(isUndefined(oScope) ? null : oScope,
|
||||
Array.prototype.slice.call(arguments));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number=} iLen
|
||||
* @return {string}
|
||||
*/
|
||||
function fakeMd5(iLen)
|
||||
{
|
||||
var
|
||||
sResult = '',
|
||||
sLine = '0123456789abcdefghijklmnopqrstuvwxyz'
|
||||
;
|
||||
|
||||
iLen = isUndefined(iLen) ? 32 : pInt(iLen);
|
||||
|
||||
while (sResult.length < iLen)
|
||||
{
|
||||
sResult += sLine.substr(Math.round(Math.random() * sLine.length), 1);
|
||||
}
|
||||
|
||||
return sResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
function getNewUid()
|
||||
{
|
||||
return 'jua-uid-' + fakeMd5(16) + '-' + (new Date()).getTime().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} oFile
|
||||
* @param {string=} sPath
|
||||
* @return {Object}
|
||||
*/
|
||||
function getDataFromFile(oFile, sPath)
|
||||
{
|
||||
var
|
||||
sFileName = isUndefined(oFile.fileName) ? (isUndefined(oFile.name) ? null : oFile.name) : oFile.fileName,
|
||||
iSize = isUndefined(oFile.fileSize) ? (isUndefined(oFile.size) ? null : oFile.size) : oFile.fileSize,
|
||||
sType = isUndefined(oFile.type) ? null : oFile.type
|
||||
;
|
||||
|
||||
return {
|
||||
'FileName': sFileName,
|
||||
'Size': iSize,
|
||||
'Type': sType,
|
||||
'Folder': isUndefined(sPath) ? '' : sPath,
|
||||
'File' : oFile
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} aItems
|
||||
* @param {Function} fFileCallback
|
||||
* @param {boolean=} bEntry = false
|
||||
* @param {boolean=} bAllowFolderDragAndDrop = true
|
||||
* @param {number=} iLimit = 20
|
||||
* @param {Function=} fLimitCallback
|
||||
*/
|
||||
function getDataFromFiles(aItems, fFileCallback, bEntry, bAllowFolderDragAndDrop, iLimit, fLimitCallback)
|
||||
{
|
||||
var
|
||||
iInputLimit = 0,
|
||||
iLen = 0,
|
||||
iIndex = 0,
|
||||
oItem = null,
|
||||
oEntry = null,
|
||||
bUseLimit = false,
|
||||
bCallLimit = false,
|
||||
fTraverseFileTree = function (oItem, sPath, fCallback, fLimitCallbackProxy) {
|
||||
|
||||
if (oItem && !isUndefined(oItem['name']))
|
||||
{
|
||||
sPath = sPath || '';
|
||||
if (oItem['isFile'])
|
||||
{
|
||||
oItem.file(function (oFile) {
|
||||
if (!bUseLimit || 0 <= --iLimit)
|
||||
{
|
||||
fCallback(getDataFromFile(oFile, sPath));
|
||||
}
|
||||
else if (bUseLimit && !bCallLimit)
|
||||
{
|
||||
if (0 > 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 $('<label style="' +
|
||||
'position: absolute; background-color:#fff; right: 0px; top: 0px; left: 0px; bottom: 0px; margin: 0px; padding: 0px; cursor: pointer;' +
|
||||
'"></label>').css({
|
||||
'opacity': 0
|
||||
});
|
||||
}
|
||||
|
||||
function createNextInput()
|
||||
{
|
||||
return $('<input type="file" tabindex="-1" hidefocus="hidefocus" style="position: absolute; left: -9999px;" />');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} mValue
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isUndefined(mValue)
|
||||
{
|
||||
return 'undefined' === typeof mValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} mObjectFirst
|
||||
* @param {Object=} mObjectSecond
|
||||
* @return {Object}
|
||||
*/
|
||||
function extend(mObjectFirst, mObjectSecond)
|
||||
{
|
||||
if (mObjectSecond)
|
||||
{
|
||||
for (var sProp in mObjectSecond)
|
||||
{
|
||||
if (mObjectSecond.hasOwnProperty(sProp))
|
||||
{
|
||||
mObjectFirst[sProp] = mObjectSecond[sProp];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mObjectFirst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} oParent
|
||||
* @param {*} oDescendant
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
function contains(oParent, oDescendant)
|
||||
{
|
||||
var bResult = false;
|
||||
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*/
|
||||
}
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
function mainClearTimeout(iTimer)
|
||||
{
|
||||
if (0 < iTimer)
|
||||
{
|
||||
clearTimeout(iTimer);
|
||||
}
|
||||
|
||||
iTimer = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Event} oEvent
|
||||
* @return {?Event}
|
||||
*/
|
||||
function getEvent(oEvent)
|
||||
{
|
||||
oEvent = (oEvent && (oEvent.originalEvent ?
|
||||
oEvent.originalEvent : oEvent)) || window.event;
|
||||
|
||||
return oEvent.dataTransfer ? oEvent : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} oValues
|
||||
* @param {string} sKey
|
||||
* @param {?} mDefault
|
||||
* @return {?}
|
||||
*/
|
||||
function getValue(oValues, sKey, mDefault)
|
||||
{
|
||||
return (!oValues || !sKey || isUndefined(oValues[sKey])) ? mDefault : oValues[sKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} oOwner
|
||||
* @param {string} sPublicName
|
||||
* @param {*} mObject
|
||||
*/
|
||||
function setValue(oOwner, sPublicName, mObject)
|
||||
{
|
||||
oOwner[sPublicName] = mObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} aData
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isNonEmptyArray(aData)
|
||||
{
|
||||
return aData && aData.length && 0 < aData.length ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} mValue
|
||||
* @return {number}
|
||||
*/
|
||||
function pInt(mValue)
|
||||
{
|
||||
return parseInt(mValue || 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} fFunction
|
||||
* @param {Object=} oScope
|
||||
* @return {Function}
|
||||
*/
|
||||
function scopeBind(fFunction, oScope)
|
||||
{
|
||||
return function () {
|
||||
return fFunction.apply(isUndefined(oScope) ? null : oScope,
|
||||
Array.prototype.slice.call(arguments));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number=} iLen
|
||||
* @return {string}
|
||||
*/
|
||||
function fakeMd5(iLen)
|
||||
{
|
||||
var
|
||||
sResult = '',
|
||||
sLine = '0123456789abcdefghijklmnopqrstuvwxyz'
|
||||
;
|
||||
|
||||
iLen = isUndefined(iLen) ? 32 : pInt(iLen);
|
||||
|
||||
while (sResult.length < iLen)
|
||||
{
|
||||
sResult += sLine.substr(Math.round(Math.random() * sLine.length), 1);
|
||||
}
|
||||
|
||||
return sResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
function getNewUid()
|
||||
{
|
||||
return 'jua-uid-' + fakeMd5(16) + '-' + (new Date()).getTime().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} oFile
|
||||
* @param {string=} sPath
|
||||
* @return {Object}
|
||||
*/
|
||||
function getDataFromFile(oFile, sPath)
|
||||
{
|
||||
var
|
||||
sFileName = isUndefined(oFile.fileName) ? (isUndefined(oFile.name) ? null : oFile.name) : oFile.fileName,
|
||||
iSize = isUndefined(oFile.fileSize) ? (isUndefined(oFile.size) ? null : oFile.size) : oFile.fileSize,
|
||||
sType = isUndefined(oFile.type) ? null : oFile.type
|
||||
;
|
||||
|
||||
return {
|
||||
'FileName': sFileName,
|
||||
'Size': iSize,
|
||||
'Type': sType,
|
||||
'Folder': isUndefined(sPath) ? '' : sPath,
|
||||
'File' : oFile
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} aItems
|
||||
* @param {Function} fFileCallback
|
||||
* @param {boolean=} bEntry = false
|
||||
* @param {boolean=} bAllowFolderDragAndDrop = true
|
||||
* @param {number=} iLimit = 20
|
||||
* @param {Function=} fLimitCallback
|
||||
*/
|
||||
function getDataFromFiles(aItems, fFileCallback, bEntry, bAllowFolderDragAndDrop, iLimit, fLimitCallback)
|
||||
{
|
||||
var
|
||||
iInputLimit = 0,
|
||||
iLen = 0,
|
||||
iIndex = 0,
|
||||
oItem = null,
|
||||
oEntry = null,
|
||||
bUseLimit = false,
|
||||
bCallLimit = false,
|
||||
fTraverseFileTree = function (oItem, sPath, fCallback, fLimitCallbackProxy) {
|
||||
|
||||
if (oItem && !isUndefined(oItem['name']))
|
||||
{
|
||||
sPath = sPath || '';
|
||||
if (oItem['isFile'])
|
||||
{
|
||||
oItem.file(function (oFile) {
|
||||
if (!bUseLimit || 0 <= --iLimit)
|
||||
{
|
||||
fCallback(getDataFromFile(oFile, sPath));
|
||||
}
|
||||
else if (bUseLimit && !bCallLimit)
|
||||
{
|
||||
if (0 > 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 $('<label style="' +
|
||||
'position: absolute; background-color:#fff; right: 0px; top: 0px; left: 0px; bottom: 0px; margin: 0px; padding: 0px; cursor: pointer;' +
|
||||
'"></label>').css({
|
||||
'opacity': 0
|
||||
});
|
||||
}
|
||||
|
||||
function createNextInput()
|
||||
{
|
||||
return $('<input type="file" tabindex="-1" hidefocus="hidefocus" style="position: absolute; left: -9999px;" />');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
|
|
|||
2
vendors/jua/jua.min.js
vendored
2
vendors/jua/jua.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue