mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 13:09:21 +03:00
Move changeTheme and convertThemeName to Themes.js
This commit is contained in:
parent
10835a6f82
commit
04c11ddc49
6 changed files with 76 additions and 94 deletions
|
|
@ -1,9 +1,3 @@
|
|||
import { SaveSettingStatus } from 'Common/Enums';
|
||||
import { elementById } from 'Common/Globals';
|
||||
|
||||
let __themeTimer = 0,
|
||||
__themeJson = null;
|
||||
|
||||
export const
|
||||
isArray = Array.isArray,
|
||||
arrayLength = array => isArray(array) && array.length,
|
||||
|
|
@ -19,12 +13,6 @@ export const
|
|||
return isNaN(value) || !isFinite(value) ? defaultValue : value;
|
||||
},
|
||||
|
||||
convertThemeName = theme => theme
|
||||
.replace(/@custom$/, '')
|
||||
.replace(/([A-Z])/g, ' $1')
|
||||
.replace(/[^a-zA-Z0-9]+/g, ' ')
|
||||
.trim(),
|
||||
|
||||
defaultOptionsAfterRender = (domItem, item) =>
|
||||
item && undefined !== item.disabled && domItem?.classList.toggle('disabled', domItem.disabled = item.disabled),
|
||||
|
||||
|
|
@ -37,34 +25,4 @@ export const
|
|||
*/
|
||||
b64EncodeJSONSafe = data => b64EncodeJSON(data).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
|
||||
|
||||
changeTheme = (value, themeTrigger = ()=>0) => {
|
||||
const themeStyle = elementById('app-theme-style'),
|
||||
clearTimer = () => {
|
||||
__themeTimer = setTimeout(() => themeTrigger(SaveSettingStatus.Idle), 1000);
|
||||
__themeJson = null;
|
||||
},
|
||||
url = themeStyle.dataset.href.replace(/(Admin|User)\/-\/[^/]+\//, '$1/-/' + value + '/') + 'Json/';
|
||||
|
||||
clearTimeout(__themeTimer);
|
||||
|
||||
themeTrigger(SaveSettingStatus.Saving);
|
||||
|
||||
if (__themeJson) {
|
||||
__themeJson.abort();
|
||||
}
|
||||
let init = {};
|
||||
if (window.AbortController) {
|
||||
__themeJson = new AbortController();
|
||||
init.signal = __themeJson.signal;
|
||||
}
|
||||
rl.fetchJSON(url, init)
|
||||
.then(data => {
|
||||
if (2 === arrayLength(data)) {
|
||||
themeStyle.textContent = data[1];
|
||||
themeTrigger(SaveSettingStatus.Success);
|
||||
}
|
||||
})
|
||||
.then(clearTimer, clearTimer);
|
||||
},
|
||||
|
||||
getKeyByValue = (o, v) => Object.keys(o).find(key => o[key] === v);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue