homer/app.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-02-18 09:23:20 +01:00
const app = new Vue({
2018-06-14 07:14:05 +02:00
el: '#app',
data: {
config: null,
2019-02-18 09:23:20 +01:00
offline: false,
filter: '',
2018-06-14 07:14:05 +02:00
},
2019-02-18 09:23:20 +01:00
created: function () {
2018-06-17 00:48:28 +02:00
let that = this;
2019-02-18 09:23:20 +01:00
this.checkOffline();
that.getConfig().then(function (config) {
2018-06-14 07:14:05 +02:00
that.config = config;
2018-06-17 00:48:28 +02:00
}).catch(function () {
2019-02-18 09:23:20 +01:00
that.offline = true;
2018-06-14 07:14:05 +02:00
});
2019-02-18 09:23:20 +01:00
document.addEventListener('visibilitychange', function () {
if (document.visibilityState == "visible") {
that.checkOffline();
}
}, false);
},
methods: {
checkOffline: function () {
let that = this;
return fetch(window.location.href + "?alive", {
method: 'HEAD',
cache: 'no-store'
}).then(function () {
that.offline = false;
}).catch(function () {
that.offline = true;
});
},
getConfig: function (event) {
return fetch('config.yml').then(function (response) {
if (response.status != 200) {
return
}
return response.text().then(function (body) {
return jsyaml.load(body);
});
});
},
2018-06-14 07:14:05 +02:00
}
});
2019-02-18 09:23:20 +01:00
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/worker.js');
2018-06-14 07:14:05 +02:00
});
2018-11-13 06:14:38 +01:00
}