]>
Commit | Line | Data |
---|---|---|
9baec9ae | 1 | const app = new Vue({ |
09763dbf BW |
2 | el: '#app', |
3 | data: { | |
4 | config: null, | |
9baec9ae BW |
5 | offline: false, |
6 | filter: '', | |
5323df4a | 7 | vlayout: true, |
d6adb2db | 8 | isDark: null |
09763dbf | 9 | }, |
7fd9dc6f | 10 | created: async function () { |
9ca12a40 | 11 | let that = this; |
7fd9dc6f | 12 | |
a489a0a3 | 13 | this.isDark = 'overrideDark' in localStorage ? |
d6adb2db | 14 | JSON.parse(localStorage.overrideDark) : matchMedia("(prefers-color-scheme: dark)").matches; |
9ca12a40 | 15 | |
d6adb2db BW |
16 | if ('vlayout' in localStorage) { |
17 | this.vlayout = JSON.parse(localStorage.vlayout) | |
18 | } | |
a489a0a3 | 19 | |
9baec9ae | 20 | this.checkOffline(); |
7fd9dc6f BW |
21 | try { |
22 | this.config = await this.getConfig(); | |
23 | } catch (error) { | |
24 | this.offline = true; | |
25 | } | |
26 | ||
27 | // Look for a new message if an endpoint is provided. | |
d5ef84f5 | 28 | if (this.config.message && this.config.message.url) { |
7fd9dc6f BW |
29 | this.getMessage(this.config.message.url).then(function(message){ |
30 | // keep the original config value if no value is provided by the endpoint | |
31 | for (const prop of ['title','style','content']) { | |
32 | if (prop in message && message[prop] !== null) { | |
33 | that.config.message[prop] = message[prop]; | |
34 | } | |
35 | } | |
36 | }); | |
37 | } | |
9baec9ae BW |
38 | |
39 | document.addEventListener('visibilitychange', function () { | |
40 | if (document.visibilityState == "visible") { | |
41 | that.checkOffline(); | |
42 | } | |
43 | }, false); | |
44 | }, | |
45 | methods: { | |
46 | checkOffline: function () { | |
47 | let that = this; | |
48 | return fetch(window.location.href + "?alive", { | |
49 | method: 'HEAD', | |
50 | cache: 'no-store' | |
51 | }).then(function () { | |
52 | that.offline = false; | |
53 | }).catch(function () { | |
54 | that.offline = true; | |
55 | }); | |
56 | }, | |
57 | getConfig: function (event) { | |
58 | return fetch('config.yml').then(function (response) { | |
59 | if (response.status != 200) { | |
60 | return | |
61 | } | |
62 | return response.text().then(function (body) { | |
63 | return jsyaml.load(body); | |
64 | }); | |
65 | }); | |
66 | }, | |
7fd9dc6f BW |
67 | getMessage: function (url) { |
68 | return fetch(url).then(function (response) { | |
69 | if (response.status != 200) { | |
70 | return; | |
71 | } | |
72 | return response.json(); | |
73 | }); | |
74 | }, | |
5323df4a | 75 | toggleTheme: function() { |
d6adb2db BW |
76 | this.isDark = !this.isDark; |
77 | localStorage.overrideDark = this.isDark; | |
78 | }, | |
79 | toggleLayout: function() { | |
80 | this.vlayout = !this.vlayout; | |
a489a0a3 FB |
81 | localStorage.vlayout = this.vlayout; |
82 | }, | |
09763dbf BW |
83 | } |
84 | }); | |
85 | ||
4877ec98 BW |
86 | Vue.component('service', { |
87 | props: ['item'], | |
88 | template: `<div> | |
89 | <div class="card"> | |
56c69e0d | 90 | <a :href="item.url" :target="item.target"> |
4877ec98 BW |
91 | <div class="card-content"> |
92 | <div class="media"> | |
93 | <div v-if="item.logo" class="media-left"> | |
94 | <figure class="image is-48x48"> | |
95 | <img :src="item.logo" /> | |
96 | </figure> | |
97 | </div> | |
98 | <div v-if="item.icon" class="media-left"> | |
99 | <figure class="image is-48x48"> | |
100 | <i style="font-size: 35px" :class="item.icon"></i> | |
101 | </figure> | |
102 | </div> | |
103 | <div class="media-content"> | |
104 | <p class="title is-4">{{ item.name }}</p> | |
105 | <p class="subtitle is-6">{{ item.subtitle }}</p> | |
106 | </div> | |
107 | </div> | |
a2fdb8a9 | 108 | <div class="tag" :class="item.tagstyle" v-if="item.tag"> |
109 | <strong class="tag-text">#{{ item.tag }}</strong> | |
110 | </div> | |
4877ec98 BW |
111 | </div> |
112 | </a> | |
113 | </div></div>` | |
114 | }); | |
115 | ||
9baec9ae BW |
116 | if ('serviceWorker' in navigator) { |
117 | window.addEventListener('load', function () { | |
a489a0a3 | 118 | navigator.serviceWorker.register('worker.js'); |
09763dbf | 119 | }); |
e41196e7 | 120 | } |