Prevent unnecessary switch
parent
032a6a8355
commit
9e13aaf342
12
app.vue
12
app.vue
|
@ -22,13 +22,11 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.themeChangeListener = (event) => {
|
this.themeChangeListener = (event) => {
|
||||||
if (event.theme !== this.$appState.theme) {
|
this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => {
|
||||||
this.$primevue.changeTheme(this.$appState.theme, event.theme, 'theme-link', () => {
|
this.$appState.theme = event.theme;
|
||||||
this.$appState.theme = event.theme;
|
this.$appState.darkTheme = event.dark;
|
||||||
this.$appState.darkTheme = event.dark;
|
EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark });
|
||||||
EventBus.emit('theme-change-complete', { theme: event.theme, dark: event.dark });
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EventBus.on('theme-change', this.themeChangeListener);
|
EventBus.on('theme-change', this.themeChangeListener);
|
||||||
|
|
|
@ -157,21 +157,23 @@ export function usePrimeVue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchTheme(currentTheme, newTheme, linkElementId, callback) {
|
function switchTheme(currentTheme, newTheme, linkElementId, callback) {
|
||||||
const linkElement = document.getElementById(linkElementId);
|
if (currentTheme !== newTheme) {
|
||||||
const cloneLinkElement = linkElement.cloneNode(true);
|
const linkElement = document.getElementById(linkElementId);
|
||||||
const newThemeUrl = linkElement.getAttribute('href').replace(currentTheme, newTheme);
|
const cloneLinkElement = linkElement.cloneNode(true);
|
||||||
|
const newThemeUrl = linkElement.getAttribute('href').replace(currentTheme, newTheme);
|
||||||
|
|
||||||
cloneLinkElement.setAttribute('id', linkElementId + '-clone');
|
cloneLinkElement.setAttribute('id', linkElementId + '-clone');
|
||||||
cloneLinkElement.setAttribute('href', newThemeUrl);
|
cloneLinkElement.setAttribute('href', newThemeUrl);
|
||||||
cloneLinkElement.addEventListener('load', () => {
|
cloneLinkElement.addEventListener('load', () => {
|
||||||
linkElement.remove();
|
linkElement.remove();
|
||||||
cloneLinkElement.setAttribute('id', linkElementId);
|
cloneLinkElement.setAttribute('id', linkElementId);
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
linkElement.parentNode && linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
|
linkElement.parentNode && linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
Loading…
Reference in New Issue