-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffline.js
30 lines (26 loc) · 869 Bytes
/
offline.js
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
(function () {
'use strict';
var headerElement = document.querySelector('header');
var metaTagTheme = document.querySelector('meta[name=theme-color]');
//After DOM Loaded
document.addEventListener('DOMContentLoaded', function(event) {
//On initial load to check connectivity
if (!navigator.onLine) {
updateNetworkStatus();
}
window.addEventListener('online', updateNetworkStatus, false);
window.addEventListener('offline', updateNetworkStatus, false);
});
//To update network status
function updateNetworkStatus() {
if (navigator.onLine) {
metaTagTheme.setAttribute('content', '#0288d1');
headerElement.classList.remove('app__offline');
}
else {
toast('App is offline');
metaTagTheme.setAttribute('content', '#6b6b6b');
headerElement.classList.add('app__offline');
}
}
})();