client: page visibility detection infrastructure (but it doesn't do anything yet)

This commit is contained in:
mappu 2017-02-05 19:59:43 +13:00
parent a60e4bb0c2
commit 0951bf821e

View File

@ -396,6 +396,42 @@ var submit = function() {
$("#chatbox").value = '';
};
/* page visibility */
var pagevis_currently_visible = true;
var pagevis_setup(fnActive, fnInactive) {
var h, visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
h = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.msHidden !== "undefined") {
h = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
h = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
// Warn if the browser doesn't support addEventListener or the Page Visibility API
if (typeof document[h] === "undefined") {
// Browser doesn't support Page Visibility API
// Behave as if the page is always visible.
pagevis_currently_visible = true
fnActive();
} else {
document.addEventListener(visibilityChange, function() {
if (document[h]) {
fnInactive();
} else {
fnActive();
}
});
}
}
/* tabs */
/**
@ -929,6 +965,17 @@ window.onload = function() {
tab_addHandlers();
pagevis_currently_visible(
function() {
// We've just become active
// If the foreground is a PM window with UNREAD, mark it as read
},
function() {
// We've just become inactive
// ...TODO
}
);
// Hacks for WiiU user-agent
if (navigator && navigator.userAgent && !!navigator.userAgent.match("Nintendo WiiU")) {