]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - app.js
Add offline cache + improve layout
[github/bastienwirtz/homer.git] / app.js
CommitLineData
9baec9ae 1const app = new Vue({
09763dbf
BW
2 el: '#app',
3 data: {
4 config: null,
9baec9ae
BW
5 offline: false,
6 filter: '',
09763dbf 7 },
9baec9ae 8 created: function () {
9ca12a40
BW
9 let that = this;
10
9baec9ae
BW
11 this.checkOffline();
12 that.getConfig().then(function (config) {
09763dbf 13 that.config = config;
9ca12a40 14 }).catch(function () {
9baec9ae 15 that.offline = true;
09763dbf 16 });
9baec9ae
BW
17
18 document.addEventListener('visibilitychange', function () {
19 if (document.visibilityState == "visible") {
20 that.checkOffline();
21 }
22 }, false);
23 },
24 methods: {
25 checkOffline: function () {
26 let that = this;
27 return fetch(window.location.href + "?alive", {
28 method: 'HEAD',
29 cache: 'no-store'
30 }).then(function () {
31 that.offline = false;
32 }).catch(function () {
33 that.offline = true;
34 });
35 },
36 getConfig: function (event) {
37 return fetch('config.yml').then(function (response) {
38 if (response.status != 200) {
39 return
40 }
41 return response.text().then(function (body) {
42 return jsyaml.load(body);
43 });
44 });
45 },
09763dbf
BW
46 }
47});
48
9baec9ae
BW
49if ('serviceWorker' in navigator) {
50 window.addEventListener('load', function () {
51 navigator.serviceWorker.register('/worker.js');
09763dbf 52 });
e41196e7 53}