From a0a2e919280d42cc69a18cdcce8bd4009cd9dce6 Mon Sep 17 00:00:00 2001 From: Jay2k1 Date: Fri, 1 Jun 2018 19:32:30 +0200 Subject: [PATCH] add highlight count to page title --- client/js/lounge.js | 12 ++---------- client/js/socket-events/msg.js | 2 ++ client/js/utils.js | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index c0facbd6..24bb09da 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -225,21 +225,13 @@ $(function() { .trigger("show"); utils.togglePreviewMoreButtonsIfNeeded(); - - let title = $(document.body).data("app-name"); - const chanTitle = chan.attr("aria-label"); - - if (chanTitle.length > 0) { - title = `${chanTitle} — ${title}`; - } - - document.title = title; + utils.updateTitle(); const type = chan.data("type"); let placeholder = ""; if (type === "channel" || type === "query") { - placeholder = `Write to ${chanTitle}`; + placeholder = `Write to ${chan.attr("aria-label")}`; } input diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index 8fc68462..f83755d4 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -217,5 +217,7 @@ function notifyMessage(targetId, channel, msg) { badge .attr("data-highlight", serverHighlight) .addClass("highlight"); + + utils.updateTitle(); } } diff --git a/client/js/utils.js b/client/js/utils.js index 3b808530..a840804c 100644 --- a/client/js/utils.js +++ b/client/js/utils.js @@ -21,6 +21,7 @@ module.exports = { closeChan, resetHeight, toggleNotificationMarkers, + updateTitle, togglePasswordField, requestIdleCallback, togglePreviewMoreButtonsIfNeeded, @@ -99,6 +100,27 @@ function toggleNotificationMarkers(newState) { viewport.toggleClass("notified", newState); } +function updateTitle() { + let title = $(document.body).data("app-name"); + const chanTitle = $("#sidebar").find(".chan.active").attr("aria-label"); + + if (chanTitle.length > 0) { + title = `${chanTitle} — ${title}`; + } + + // add highlight count to title + let alertEventCount = 0; + $(".badge.highlight").each(function() { + alertEventCount += parseInt($(this).attr("data-highlight")); + }); + + if (alertEventCount > 0) { + title = `(${alertEventCount}) ${title}`; + } + + document.title = title; +} + function togglePasswordField(elem) { $(elem).on("click", function() { const $this = $(this);