]> git.immae.eu Git - github/bastienwirtz/homer.git/blob - app.js
Add offline cache + improve layout
[github/bastienwirtz/homer.git] / app.js
1 const app = new Vue({
2 el: '#app',
3 data: {
4 config: null,
5 offline: false,
6 filter: '',
7 },
8 created: function () {
9 let that = this;
10
11 this.checkOffline();
12 that.getConfig().then(function (config) {
13 that.config = config;
14 }).catch(function () {
15 that.offline = true;
16 });
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 },
46 }
47 });
48
49 if ('serviceWorker' in navigator) {
50 window.addEventListener('load', function () {
51 navigator.serviceWorker.register('/worker.js');
52 });
53 }