From 9060b87e9479c8da60ad63f8a17995b5210c797d Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 5 Feb 2017 20:46:50 +1300 Subject: [PATCH] client: 'unread' support for the main tab --- client/dcwebui.js | 45 ++++++++++++++++++++++++++++----------------- client/index.htm | 2 +- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/client/dcwebui.js b/client/dcwebui.js index d0317c3..30a9a5a 100644 --- a/client/dcwebui.js +++ b/client/dcwebui.js @@ -402,30 +402,29 @@ var pagevis_currently_visible = true; var pagevis_setup = function(fnActive, fnInactive) { - var h, visibilityChange; - if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support + var h, vc; + if (typeof document.hidden !== "undefined") { h = "hidden"; - visibilityChange = "visibilitychange"; + vc = "visibilitychange"; } else if (typeof document.msHidden !== "undefined") { h = "msHidden"; - visibilityChange = "msvisibilitychange"; + vc = "msvisibilitychange"; } else if (typeof document.webkitHidden !== "undefined") { h = "webkitHidden"; - visibilityChange = "webkitvisibilitychange"; + vc = "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. + // Browser doesn't support Page Visibility API, so behave as if the page is always visible pagevis_currently_visible = true - fnActive(); } else { - document.addEventListener(visibilityChange, function() { + document.addEventListener(vc, function() { if (document[h]) { + pagevis_currently_visible = false; fnInactive(); } else { + pagevis_currently_visible = true; fnActive(); } }); @@ -899,6 +898,17 @@ var transition = function(new_state) { } }; +var tab_is_visible = function(tabref) { + return (last_tab === tabref && pagevis_currently_visible); +} + +var tab_mark_unread = function(tabref) { + if ($("#tabitem-"+tabref).className.indexOf('unread') === -1) { + $("#tabitem-"+tabref).className += " unread"; + updateTitle(); + } +} + window.onload = function() { write("tab-main").system("Communicating with server..."); @@ -975,10 +985,11 @@ window.onload = function() { function() { // We've just become active // If the foreground is a PM window with UNREAD, mark it as read + tab_set(last_tab); }, function() { // We've just become inactive - // ...TODO + // TODO: marker lines } ); @@ -1025,17 +1036,17 @@ window.onload = function() { }); sock.on('pub', function(data) { write("tab-main").pub( data.user, data.message); + + if (! tab_is_visible("tab-main")) { + tab_mark_unread("tab-main"); + } }); sock.on('priv', function(data) { writerFor(data.user).pub(data.user, data.message); - if (last_tab !== pm_tabs[data.user]) { + if (! tab_is_visible(pm_tabs[data.user])) { // Got PM, but tab isn't focused - // Mark tab as unread - if ($("#tabitem-"+pm_tabs[data.user]).className.indexOf('unread') === -1) { - $("#tabitem-"+pm_tabs[data.user]).className += " unread"; - updateTitle(); - } + tab_mark_unread( pm_tabs[data.user] ); if (desktop_notifications_enabled) { notify("Message from " + data.user, data.message); diff --git a/client/index.htm b/client/index.htm index 1ddb118..25ed861 100644 --- a/client/index.htm +++ b/client/index.htm @@ -12,7 +12,7 @@
-
+
Main