From 0951bf821ed072a66e1f6f4fe0f71c3b9749c98d Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 5 Feb 2017 19:59:43 +1300 Subject: [PATCH] client: page visibility detection infrastructure (but it doesn't do anything yet) --- client/dcwebui.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/client/dcwebui.js b/client/dcwebui.js index 7b0ac18..2dab036 100644 --- a/client/dcwebui.js +++ b/client/dcwebui.js @@ -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")) {