mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 04:29:21 +03:00
Keep AUTH_SPEC_TOKEN_KEY
And now we can embed theme and language in index.html template
This commit is contained in:
parent
4579a786ab
commit
ce63ba506a
7 changed files with 30 additions and 49 deletions
|
|
@ -3,7 +3,7 @@ import { Notification, UploadErrorCode } from 'Common/Enums';
|
|||
import { langLink } from 'Common/Links';
|
||||
import { doc, createElement } from 'Common/Globals';
|
||||
|
||||
let I18N_DATA = window.snappymailI18N || {};
|
||||
let I18N_DATA = {};
|
||||
|
||||
export const trigger = ko.observable(false);
|
||||
|
||||
|
|
@ -49,10 +49,21 @@ const i18nToNode = element => {
|
|||
}
|
||||
},
|
||||
|
||||
init = () => {
|
||||
if (rl.I18N) {
|
||||
I18N_DATA = rl.I18N;
|
||||
Date.defineRelativeTimeFormat(rl.relativeTime || {});
|
||||
rl.I18N = null;
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
|
||||
i18nKey = key => key.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase(),
|
||||
|
||||
getKeyByValue = (o, v) => Object.keys(o).find(key => o[key] === v);
|
||||
|
||||
init();
|
||||
|
||||
/**
|
||||
* @param {Object} elements
|
||||
* @param {boolean=} animate = false
|
||||
|
|
@ -127,13 +138,11 @@ export function reload(admin, language) {
|
|||
const script = createElement('script');
|
||||
script.onload = () => {
|
||||
// reload the data
|
||||
if (window.snappymailI18N) {
|
||||
I18N_DATA = window.snappymailI18N;
|
||||
if (init()) {
|
||||
i18nToNodes(doc);
|
||||
dispatchEvent(new CustomEvent('reload-time'));
|
||||
trigger(!trigger());
|
||||
}
|
||||
window.snappymailI18N = null;
|
||||
script.remove();
|
||||
resolve();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { SaveSettingsStep } from 'Common/Enums';
|
||||
import { doc, createElement, elementById } from 'Common/Globals';
|
||||
import { doc, elementById } from 'Common/Globals';
|
||||
|
||||
export const
|
||||
isArray = Array.isArray,
|
||||
|
|
@ -84,14 +84,13 @@ let __themeTimer = 0,
|
|||
* @returns {void}
|
||||
*/
|
||||
export function changeTheme(value, themeTrigger = ()=>{}) {
|
||||
const themeLink = elementById('app-theme-link'),
|
||||
const themeStyle = elementById('app-theme-style'),
|
||||
clearTimer = () => {
|
||||
__themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
|
||||
__themeJson = null;
|
||||
};
|
||||
|
||||
let themeStyle = elementById('app-theme-style'),
|
||||
url = (themeLink && themeLink.href) || (themeStyle && themeStyle.dataset.href);
|
||||
let url = themeStyle.dataset.href;
|
||||
|
||||
if (url) {
|
||||
url = url.toString()
|
||||
|
|
@ -118,19 +117,9 @@ export function changeTheme(value, themeTrigger = ()=>{}) {
|
|||
rl.fetchJSON(url, init)
|
||||
.then(data => {
|
||||
if (data && isArray(data) && 2 === data.length) {
|
||||
if (themeLink && !themeStyle) {
|
||||
themeStyle = createElement('style');
|
||||
themeStyle.id = 'app-theme-style';
|
||||
themeLink.after(themeStyle);
|
||||
themeLink.remove();
|
||||
}
|
||||
|
||||
if (themeStyle) {
|
||||
themeStyle.textContent = data[1];
|
||||
themeStyle.dataset.href = url;
|
||||
themeStyle.dataset.theme = data[0];
|
||||
}
|
||||
|
||||
themeStyle.textContent = data[1];
|
||||
themeStyle.dataset.href = url;
|
||||
themeStyle.dataset.theme = data[0];
|
||||
themeTrigger(SaveSettingsStep.TrueResult);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -144,12 +144,7 @@ win.rl = {
|
|||
rl.hash.set();
|
||||
|
||||
if (appData) {
|
||||
if (appData.NewThemeLink) {
|
||||
eId('app-theme-link').href = appData.NewThemeLink;
|
||||
}
|
||||
|
||||
loadScript(appData.StaticLibJsLink)
|
||||
.then(() => loadScript(appData.LangLink))
|
||||
.then(() => loadScript(appData.StaticAppJsLink))
|
||||
.then(() => appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve())
|
||||
.then(() => win.__APP_BOOT ? win.__APP_BOOT(showError) : showError())
|
||||
|
|
@ -170,7 +165,7 @@ Storage('local');
|
|||
// init section
|
||||
setInterval(setTimestamp, 60000); // 1m
|
||||
|
||||
[eId('app-css'),eId('app-theme-link')].forEach(css => css.href = css.dataset.href);
|
||||
eId('app-css').href = eId('app-css').dataset.href;
|
||||
|
||||
loadScript(`./?/${admin ? 'Admin' : ''}AppData/${rl.hash.get() || '0'}/${Math.random().toString().substr(2)}/`)
|
||||
.then(() => {});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue