Prevent unnecessary switch

pull/4649/head
Cagatay Civici 2023-10-18 01:00:08 +03:00
parent 032a6a8355
commit 9e13aaf342
2 changed files with 22 additions and 22 deletions

12
app.vue
View File

@ -22,13 +22,11 @@ export default {
},
mounted() {
this.themeChangeListener = (event) => {
if (event.theme !== this.$appState.theme) {
this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => {
this.$appState.theme = event.theme;
this.$appState.darkTheme = event.dark;
EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark });
});
}
this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => {
this.$appState.theme = event.theme;
this.$appState.darkTheme = event.dark;
EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark });
});
};
EventBus.on('theme-change', this.themeChangeListener);

View File

@ -157,21 +157,23 @@ export function usePrimeVue() {
}
function switchTheme(currentTheme, newTheme, linkElementId, callback) {
const linkElement = document.getElementById(linkElementId);
const cloneLinkElement = linkElement.cloneNode(true);
const newThemeUrl = linkElement.getAttribute('href').replace(currentTheme, newTheme);
if (currentTheme !== newTheme) {
const linkElement = document.getElementById(linkElementId);
const cloneLinkElement = linkElement.cloneNode(true);
const newThemeUrl = linkElement.getAttribute('href').replace(currentTheme, newTheme);
cloneLinkElement.setAttribute('id', linkElementId + '-clone');
cloneLinkElement.setAttribute('href', newThemeUrl);
cloneLinkElement.addEventListener('load', () => {
linkElement.remove();
cloneLinkElement.setAttribute('id', linkElementId);
cloneLinkElement.setAttribute('id', linkElementId + '-clone');
cloneLinkElement.setAttribute('href', newThemeUrl);
cloneLinkElement.addEventListener('load', () => {
linkElement.remove();
cloneLinkElement.setAttribute('id', linkElementId);
if (callback) {
callback();
}
});
linkElement.parentNode && linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
if (callback) {
callback();
}
});
linkElement.parentNode && linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
}
}
export default {