client: 'unread' support for the main tab
This commit is contained in:
parent
78b7af7fbc
commit
9060b87e94
@ -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);
|
||||
|
@ -12,7 +12,7 @@
|
||||
<body>
|
||||
<div class="tabbar placement-top" id="bar">
|
||||
<div class="menubutton" id="menubutton">☰</div>
|
||||
<div class="tabitem selected" data-tab="tab-main">
|
||||
<div class="tabitem selected" data-tab="tab-main" id="tabitem-tab-main">
|
||||
<span class="tab-label">
|
||||
Main
|
||||
</span>
|
||||
|
Loading…
Reference in New Issue
Block a user