Sync table theme with dark/light mode

pull/2207/head
Cagatay Civici 2022-02-24 00:19:22 +03:00
parent eb5f453b24
commit 843320f519
1 changed files with 17 additions and 10 deletions

View File

@ -49,6 +49,8 @@ export default {
expire.setTime(today.getTime() + 3600000*24*7); expire.setTime(today.getTime() + 3600000*24*7);
document.cookie = 'primeaffiliateid=' + afId + ';expires=' + expire.toUTCString() + ';path=/; domain:primefaces.org'; document.cookie = 'primeaffiliateid=' + afId + ';expires=' + expire.toUTCString() + ';path=/; domain:primefaces.org';
} }
this.replaceTableTheme(this.$appState.darkTheme ? 'lara-dark-indigo': 'lara-light-indigo');
}, },
methods: { methods: {
onThemeToggle() { onThemeToggle() {
@ -64,18 +66,23 @@ export default {
replaceTableTheme(newTheme) { replaceTableTheme(newTheme) {
const elementId = 'home-table-link'; const elementId = 'home-table-link';
const linkElement = document.getElementById(elementId); const linkElement = document.getElementById(elementId);
const cloneLinkElement = linkElement.cloneNode(true); const tableThemeTokens = linkElement.getAttribute('href').split('/');
const newThemeUrl = linkElement.getAttribute('href').replace(this.tableTheme, newTheme); const currentTableTheme = tableThemeTokens[tableThemeTokens.length - 2];
cloneLinkElement.setAttribute('id', elementId + '-clone'); if (currentTableTheme !== newTheme) {
cloneLinkElement.setAttribute('href', newThemeUrl); const newThemeUrl = linkElement.getAttribute('href').replace(currentTableTheme, newTheme);
cloneLinkElement.addEventListener('load', () => {
linkElement.remove();
cloneLinkElement.setAttribute('id', elementId);
});
linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
this.tableTheme = newTheme; const cloneLinkElement = linkElement.cloneNode(true);
cloneLinkElement.setAttribute('id', elementId + '-clone');
cloneLinkElement.setAttribute('href', newThemeUrl);
cloneLinkElement.addEventListener('load', () => {
linkElement.remove();
cloneLinkElement.setAttribute('id', elementId);
});
linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
this.tableTheme = newTheme;
}
} }
}, },
computed: { computed: {