Skip to content

Commit 0b2e486

Browse files
committed
added handling for offline events/icon
1 parent a3a0b2b commit 0b2e486

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

web/js/blog.js

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"use strict";
33

44
var offlineIcon;
5+
var isOnline = ("onLine" in navigator) && navigator.onLine;
56
var isLoggedIn = /isLoggedIn=1/.test(document.cookie.toString() || "");
67

78
document.addEventListener("DOMContentLoaded",ready,false);
@@ -11,6 +12,19 @@
1112

1213
function ready() {
1314
offlineIcon = document.getElementById("connectivity-status");
15+
16+
if (!isOnline) {
17+
offlineIcon.classList.remove("hidden");
18+
}
19+
20+
window.addEventListener("online",function online(){
21+
offlineIcon.classList.add("hidden");
22+
isOnline = true;
23+
},false);
24+
window.addEventListener("offline",function offline(){
25+
offlineIcon.classList.remove("hidden");
26+
isOnline = false;
27+
},false);
1428
}
1529

1630
})();

0 commit comments

Comments
 (0)