Cleanup a bit of javascript

This commit is contained in:
the-djmaze
2023-02-21 12:59:56 +01:00
parent 0b8ec5c664
commit 938c209869
3 changed files with 54 additions and 48 deletions

View File

@@ -6,6 +6,7 @@ import { i18n } from 'Common/Translator';
import { SettingsCapa } from 'Common/Globals';
import { ThemeStore, convertThemeName, changeTheme } from 'Stores/Theme';
import { addSubscribablesTo } from 'External/ko';
import Remote from 'Remote/User/Fetch';
@@ -24,20 +25,22 @@ export class UserSettingsThemes /*extends AbstractViewSettings*/ {
this.fontSansSerif = ThemeStore.fontSansSerif;
this.fontSerif = ThemeStore.fontSerif;
this.fontMono = ThemeStore.fontMono;
ThemeStore.fontSansSerif.subscribe(value => {
Remote.saveSettings(null, {
fontSansSerif: value
});
});
ThemeStore.fontSerif.subscribe(value => {
Remote.saveSettings(null, {
fontSerif: value
});
});
ThemeStore.fontMono.subscribe(value => {
Remote.saveSettings(null, {
fontMono: value
});
addSubscribablesTo(ThemeStore, {
fontSansSerif: value => {
Remote.saveSettings(null, {
fontSansSerif: value
});
},
fontSerif: value => {
Remote.saveSettings(null, {
fontSerif: value
});
},
fontMono: value => {
Remote.saveSettings(null, {
fontMono: value
});
}
});
this.theme = ThemeStore.theme;

View File

@@ -3,6 +3,7 @@ import { $htmlCL, appEl, elementById, leftPanelDisabled, Settings, SettingsGet }
import { isArray, arrayLength } from 'Common/Utils';
import { cssLink, serverRequestRaw } from 'Common/Links';
import { SaveSettingStatus } from 'Common/Enums';
import { addSubscribablesTo } from 'External/ko';
let __themeTimer = 0;
@@ -60,35 +61,39 @@ export const
convertThemeName = theme => theme.replace(/@[a-z]+$/, '').replace(/([A-Z])/g, ' $1').trim();
ThemeStore.isMobile.subscribe(value => $htmlCL.toggle('rl-mobile', value));
addSubscribablesTo(ThemeStore, {
isMobile: value => $htmlCL.toggle('rl-mobile', value),
ThemeStore.fontSansSerif.subscribe(value => {
if (null != value) {
let cl = appEl.classList;
cl.forEach(name => {
if (name.startsWith('font') && !/font(Serif|Mono)/.test(name)) {
cl.remove(name);
}
});
value && cl.add('font'+value);
}
});
ThemeStore.fontSerif.subscribe(value => {
if (null != value) {
let cl = appEl.classList;
cl.forEach(name => name.startsWith('fontSerif') && cl.remove(name));
value && cl.add('fontSerif'+value);
}
});
ThemeStore.fontMono.subscribe(value => {
if (null != value) {
let cl = appEl.classList;
cl.forEach(name => name.startsWith('fontMono') && cl.remove(name));
value && cl.add('fontMono'+value);
}
});
fontSansSerif: value => {
if (null != value) {
let cl = appEl.classList;
cl.forEach(name => {
if (name.startsWith('font') && !/font(Serif|Mono)/.test(name)) {
cl.remove(name);
}
});
value && cl.add('font'+value);
}
},
ThemeStore.userBackgroundHash.subscribe(value => {
appEl.classList.toggle('UserBackground', !!value);
appEl.style.backgroundImage = value ? "url("+serverRequestRaw('UserBackground', value)+")" : null;
fontSerif: value => {
if (null != value) {
let cl = appEl.classList;
cl.forEach(name => name.startsWith('fontSerif') && cl.remove(name));
value && cl.add('fontSerif'+value);
}
},
fontMono: value => {
if (null != value) {
let cl = appEl.classList;
cl.forEach(name => name.startsWith('fontMono') && cl.remove(name));
value && cl.add('fontMono'+value);
}
},
userBackgroundHash: value => {
appEl.classList.toggle('UserBackground', !!value);
appEl.style.backgroundImage = value ? "url("+serverRequestRaw('UserBackground', value)+")" : null;
}
});

8
dev/prototype.js vendored
View File

@@ -53,7 +53,7 @@
return function(...args) {
timer && clearTimeout(timer);
timer = setTimeout(()=>{
func.apply(this, args)
func.apply(this, args);
timer = 0;
}, ms);
};
@@ -68,12 +68,10 @@
Function.prototype.throttle = function(ms) {
let func = this, timer;
return function(...args) {
if (!timer) {
timer = setTimeout(()=>{
func.apply(this, args)
timer = timer || setTimeout(()=>{
func.apply(this, args);
timer = 0;
}, ms);
}
};
};
}