forked from primefaces/primevue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.vue
80 lines (70 loc) · 2.41 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<template>
<NuxtLayout :name="layout">
<NuxtPage />
</NuxtLayout>
</template>
<script>
import EventBus from '@/layouts/AppEventBus';
import News from '@/assets/data/news.json';
export default {
themeChangeListener: null,
newsActivate: null,
data() {
return {
layout: 'custom'
};
},
watch: {
$route: {
immediate: true,
handler(to) {
if (to.name === 'index') {
this.layout = 'custom';
} else {
this.layout = 'default';
}
}
}
},
mounted() {
this.newsActivate = () => {
this.$appState.announcement = News;
const itemString = localStorage.getItem(this.$appState.storageKey);
if (itemString) {
const item = JSON.parse(itemString);
if (!item.hiddenNews || item.hiddenNews !== News.id)
this.$appState.newsActive = true;
else this.$appState.newsActive = false;
}
else {
this.$appState.newsActive = true;
}
};
this.themeChangeListener = (event) => {
const elementId = 'theme-link';
const linkElement = document.getElementById(elementId);
const cloneLinkElement = linkElement.cloneNode(true);
const newThemeUrl = linkElement.getAttribute('href').replace(this.$appState.theme, event.theme);
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.$appState.theme = event.theme;
this.$appState.darkTheme = event.dark;
};
EventBus.on('theme-change', this.themeChangeListener);
EventBus.on('news-activate', this.newsActivate);
},
beforeUnmount() {
EventBus.off('theme-change', this.themeChangeListener);
EventBus.off('news-activate', this.newsActivate);
}
};
</script>
<style lang="scss">
@import '@/assets/styles/landing/landing.scss';
@import '@/assets/styles/app/app.scss';
</style>