diff --git a/dev/Common/Enums.js b/dev/Common/Enums.js index dd7a78fa3..5a59b03f1 100644 --- a/dev/Common/Enums.js +++ b/dev/Common/Enums.js @@ -411,10 +411,10 @@ export const Notification = { ClientViewError: 902, InvalidInputArgument: 903, - AjaxFalse: 950, - AjaxAbort: 951, - AjaxParse: 952, - AjaxTimeout: 953, + JsonFalse: 950, + JsonAbort: 951, + JsonParse: 952, +// JsonTimeout: 953, UnknownNotification: 999, UnknownError: 999 diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index a50ff1083..e534915a1 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -87,7 +87,7 @@ export function settingsSaveHelperSimpleFunction(koTrigger, context) { } let __themeTimer = 0, - __themeAjax = null; + __themeJson = null; /** * @param {string} value @@ -98,7 +98,7 @@ export function changeTheme(value, themeTrigger = ()=>{}) { const themeLink = doc.getElementById('app-theme-link'), clearTimer = () => { __themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000); - __themeAjax = null; + __themeJson = null; }; let themeStyle = doc.getElementById('app-theme-style'), @@ -118,13 +118,13 @@ export function changeTheme(value, themeTrigger = ()=>{}) { themeTrigger(SaveSettingsStep.Animate); - if (__themeAjax) { - __themeAjax.abort(); + if (__themeJson) { + __themeJson.abort(); } let init = {}; if (window.AbortController) { - __themeAjax = new AbortController(); - init.signal = __themeAjax.signal; + __themeJson = new AbortController(); + init.signal = __themeJson.signal; } rl.fetchJSON(url, init) .then(data => { diff --git a/dev/Remote/AbstractFetch.js b/dev/Remote/AbstractFetch.js index cc2251a4a..eb6558a14 100644 --- a/dev/Remote/AbstractFetch.js +++ b/dev/Remote/AbstractFetch.js @@ -2,11 +2,11 @@ import { StorageResultType, Notification } from 'Common/Enums'; import { pInt, pString } from 'Common/Utils'; import { serverRequest } from 'Common/Links'; -let iAjaxErrorCount = 0, +let iJsonErrorCount = 0, iTokenErrorCount = 0, bUnload = false; -const getURL = (add = '') => serverRequest('Ajax') + add, +const getURL = (add = '') => serverRequest('Json') + add, updateToken = data => { if (data.UpdateToken) { @@ -28,7 +28,7 @@ checkResponseError = data => { Notification.UnknownError ].includes(err) ) { - ++iAjaxErrorCount; + ++iJsonErrorCount; } if (Notification.InvalidToken === err) { @@ -39,7 +39,7 @@ checkResponseError = data => { rl.logoutReload(); } - if (window.rl && (data.ClearAuth || data.Logout || 7 < iAjaxErrorCount)) { + if (window.rl && (data.ClearAuth || data.Logout || 7 < iJsonErrorCount)) { rl.hash.clear(); if (!data.ClearAuth) { @@ -118,7 +118,7 @@ class AbstractFetchRemote if (StorageResultType.Success === sType && data && !data.Result) { checkResponseError(data); } else if (StorageResultType.Success === sType && data && data.Result) { - iAjaxErrorCount = iTokenErrorCount = 0; + iJsonErrorCount = iTokenErrorCount = 0; } if (fCallback) { @@ -152,7 +152,7 @@ class AbstractFetchRemote }).catch(err => { if (err.name == 'AbortError') { // handle abort() - err = Notification.AjaxAbort; + err = Notification.JsonAbort; } return Promise.reject(err); }); @@ -222,7 +222,7 @@ class AbstractFetchRemote this.abort(action, true); if (!data) { - return Promise.reject(Notification.AjaxParse); + return Promise.reject(Notification.JsonParse); } updateToken(data); @@ -249,13 +249,13 @@ class AbstractFetchRemote if (!data.Result || action !== data.Action) { checkResponseError(data); const err = data ? data.ErrorCode : null; - return Promise.reject(err || Notification.AjaxFalse); + return Promise.reject(err || Notification.JsonFalse); } return data; }).catch(err => { if (err.name == 'AbortError') { // handle abort() - return Promise.reject(Notification.AjaxAbort); + return Promise.reject(Notification.JsonAbort); } return Promise.reject(err); }); diff --git a/plugins/custom-admin-settings-tab/index.php b/plugins/custom-admin-settings-tab/index.php index 78544287d..dc8f6190b 100644 --- a/plugins/custom-admin-settings-tab/index.php +++ b/plugins/custom-admin-settings-tab/index.php @@ -11,7 +11,7 @@ class CustomAdminSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin $this->addJs('js/CustomAdminSettings.js', true); // add js file - $this->addAjaxHook('AjaxAdminGetData', 'AjaxAdminGetData'); + $this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData'); $this->addTemplate('templates/PluginCustomAdminSettingsTab.html', true); } @@ -19,9 +19,9 @@ class CustomAdminSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin /** * @return array */ - public function AjaxAdminGetData() + public function JsonAdminGetData() { - return $this->ajaxResponse(__FUNCTION__, array( + return $this->jsonResponse(__FUNCTION__, array( 'PHP' => phpversion() )); } diff --git a/plugins/custom-admin-settings-tab/js/CustomAdminSettings.js b/plugins/custom-admin-settings-tab/js/CustomAdminSettings.js index 8c67f7c15..ce8ff0e1d 100644 --- a/plugins/custom-admin-settings-tab/js/CustomAdminSettings.js +++ b/plugins/custom-admin-settings-tab/js/CustomAdminSettings.js @@ -31,7 +31,7 @@ self.php(oData.Result.PHP || ''); } - }, 'AjaxAdminGetData'); + }, 'JsonAdminGetData'); }; diff --git a/plugins/custom-settings-tab/index.php b/plugins/custom-settings-tab/index.php index ebdf17738..5918a1ece 100644 --- a/plugins/custom-settings-tab/index.php +++ b/plugins/custom-settings-tab/index.php @@ -11,8 +11,8 @@ class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin $this->addJs('js/CustomUserSettings.js'); // add js file - $this->addAjaxHook('AjaxGetCustomUserData', 'AjaxGetCustomUserData'); - $this->addAjaxHook('AjaxSaveCustomUserData', 'AjaxSaveCustomUserData'); + $this->addJsonHook('JsonGetCustomUserData', 'JsonGetCustomUserData'); + $this->addJsonHook('JsonSaveCustomUserData', 'JsonSaveCustomUserData'); $this->addTemplate('templates/PluginCustomSettingsTab.html'); } @@ -20,7 +20,7 @@ class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin /** * @return array */ - public function AjaxGetCustomUserData() + public function JsonGetCustomUserData() { $aSettings = $this->getUserSettings(); @@ -30,7 +30,7 @@ class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin // or get user's data from your custom storage ( DB / LDAP / ... ). \sleep(1); - return $this->ajaxResponse(__FUNCTION__, array( + return $this->jsonResponse(__FUNCTION__, array( 'UserFacebook' => $sUserFacebook, 'UserSkype' => $sUserSkype )); @@ -39,15 +39,15 @@ class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin /** * @return array */ - public function AjaxSaveCustomUserData() + public function JsonSaveCustomUserData() { - $sUserFacebook = $this->ajaxParam('UserFacebook'); - $sUserSkype = $this->ajaxParam('UserSkype'); + $sUserFacebook = $this->jsonParam('UserFacebook'); + $sUserSkype = $this->jsonParam('UserSkype'); // or put user's data to your custom storage ( DB / LDAP / ... ). \sleep(1); - return $this->ajaxResponse(__FUNCTION__, $this->saveUserSettings(array( + return $this->jsonResponse(__FUNCTION__, $this->saveUserSettings(array( 'UserFacebook' => $sUserFacebook, 'UserSkype' => $sUserSkype ))); diff --git a/plugins/custom-settings-tab/js/CustomUserSettings.js b/plugins/custom-settings-tab/js/CustomUserSettings.js index 16920d40f..3673f0518 100644 --- a/plugins/custom-settings-tab/js/CustomUserSettings.js +++ b/plugins/custom-settings-tab/js/CustomUserSettings.js @@ -22,7 +22,7 @@ }, this); } - CustomUserSettings.prototype.customAjaxSaveData = function () + CustomUserSettings.prototype.customJsonSaveData = function () { var self = this; @@ -46,7 +46,7 @@ // false } - }, 'AjaxSaveCustomUserData', { + }, 'JsonSaveCustomUserData', { 'UserSkype': this.userSkype(), 'UserFacebook': this.userFacebook() }); @@ -68,11 +68,11 @@ self.userFacebook(oData.Result.UserFacebook || ''); } - }, 'AjaxGetCustomUserData'); + }, 'JsonGetCustomUserData'); }; window.rl.addSettingsViewModel(CustomUserSettings, 'PluginCustomSettingsTab', 'SETTINGS_CUSTOM_PLUGIN/TAB_NAME', 'custom'); -}()); \ No newline at end of file +}()); diff --git a/plugins/custom-settings-tab/templates/PluginCustomSettingsTab.html b/plugins/custom-settings-tab/templates/PluginCustomSettingsTab.html index 31d4eb82b..1b688168b 100644 --- a/plugins/custom-settings-tab/templates/PluginCustomSettingsTab.html +++ b/plugins/custom-settings-tab/templates/PluginCustomSettingsTab.html @@ -23,7 +23,7 @@
-
- \ No newline at end of file + diff --git a/plugins/demo-account/index.php b/plugins/demo-account/index.php index e5fb923aa..63b6a15bc 100644 --- a/plugins/demo-account/index.php +++ b/plugins/demo-account/index.php @@ -9,7 +9,7 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin { $this->addHook('filter.app-data', 'FilterAppData'); $this->addHook('filter.action-params', 'FilterActionParams'); - $this->addHook('ajax.action-pre-call', 'AjaxActionPreCall'); + $this->addHook('json.action-pre-call', 'JsonActionPreCall'); $this->addHook('filter.send-message', 'FilterSendMessage'); $this->addHook('main.fabrica', 'MainFabrica'); } @@ -63,7 +63,7 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin return ($oAccount && $oAccount->Email() === $this->Config()->Get('plugin', 'email')); } - public function AjaxActionPreCall($sAction) + public function JsonActionPreCall($sAction) { if ('AccountSetup' === $sAction && $this->isDemoAccount($this->Manager()->Actions()->GetAccount())) diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 87c005413..da9b2d292 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -141,7 +141,7 @@ class Actions $this->sSpecAuthToken = ''; $this->sUpdateAuthToken = ''; - $this->bIsAjax = false; + $this->bIsJson = false; $oConfig = $this->Config(); $this->Plugins()->RunHook('filter.application-config', array($oConfig)); @@ -163,9 +163,9 @@ class Actions return $this; } - public function SetIsAjax(bool $bIsAjax): self + public function SetIsJson(bool $bIsJson): self { - $this->bIsAjax = $bIsAjax; + $this->bIsJson = $bIsJson; return $this; } @@ -180,9 +180,9 @@ class Actions return $this->sUpdateAuthToken; } - public function GetIsAjax(): bool + public function GetIsJson(): bool { - return $this->bIsAjax; + return $this->bIsJson; } public function GetShortLifeSpecAuthToken(int $iLife = 60): string diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php index 717c95d76..ff165096e 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php @@ -387,7 +387,7 @@ trait User $aResult = array(); - $this->Plugins()->RunHook('ajax.suggestions-input-parameters', array(&$sQuery, &$iLimit, $oAccount)); + $this->Plugins()->RunHook('json.suggestions-input-parameters', array(&$sQuery, &$iLimit, $oAccount)); $iLimit = (int) $iLimit; if (5 > $iLimit) @@ -395,7 +395,7 @@ trait User $iLimit = 5; } - $this->Plugins()->RunHook('ajax.suggestions-pre', array(&$aResult, $sQuery, $oAccount, $iLimit)); + $this->Plugins()->RunHook('json.suggestions-pre', array(&$aResult, $sQuery, $oAccount, $iLimit)); if ($iLimit > \count($aResult) && 0 < \strlen($sQuery)) { @@ -442,7 +442,7 @@ trait User $aResult = \array_slice($aResult, 0, $iLimit); } - $this->Plugins()->RunHook('ajax.suggestions-post', array(&$aResult, $sQuery, $oAccount, $iLimit)); + $this->Plugins()->RunHook('json.suggestions-post', array(&$aResult, $sQuery, $oAccount, $iLimit)); $aResult = Utils::RemoveSuggestionDuplicates($aResult); if ($iLimit < \count($aResult)) diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Identity.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Identity.php index 802e9a6f1..a2829099d 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Identity.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Identity.php @@ -131,17 +131,17 @@ class Identity implements JsonSerializable return $this; } - public function FromJSON(array $aData, bool $bAjax = false): bool + public function FromJSON(array $aData, bool $bJson = false): bool { if (!empty($aData['Email'])) { $this->sId = !empty($aData['Id']) ? $aData['Id'] : ''; - $this->sEmail = $bAjax ? Utils::IdnToAscii($aData['Email'], true) : $aData['Email']; + $this->sEmail = $bJson ? Utils::IdnToAscii($aData['Email'], true) : $aData['Email']; $this->sName = isset($aData['Name']) ? $aData['Name'] : ''; $this->sReplyTo = !empty($aData['ReplyTo']) ? $aData['ReplyTo'] : ''; $this->sBcc = !empty($aData['Bcc']) ? $aData['Bcc'] : ''; $this->sSignature = !empty($aData['Signature']) ? $aData['Signature'] : ''; $this->bSignatureInsertBefore = isset($aData['SignatureInsertBefore']) ? - ($bAjax ? '1' === $aData['SignatureInsertBefore'] : !!$aData['SignatureInsertBefore']) : true; + ($bJson ? '1' === $aData['SignatureInsertBefore'] : !!$aData['SignatureInsertBefore']) : true; return true; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Template.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Template.php index ee75d1153..331414d03 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Template.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Template.php @@ -52,7 +52,7 @@ class Template implements \JsonSerializable $this->bPopulateAlways = $bPopulateAlways; } - public function FromJSON(array $aData, bool $bAjax = false) : bool + public function FromJSON(array $aData, bool $bJson = false) : bool { if (isset($aData['ID'], $aData['Name'], $aData['Body'])) { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/AbstractPlugin.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/AbstractPlugin.php index 4650585d0..8ad7f8898 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/AbstractPlugin.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/AbstractPlugin.php @@ -232,11 +232,11 @@ abstract class AbstractPlugin return $this; } - protected function addAjaxHook(string $sActionName, string $sFunctionName) : self + protected function addJsonHook(string $sActionName, string $sFunctionName) : self { if ($this->oPluginManager) { - $this->oPluginManager->AddAdditionalAjaxAction($sActionName, array(&$this, $sFunctionName)); + $this->oPluginManager->AddAdditionalJsonAction($sActionName, array(&$this, $sFunctionName)); } return $this; @@ -253,11 +253,11 @@ abstract class AbstractPlugin return $this; } - protected function ajaxResponse(string $sFunctionName, array $aData) : self + protected function jsonResponse(string $sFunctionName, array $aData) : self { if ($this->oPluginManager) { - return $this->oPluginManager->AjaxResponseHelper( + return $this->oPluginManager->JsonResponseHelper( $this->oPluginManager->convertPluginFolderNameToClassName($this->Name()).'::'.$sFunctionName, $aData); } @@ -269,7 +269,7 @@ abstract class AbstractPlugin * * @return mixed */ - public function ajaxParam(string $sKey, $mDefault = null) + public function jsonParam(string $sKey, $mDefault = null) { if ($this->oPluginManager) { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php index 4096e22a9..d6b7dede6 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php @@ -47,7 +47,7 @@ class Manager /** * @var array */ - private $aAdditionalAjax; + private $aAdditionalJson; /** * @var array @@ -76,8 +76,8 @@ class Manager $this->aTemplates = array(); $this->aAdminTemplates = array(); - $this->aAjaxFilters = array(); - $this->aAdditionalAjax = array(); + $this->aJsonFilters = array(); + $this->aAdditionalJson = array(); $this->aProcessTemplate = array(); $this->bIsEnabled = (bool) $this->oActions->Config()->Get('plugins', 'enable', false); @@ -438,36 +438,36 @@ class Manager /** * @param mixed $mCallback */ - public function AddAdditionalAjaxAction(string $sActionName, $mCallback) : self + public function AddAdditionalJsonAction(string $sActionName, $mCallback) : self { if ($this->bIsEnabled && \is_callable($mCallback) && 0 < \strlen($sActionName)) { $sActionName = 'DoPlugin'.$sActionName; - if (!isset($this->aAdditionalAjax[$sActionName])) + if (!isset($this->aAdditionalJson[$sActionName])) { - $this->aAdditionalAjax[$sActionName] = $mCallback; + $this->aAdditionalJson[$sActionName] = $mCallback; } } return $this; } - public function HasAdditionalAjax(string $sActionName) : bool + public function HasAdditionalJson(string $sActionName) : bool { - return $this->bIsEnabled && isset($this->aAdditionalAjax[$sActionName]); + return $this->bIsEnabled && isset($this->aAdditionalJson[$sActionName]); } /** * @return mixed */ - public function RunAdditionalAjax(string $sActionName) + public function RunAdditionalJson(string $sActionName) { if ($this->bIsEnabled) { - if (isset($this->aAdditionalAjax[$sActionName])) + if (isset($this->aAdditionalJson[$sActionName])) { - return \call_user_func($this->aAdditionalAjax[$sActionName]); + return \call_user_func($this->aAdditionalJson[$sActionName]); } } @@ -479,7 +479,7 @@ class Manager * * @return mixed */ - public function AjaxResponseHelper(string $sFunctionName, $mData) + public function JsonResponseHelper(string $sFunctionName, $mData) { return $this->oActions->DefaultResponse($sFunctionName, $mData); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index beddca589..9b1639704 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -74,7 +74,7 @@ class ServiceActions return $this; } - public function ServiceAjax() : string + public function ServiceJson() : string { \ob_start(); @@ -87,7 +87,7 @@ class ServiceActions $sAction = $this->aPaths[2]; } - $this->oActions->SetIsAjax(true); + $this->oActions->SetIsJson(true); try { @@ -105,7 +105,7 @@ class ServiceActions $sMethodName = 'Do'.$sAction; - $this->Logger()->Write('Action: '.$sMethodName, \MailSo\Log\Enumerations\Type::NOTE, 'AJAX'); + $this->Logger()->Write('Action: '.$sMethodName, \MailSo\Log\Enumerations\Type::NOTE, 'JSON'); $aPost = $this->oHttp->GetPostAsArray(); if ($aPost) @@ -133,15 +133,15 @@ class ServiceActions if (\method_exists($this->oActions, $sMethodName) && \is_callable(array($this->oActions, $sMethodName))) { - $this->Plugins()->RunHook('ajax.action-pre-call', array($sAction)); + $this->Plugins()->RunHook('json.action-pre-call', array($sAction)); $aResponseItem = \call_user_func(array($this->oActions, $sMethodName)); - $this->Plugins()->RunHook('ajax.action-post-call', array($sAction, &$aResponseItem)); + $this->Plugins()->RunHook('json.action-post-call', array($sAction, &$aResponseItem)); } - else if ($this->Plugins()->HasAdditionalAjax($sMethodName)) + else if ($this->Plugins()->HasAdditionalJson($sMethodName)) { - $this->Plugins()->RunHook('ajax.action-pre-call', array($sAction)); - $aResponseItem = $this->Plugins()->RunAdditionalAjax($sMethodName); - $this->Plugins()->RunHook('ajax.action-post-call', array($sAction, &$aResponseItem)); + $this->Plugins()->RunHook('json.action-pre-call', array($sAction)); + $aResponseItem = $this->Plugins()->RunAdditionalJson($sMethodName); + $this->Plugins()->RunHook('json.action-post-call', array($sAction, &$aResponseItem)); } } @@ -189,7 +189,7 @@ class ServiceActions } } - $this->Plugins()->RunHook('filter.ajax-response', array($sAction, &$aResponseItem)); + $this->Plugins()->RunHook('filter.json-response', array($sAction, &$aResponseItem)); \header('Content-Type: application/json; charset=utf-8'); @@ -211,7 +211,7 @@ class ServiceActions $iLimit = (int) $this->Config()->Get('labs', 'log_ajax_response_write_limit', 0); $this->Logger()->Write(0 < $iLimit && $iLimit < \strlen($sResult) - ? \substr($sResult, 0, $iLimit).'...' : $sResult, \MailSo\Log\Enumerations\Type::INFO, 'AJAX'); + ? \substr($sResult, 0, $iLimit).'...' : $sResult, \MailSo\Log\Enumerations\Type::INFO, 'JSON'); } return $sResult; @@ -316,14 +316,7 @@ class ServiceActions $aResponseItem = $this->oActions->ExceptionResponse($sAction, $oException); } - if ('iframe' === $this->oHttp->GetPost('jua-post-type', '')) - { - \header('Content-Type: text/html; charset=utf-8'); - } - else - { - \header('Content-Type: application/json; charset=utf-8'); - } + \header('Content-Type: application/json; charset=utf-8'); $this->Plugins()->RunHook('filter.upload-response', array(&$aResponseItem)); $sResult = \MailSo\Base\Utils::Php2js($aResponseItem, $this->Logger()); diff --git a/vendors/jua/jua.js b/vendors/jua/jua.js index c0ad52640..e390da692 100644 --- a/vendors/jua/jua.js +++ b/vendors/jua/jua.js @@ -88,7 +88,7 @@ * @param {Jua} oJua * @param {Object} oOptions */ - class AjaxDriver + class XHRDriver { constructor(oJua, oOptions) { @@ -170,7 +170,6 @@ fStartFunction && fStartFunction(sUid); - oFormData.append('jua-post-type', 'ajax'); oFormData.append(this.oOptions.name, oFileInfo['File']); Object.entries(aHidden).forEach(([key, value]) => oFormData.append(key, (typeof value === "function" ? value(oFileInfo) : value).toString()) @@ -305,7 +304,7 @@ self.oQueue = new Queue(oOptions.queueSize); - self.oDriver = new AjaxDriver(self, oOptions); + self.oDriver = new XHRDriver(self, oOptions); let el = oOptions.clickElement; if (el) { diff --git a/vendors/jua/jua.min.js b/vendors/jua/jua.min.js index 487d147a1..69d2f87b7 100644 --- a/vendors/jua/jua.min.js +++ b/vendors/jua/jua.min.js @@ -1,2 +1,2 @@ /* RainLoop Webmail (c) RainLoop Team | MIT */ -(e=>{const t=20,n=e=>void 0!==e,r=(e,r,i,l)=>{if(e&&e.length){let a=i=n(i)?parseInt(i||0,10):t,s=null,d=0{e&&(!d||0<=--i?(s=o(e))&&r(s):d&&!u&&0>i&&l&&(u=!0,l(a)))})}},i=(e,t)=>Object.entries(t).forEach(([t,n])=>e.addEventListener(t,n)),o=e=>{let t=n(e.fileName)?e.fileName:n(e.name)?e.name:null,r=n(e.fileSize)?e.fileSize:n(e.size)?e.size:null,i=n(e.type)?e.type:null;return"/"===t.charAt(0)&&(t=t.substr(1)),i||0!==r?{FileName:t,Size:r,Type:i,Folder:"",File:e}:null},l=e=>{try{return e.dataTransfer.types.includes("Files")}catch(e){return!1}};class a{constructor(e,t){this.oXhrs={},this.oUids={},this.oJua=e,this.oOptions=Object.assign({action:"",name:"juaFile",hidden:{},disableMultiple:!1},t)}regTaskUid(e){this.oUids[e]=!0}uploadTask(e,t){if(!1===this.oUids[e]||!t||!t.File)return!1;try{const r=this,i=new XMLHttpRequest,o=new FormData,l=this.oOptions.action,a=this.oOptions.hidden,s=this.oJua.getEvent("onStart"),d=this.oJua.getEvent("onProgress");return i.open("POST",l,!0),d&&i.upload&&(i.upload.onprogress=(t=>{t&&t.lengthComputable&&n(t.loaded)&&n(t.total)&&d(e,t.loaded,t.total)})),i.onreadystatechange=(()=>{if(4===i.readyState){delete r.oXhrs[e];let t=!1,n=null;if(200===i.status)try{n=JSON.parse(i.responseText),t=!0}catch(e){console.error(e)}this.oJua.getEvent("onComplete")(e,t,t?n:null)}}),s&&s(e),o.append("jua-post-type","ajax"),o.append(this.oOptions.name,t.File),Object.entries(a).forEach(([e,n])=>o.append(e,("function"==typeof n?n(t):n).toString())),i.send(o),this.oXhrs[e]=i,!0}catch(e){console.error(e)}return!1}generateNewInput(t){if(t){const n=this,i=e.createElement("input"),o=()=>i.click();i.type="file",i.tabIndex=-1,i.style.display="none",i.multiple=!n.oOptions.disableMultiple,t.addEventListener("click",o),i.addEventListener("input",()=>{const e=e=>{n.oJua.addNewFile(e),setTimeout(()=>{i.remove(),t.removeEventListener("click",o),n.generateNewInput(t)},10)};i.files&&i.files.length?r(i.files,e,n.oOptions.multipleSizeLimit,n.oJua.getEvent("onLimitReached")):e({FileName:i.value.split("\\").pop().split("/").pop(),Size:null,Type:null,Folder:"",File:null})})}}cancel(e){if(this.oUids[e]=!1,this.oXhrs[e]){try{this.oXhrs[e].abort&&this.oXhrs[e].abort()}catch(e){console.error(e)}delete this.oXhrs[e]}}}class s extends Array{constructor(e){super(),this.limit=parseInt(e||0,10)}push(e,...t){this.limit>this.length&&(super.push([e,t]),this.call())}call(){if(!this.running){let e;for(this.running=!0;e=this.shift();)e[0](...e[1]);this.running=!1}}}class d{constructor(n){const o=this;o.oEvents={onSelect:null,onStart:null,onComplete:null,onProgress:null,onDragEnter:null,onDragLeave:null,onBodyDragEnter:null,onBodyDragLeave:null,onLimitReached:null},n=Object.assign({queueSize:10,clickElement:null,dragAndDropElement:null,dragAndDropBodyElement:null,disableDocumentDropPrevent:!1,multipleSizeLimit:t},n||{}),o.oQueue=new s(n.queueSize),o.oDriver=new a(o,n);let d=n.clickElement;if(d&&(d.style.position="relative",d.style.overflow="hidden","inline"===d.style.display&&(d.style.display="inline-block"),o.oDriver.generateNewInput(d)),d=n.dragAndDropElement){let t=n.dragAndDropBodyElement||e;n.disableDocumentDropPrevent||e.addEventListener("dragover",e=>{if(l(e))try{e.dataTransfer.dropEffect="none",e.preventDefault()}catch(e){console.error(e)}}),t&&i(t,{dragover:()=>o.docTimer.clear(),dragenter:e=>{l(e)&&(o.docTimer.clear(),e.preventDefault(),o.runEvent("onBodyDragEnter",[e]))},dragleave:e=>e.dataTransfer&&o.docTimer.start(()=>o.runEvent("onBodyDragLeave",[e])),drop:e=>{if(e.dataTransfer){let t=l(e);return t&&e.preventDefault(),o.runEvent("onBodyDragLeave",[e]),!t}return!1}}),i(d,{dragenter:e=>{l(e)&&(o.docTimer.clear(),e.preventDefault(),o.runEvent("onDragEnter",[d,e]))},dragover:e=>{if(l(e))try{let t=e.dataTransfer.effectAllowed;o.docTimer.clear(),e.dataTransfer.dropEffect="move"===t||"linkMove"===t?"move":"copy",e.stopPropagation(),e.preventDefault()}catch(e){console.error(e)}},dragleave:t=>{if(t.dataTransfer){let n=e.elementFromPoint(t.clientX,t.clientY);n&&d.contains(n)||(o.docTimer.clear(),o.runEvent("onDragLeave",[d,t]))}},drop:e=>{l(e)&&(e.preventDefault(),r(e.files||e.dataTransfer.files,e=>{e&&(o.addNewFile(e),o.docTimer.clear())},n.multipleSizeLimit,o.getEvent("onLimitReached"))),o.runEvent("onDragLeave",[e])}})}}on(e,t){return this.oEvents[e]=t,this}runEvent(e,t){this.oEvents[e]&&this.oEvents[e].apply(null,t||[])}getEvent(e){return this.oEvents[e]||null}cancel(e){this.oDriver.cancel(e)}addNewFile(e){this.addFile("jua-uid-"+d.randomId(16)+"-"+Date.now().toString(),e)}addFile(e,t){const n=this.getEvent("onSelect");!t||n&&!1===n(e,t)?this.oDriver.cancel(e):(this.oDriver.regTaskUid(e),this.oQueue.push((...e)=>this.oDriver.uploadTask(...e),e,t))}}d.randomId=(e=>{let t=new Uint8Array((e||32)/2);return crypto.getRandomValues(t),t.map(e=>e.toString(16).padStart(2,"0")).join("")}),d.prototype.docTimer={start:function(e){this.clear(),this.timer=setTimeout(e,200)},clear:function(){this.timer&&clearTimeout(this.timer),this.timer=0}},this.Jua=d})(document); +(e=>{const t=20,n=e=>void 0!==e,r=(e,r,i,l)=>{if(e&&e.length){let a=i=n(i)?parseInt(i||0,10):t,s=null,d=0{e&&(!d||0<=--i?(s=o(e))&&r(s):d&&!u&&0>i&&l&&(u=!0,l(a)))})}},i=(e,t)=>Object.entries(t).forEach(([t,n])=>e.addEventListener(t,n)),o=e=>{let t=n(e.fileName)?e.fileName:n(e.name)?e.name:null,r=n(e.fileSize)?e.fileSize:n(e.size)?e.size:null,i=n(e.type)?e.type:null;return"/"===t.charAt(0)&&(t=t.substr(1)),i||0!==r?{FileName:t,Size:r,Type:i,Folder:"",File:e}:null},l=e=>{try{return e.dataTransfer.types.includes("Files")}catch(e){return!1}};class a{constructor(e,t){this.oXhrs={},this.oUids={},this.oJua=e,this.oOptions=Object.assign({action:"",name:"juaFile",hidden:{},disableMultiple:!1},t)}regTaskUid(e){this.oUids[e]=!0}uploadTask(e,t){if(!1===this.oUids[e]||!t||!t.File)return!1;try{const r=this,i=new XMLHttpRequest,o=new FormData,l=this.oOptions.action,a=this.oOptions.hidden,s=this.oJua.getEvent("onStart"),d=this.oJua.getEvent("onProgress");return i.open("POST",l,!0),d&&i.upload&&(i.upload.onprogress=(t=>{t&&t.lengthComputable&&n(t.loaded)&&n(t.total)&&d(e,t.loaded,t.total)})),i.onreadystatechange=(()=>{if(4===i.readyState){delete r.oXhrs[e];let t=!1,n=null;if(200===i.status)try{n=JSON.parse(i.responseText),t=!0}catch(e){console.error(e)}this.oJua.getEvent("onComplete")(e,t,t?n:null)}}),s&&s(e),o.append(this.oOptions.name,t.File),Object.entries(a).forEach(([e,n])=>o.append(e,("function"==typeof n?n(t):n).toString())),i.send(o),this.oXhrs[e]=i,!0}catch(e){console.error(e)}return!1}generateNewInput(t){if(t){const n=this,i=e.createElement("input"),o=()=>i.click();i.type="file",i.tabIndex=-1,i.style.display="none",i.multiple=!n.oOptions.disableMultiple,t.addEventListener("click",o),i.addEventListener("input",()=>{const e=e=>{n.oJua.addNewFile(e),setTimeout(()=>{i.remove(),t.removeEventListener("click",o),n.generateNewInput(t)},10)};i.files&&i.files.length?r(i.files,e,n.oOptions.multipleSizeLimit,n.oJua.getEvent("onLimitReached")):e({FileName:i.value.split("\\").pop().split("/").pop(),Size:null,Type:null,Folder:"",File:null})})}}cancel(e){if(this.oUids[e]=!1,this.oXhrs[e]){try{this.oXhrs[e].abort&&this.oXhrs[e].abort()}catch(e){console.error(e)}delete this.oXhrs[e]}}}class s extends Array{constructor(e){super(),this.limit=parseInt(e||0,10)}push(e,...t){this.limit>this.length&&(super.push([e,t]),this.call())}call(){if(!this.running){let e;for(this.running=!0;e=this.shift();)e[0](...e[1]);this.running=!1}}}class d{constructor(n){const o=this;o.oEvents={onSelect:null,onStart:null,onComplete:null,onProgress:null,onDragEnter:null,onDragLeave:null,onBodyDragEnter:null,onBodyDragLeave:null,onLimitReached:null},n=Object.assign({queueSize:10,clickElement:null,dragAndDropElement:null,dragAndDropBodyElement:null,disableDocumentDropPrevent:!1,multipleSizeLimit:t},n||{}),o.oQueue=new s(n.queueSize),o.oDriver=new a(o,n);let d=n.clickElement;if(d&&(d.style.position="relative",d.style.overflow="hidden","inline"===d.style.display&&(d.style.display="inline-block"),o.oDriver.generateNewInput(d)),d=n.dragAndDropElement){let t=n.dragAndDropBodyElement||e;n.disableDocumentDropPrevent||e.addEventListener("dragover",e=>{if(l(e))try{e.dataTransfer.dropEffect="none",e.preventDefault()}catch(e){console.error(e)}}),t&&i(t,{dragover:()=>o.docTimer.clear(),dragenter:e=>{l(e)&&(o.docTimer.clear(),e.preventDefault(),o.runEvent("onBodyDragEnter",[e]))},dragleave:e=>e.dataTransfer&&o.docTimer.start(()=>o.runEvent("onBodyDragLeave",[e])),drop:e=>{if(e.dataTransfer){let t=l(e);return t&&e.preventDefault(),o.runEvent("onBodyDragLeave",[e]),!t}return!1}}),i(d,{dragenter:e=>{l(e)&&(o.docTimer.clear(),e.preventDefault(),o.runEvent("onDragEnter",[d,e]))},dragover:e=>{if(l(e))try{let t=e.dataTransfer.effectAllowed;o.docTimer.clear(),e.dataTransfer.dropEffect="move"===t||"linkMove"===t?"move":"copy",e.stopPropagation(),e.preventDefault()}catch(e){console.error(e)}},dragleave:t=>{if(t.dataTransfer){let n=e.elementFromPoint(t.clientX,t.clientY);n&&d.contains(n)||(o.docTimer.clear(),o.runEvent("onDragLeave",[d,t]))}},drop:e=>{l(e)&&(e.preventDefault(),r(e.files||e.dataTransfer.files,e=>{e&&(o.addNewFile(e),o.docTimer.clear())},n.multipleSizeLimit,o.getEvent("onLimitReached"))),o.runEvent("onDragLeave",[e])}})}}on(e,t){return this.oEvents[e]=t,this}runEvent(e,t){this.oEvents[e]&&this.oEvents[e].apply(null,t||[])}getEvent(e){return this.oEvents[e]||null}cancel(e){this.oDriver.cancel(e)}addNewFile(e){this.addFile("jua-uid-"+d.randomId(16)+"-"+Date.now().toString(),e)}addFile(e,t){const n=this.getEvent("onSelect");!t||n&&!1===n(e,t)?this.oDriver.cancel(e):(this.oDriver.regTaskUid(e),this.oQueue.push((...e)=>this.oDriver.uploadTask(...e),e,t))}}d.randomId=(e=>{let t=new Uint8Array((e||32)/2);return crypto.getRandomValues(t),t.map(e=>e.toString(16).padStart(2,"0")).join("")}),d.prototype.docTimer={start:function(e){this.clear(),this.timer=setTimeout(e,200)},clear:function(){this.timer&&clearTimeout(this.timer),this.timer=0}},this.Jua=d})(document);