2023-05-08 16:45:08 +03:00
{{define "component/themeSwitchTemplate"}}
< template >
2024-04-20 21:45:36 +03:00
< a-menu :theme = "themeSwitcher.currentTheme" mode = "inline" selected-keys = "" >
< a-sub-menu >
< span slot = "title" >
< a-icon type = "bulb" :theme = "themeSwitcher.isDarkTheme ? 'filled' : 'outlined'" > < / a-icon >
< span > Theme< / span >
< / span >
< a-menu-item id = "change-theme" class = "ant-menu-theme-switch" @ mousedown = "themeSwitcher.animationsOff()" > Dark < a-switch style = "margin-left: 2px;" size = "small" :default-checked = "themeSwitcher.isDarkTheme" @ change = "themeSwitcher.toggleTheme()" > < / a-switch >
< / a-menu-item >
< a-menu-item id = "change-theme-ultra" v-if = "themeSwitcher.isDarkTheme" class = "ant-menu-theme-switch" @ mousedown = "themeSwitcher.animationsOffUltra()" > Ultra < a-checkbox style = "margin-left: 2px;" :checked = "themeSwitcher.isUltra" @ click = "themeSwitcher.toggleUltra()" > < / a-checkbox >
< / a-menu-item >
< / a-sub-menu >
< / a-menu >
< / template >
{{end}}
{{define "component/themeSwitchTemplateLogin"}}
< template >
< a-menu @ mousedown = "themeSwitcher.animationsOff()" id = "change-theme" :theme = "themeSwitcher.currentTheme" mode = "inline" selected-keys = "" >
2024-03-09 16:06:16 +03:00
< a-menu-item mode = "inline" class = "ant-menu-theme-switch" >
< a-icon type = "bulb" :theme = "themeSwitcher.isDarkTheme ? 'filled' : 'outlined'" > < / a-icon >
< a-switch size = "small" :default-checked = "themeSwitcher.isDarkTheme" @ change = "themeSwitcher.toggleTheme()" > < / a-switch >
< template v-if = "themeSwitcher.isDarkTheme" >
< a-checkbox style = "margin-left: 1rem; vertical-align: middle;" :checked = "themeSwitcher.isUltra" @ click = "themeSwitcher.toggleUltra()" > Ultra< / a-checkbox >
< / template >
< / a-menu-item >
< / a-menu >
2023-05-08 16:45:08 +03:00
< / template >
{{end}}
{{define "component/themeSwitcher"}}
< script >
function createThemeSwitcher() {
const isDarkTheme = localStorage.getItem('dark-mode') === 'true';
2024-02-28 14:05:01 +03:00
const isUltra = localStorage.getItem('isUltraDarkThemeEnabled') === 'true';
if (isUltra) {
document.documentElement.setAttribute('data-theme', 'ultra-dark');
}
2023-05-08 16:45:08 +03:00
const theme = isDarkTheme ? 'dark' : 'light';
2024-02-28 14:05:01 +03:00
document.querySelector('body').setAttribute('class', theme);
2023-05-08 16:45:08 +03:00
return {
2024-04-20 21:45:36 +03:00
animationsOff() {
document.documentElement.setAttribute('data-theme-animations', 'off');
const themeAnimations = document.querySelector('#change-theme');
themeAnimations.addEventListener('mouseleave', () => {
document.documentElement.removeAttribute('data-theme-animations');
});
themeAnimations.addEventListener('touchend', () => {
document.documentElement.removeAttribute('data-theme-animations');
});
},
animationsOffUltra() {
document.documentElement.setAttribute('data-theme-animations', 'off');
const themeAnimationsUltra = document.querySelector('#change-theme-ultra');
themeAnimationsUltra.addEventListener('mouseleave', () => {
document.documentElement.removeAttribute('data-theme-animations');
});
themeAnimationsUltra.addEventListener('touchend', () => {
document.documentElement.removeAttribute('data-theme-animations');
});
},
2023-05-08 16:45:08 +03:00
isDarkTheme,
2024-02-28 14:05:01 +03:00
isUltra,
2023-05-08 16:45:08 +03:00
get currentTheme() {
return this.isDarkTheme ? 'dark' : 'light';
},
toggleTheme() {
this.isDarkTheme = !this.isDarkTheme;
localStorage.setItem('dark-mode', this.isDarkTheme);
2024-02-28 14:05:01 +03:00
document.querySelector('body').setAttribute('class', this.isDarkTheme ? 'dark' : 'light');
2024-02-21 15:02:18 +03:00
document.getElementById('message').className = themeSwitcher.currentTheme;
2023-05-08 16:45:08 +03:00
},
2024-02-28 14:05:01 +03:00
toggleUltra() {
this.isUltra = !this.isUltra;
if (this.isUltra) {
document.documentElement.setAttribute('data-theme', 'ultra-dark');
} else {
document.documentElement.removeAttribute('data-theme');
}
localStorage.setItem('isUltraDarkThemeEnabled', this.isUltra.toString());
}
2023-05-08 16:45:08 +03:00
};
}
const themeSwitcher = createThemeSwitcher();
Vue.component('theme-switch', {
props: [],
template: `{{template "component/themeSwitchTemplate"}}`,
2024-02-28 14:05:01 +03:00
data: () => ({
themeSwitcher
}),
2024-02-21 15:02:18 +03:00
mounted() {
2024-02-28 14:05:01 +03:00
this.$message.config({
getContainer: () => document.getElementById('message')
});
2024-02-21 15:02:18 +03:00
document.getElementById('message').className = themeSwitcher.currentTheme;
2024-04-20 21:45:36 +03:00
}
});
Vue.component('theme-switch-login', {
props: [],
template: `{{template "component/themeSwitchTemplateLogin"}}`,
data: () => ({
themeSwitcher
}),
mounted() {
this.$message.config({
getContainer: () => document.getElementById('message')
2024-04-01 10:08:22 +03:00
});
2024-04-20 21:45:36 +03:00
document.getElementById('message').className = themeSwitcher.currentTheme;
2024-02-21 15:02:18 +03:00
}
2023-05-08 16:45:08 +03:00
});
< / script >
2024-02-28 14:05:01 +03:00
{{end}}