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 pagevis_setup = function(fnActive, fnInactive) {
|
||||||
|
|
||||||
var h, visibilityChange;
|
var h, vc;
|
||||||
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
|
if (typeof document.hidden !== "undefined") {
|
||||||
h = "hidden";
|
h = "hidden";
|
||||||
visibilityChange = "visibilitychange";
|
vc = "visibilitychange";
|
||||||
} else if (typeof document.msHidden !== "undefined") {
|
} else if (typeof document.msHidden !== "undefined") {
|
||||||
h = "msHidden";
|
h = "msHidden";
|
||||||
visibilityChange = "msvisibilitychange";
|
vc = "msvisibilitychange";
|
||||||
} else if (typeof document.webkitHidden !== "undefined") {
|
} else if (typeof document.webkitHidden !== "undefined") {
|
||||||
h = "webkitHidden";
|
h = "webkitHidden";
|
||||||
visibilityChange = "webkitvisibilitychange";
|
vc = "webkitvisibilitychange";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warn if the browser doesn't support addEventListener or the Page Visibility API
|
|
||||||
if (typeof document[h] === "undefined") {
|
if (typeof document[h] === "undefined") {
|
||||||
// Browser doesn't support Page Visibility API
|
// Browser doesn't support Page Visibility API, so behave as if the page is always visible
|
||||||
// Behave as if the page is always visible.
|
|
||||||
pagevis_currently_visible = true
|
pagevis_currently_visible = true
|
||||||
fnActive();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
document.addEventListener(visibilityChange, function() {
|
document.addEventListener(vc, function() {
|
||||||
if (document[h]) {
|
if (document[h]) {
|
||||||
|
pagevis_currently_visible = false;
|
||||||
fnInactive();
|
fnInactive();
|
||||||
} else {
|
} else {
|
||||||
|
pagevis_currently_visible = true;
|
||||||
fnActive();
|
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() {
|
window.onload = function() {
|
||||||
write("tab-main").system("Communicating with server...");
|
write("tab-main").system("Communicating with server...");
|
||||||
|
|
||||||
@ -975,10 +985,11 @@ window.onload = function() {
|
|||||||
function() {
|
function() {
|
||||||
// We've just become active
|
// We've just become active
|
||||||
// If the foreground is a PM window with UNREAD, mark it as read
|
// If the foreground is a PM window with UNREAD, mark it as read
|
||||||
|
tab_set(last_tab);
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
// We've just become inactive
|
// We've just become inactive
|
||||||
// ...TODO
|
// TODO: marker lines
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1025,17 +1036,17 @@ window.onload = function() {
|
|||||||
});
|
});
|
||||||
sock.on('pub', function(data) {
|
sock.on('pub', function(data) {
|
||||||
write("tab-main").pub( data.user, data.message);
|
write("tab-main").pub( data.user, data.message);
|
||||||
|
|
||||||
|
if (! tab_is_visible("tab-main")) {
|
||||||
|
tab_mark_unread("tab-main");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
sock.on('priv', function(data) {
|
sock.on('priv', function(data) {
|
||||||
writerFor(data.user).pub(data.user, data.message);
|
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
|
// Got PM, but tab isn't focused
|
||||||
|
|
||||||
// Mark tab as unread
|
tab_mark_unread( pm_tabs[data.user] );
|
||||||
if ($("#tabitem-"+pm_tabs[data.user]).className.indexOf('unread') === -1) {
|
|
||||||
$("#tabitem-"+pm_tabs[data.user]).className += " unread";
|
|
||||||
updateTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (desktop_notifications_enabled) {
|
if (desktop_notifications_enabled) {
|
||||||
notify("Message from " + data.user, data.message);
|
notify("Message from " + data.user, data.message);
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="tabbar placement-top" id="bar">
|
<div class="tabbar placement-top" id="bar">
|
||||||
<div class="menubutton" id="menubutton">☰</div>
|
<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">
|
<span class="tab-label">
|
||||||
Main
|
Main
|
||||||
</span>
|
</span>
|
||||||
|
Loading…
Reference in New Issue
Block a user