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

View file

@ -3,6 +3,7 @@ import { $htmlCL, appEl, elementById, leftPanelDisabled, Settings, SettingsGet }
import { isArray, arrayLength } from 'Common/Utils'; import { isArray, arrayLength } from 'Common/Utils';
import { cssLink, serverRequestRaw } from 'Common/Links'; import { cssLink, serverRequestRaw } from 'Common/Links';
import { SaveSettingStatus } from 'Common/Enums'; import { SaveSettingStatus } from 'Common/Enums';
import { addSubscribablesTo } from 'External/ko';
let __themeTimer = 0; let __themeTimer = 0;
@ -60,35 +61,39 @@ export const
convertThemeName = theme => theme.replace(/@[a-z]+$/, '').replace(/([A-Z])/g, ' $1').trim(); 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 => { fontSansSerif: value => {
if (null != value) { if (null != value) {
let cl = appEl.classList; let cl = appEl.classList;
cl.forEach(name => { cl.forEach(name => {
if (name.startsWith('font') && !/font(Serif|Mono)/.test(name)) { if (name.startsWith('font') && !/font(Serif|Mono)/.test(name)) {
cl.remove(name); cl.remove(name);
} }
}); });
value && cl.add('font'+value); 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);
}
});
ThemeStore.userBackgroundHash.subscribe(value => { fontSerif: value => {
appEl.classList.toggle('UserBackground', !!value); if (null != value) {
appEl.style.backgroundImage = value ? "url("+serverRequestRaw('UserBackground', value)+")" : null; 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) { return function(...args) {
timer && clearTimeout(timer); timer && clearTimeout(timer);
timer = setTimeout(()=>{ timer = setTimeout(()=>{
func.apply(this, args) func.apply(this, args);
timer = 0; timer = 0;
}, ms); }, ms);
}; };
@ -68,12 +68,10 @@
Function.prototype.throttle = function(ms) { Function.prototype.throttle = function(ms) {
let func = this, timer; let func = this, timer;
return function(...args) { return function(...args) {
if (!timer) { timer = timer || setTimeout(()=>{
timer = setTimeout(()=>{ func.apply(this, args);
func.apply(this, args)
timer = 0; timer = 0;
}, ms); }, ms);
}
}; };
}; };
} }