2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2021-07-20 22:49:03 +08:00
|
|
|
import { doc, $htmlCL, 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 = {
|
|
|
|
themes: ko.observableArray(),
|
2021-02-17 21:40:21 +08:00
|
|
|
userBackgroundName: ko.observable(''),
|
|
|
|
userBackgroundHash: ko.observable(''),
|
|
|
|
isMobile: ko.observable($htmlCL.contains('rl-mobile')),
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-27 07:26:31 +08:00
|
|
|
populate: function(){
|
2021-03-10 18:44:48 +08:00
|
|
|
const themes = Settings.app('themes');
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-03-16 23:49:14 +08:00
|
|
|
this.themes(isArray(themes) ? themes : []);
|
2021-03-10 18:44:48 +08:00
|
|
|
this.theme(SettingsGet('Theme'));
|
2021-02-17 03:12:23 +08:00
|
|
|
if (!this.isMobile()) {
|
2021-03-10 18:44:48 +08:00
|
|
|
this.userBackgroundName(SettingsGet('UserBackgroundName'));
|
|
|
|
this.userBackgroundHash(SettingsGet('UserBackgroundHash'));
|
2021-02-15 22:20:22 +08:00
|
|
|
}
|
2021-03-05 23:46:40 +08:00
|
|
|
|
|
|
|
leftPanelDisabled(this.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-01-27 07:26:31 +08:00
|
|
|
ThemeStore.theme = ko.observable('').extend({ limitedList: ThemeStore.themes });
|
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
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|