2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2022-10-20 15:33:44 +08:00
|
|
|
import { doc, $htmlCL, elementById, leftPanelDisabled, Settings, SettingsGet } from 'Common/Globals';
|
2021-03-16 23:49:14 +08:00
|
|
|
import { isArray } from 'Common/Utils';
|
2021-07-20 22:49:03 +08:00
|
|
|
import { serverRequestRaw } from 'Common/Links';
|
2015-01-27 05:06:00 +08:00
|
|
|
|
2021-01-27 07:26:31 +08:00
|
|
|
export const ThemeStore = {
|
2022-09-26 17:55:26 +08:00
|
|
|
theme: ko.observable(''),
|
2021-01-27 07:26:31 +08:00
|
|
|
themes: ko.observableArray(),
|
2021-02-17 21:40:21 +08:00
|
|
|
userBackgroundName: ko.observable(''),
|
|
|
|
userBackgroundHash: ko.observable(''),
|
2022-10-20 15:33:44 +08:00
|
|
|
fontSansSerif: ko.observable(''),
|
|
|
|
fontSerif: ko.observable(''),
|
|
|
|
fontMono: ko.observable(''),
|
2021-02-17 21:40:21 +08:00
|
|
|
isMobile: ko.observable($htmlCL.contains('rl-mobile')),
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2022-03-08 17:52:40 +08:00
|
|
|
populate: () => {
|
2021-03-10 18:44:48 +08:00
|
|
|
const themes = Settings.app('themes');
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2022-03-08 17:52:40 +08:00
|
|
|
ThemeStore.themes(isArray(themes) ? themes : []);
|
|
|
|
ThemeStore.theme(SettingsGet('Theme'));
|
|
|
|
if (!ThemeStore.isMobile()) {
|
|
|
|
ThemeStore.userBackgroundName(SettingsGet('UserBackgroundName'));
|
|
|
|
ThemeStore.userBackgroundHash(SettingsGet('UserBackgroundHash'));
|
2021-02-15 22:20:22 +08:00
|
|
|
}
|
2022-10-20 15:33:44 +08:00
|
|
|
ThemeStore.fontSansSerif(SettingsGet('fontSansSerif'));
|
|
|
|
ThemeStore.fontSerif(SettingsGet('fontSerif'));
|
|
|
|
ThemeStore.fontMono(SettingsGet('fontMono'));
|
2021-03-05 23:46:40 +08:00
|
|
|
|
2022-03-08 17:52:40 +08:00
|
|
|
leftPanelDisabled(ThemeStore.isMobile());
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2021-01-27 07:26:31 +08:00
|
|
|
};
|
2015-01-27 05:06:00 +08:00
|
|
|
|
2021-02-17 03:12:23 +08:00
|
|
|
ThemeStore.isMobile.subscribe(value => $htmlCL.toggle('rl-mobile', value));
|
2021-07-20 22:49:03 +08:00
|
|
|
|
2022-10-20 15:33:44 +08:00
|
|
|
ThemeStore.fontSansSerif.subscribe(value => {
|
|
|
|
if (null != value) {
|
|
|
|
let cl = elementById('rl-app').classList;
|
|
|
|
cl.forEach(name => {
|
2022-10-26 22:38:39 +08:00
|
|
|
if (name.startsWith('font') && !/font(Serif|Mono)/.test(name)) {
|
2022-10-20 15:33:44 +08:00
|
|
|
cl.remove(name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
value && cl.add('font'+value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ThemeStore.fontSerif.subscribe(value => {
|
|
|
|
if (null != value) {
|
|
|
|
let cl = elementById('rl-app').classList;
|
2022-10-26 22:38:39 +08:00
|
|
|
cl.forEach(name => name.startsWith('fontSerif') && cl.remove(name));
|
2022-10-20 15:33:44 +08:00
|
|
|
value && cl.add('fontSerif'+value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ThemeStore.fontMono.subscribe(value => {
|
|
|
|
if (null != value) {
|
|
|
|
let cl = elementById('rl-app').classList;
|
2022-10-26 22:38:39 +08:00
|
|
|
cl.forEach(name => name.startsWith('fontMono') && cl.remove(name));
|
2022-10-20 15:33:44 +08:00
|
|
|
value && cl.add('fontMono'+value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-20 22:49:03 +08:00
|
|
|
ThemeStore.userBackgroundHash.subscribe(value => {
|
|
|
|
if (value) {
|
|
|
|
$htmlCL.add('UserBackground');
|
|
|
|
doc.body.style.backgroundImage = "url("+serverRequestRaw('UserBackground', value)+")";
|
|
|
|
} else {
|
|
|
|
$htmlCL.remove('UserBackground');
|
|
|
|
doc.body.removeAttribute('style');
|
|
|
|
}
|
|
|
|
});
|