From f9e10976b8e203ed1a144541ecd9b020a73dfbe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 5 Oct 2017 12:45:50 +0200 Subject: [PATCH] Added a little DocumentTitleAPI object for easier updating of the title. --- src/scripts/tutti/0_navbar.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/scripts/tutti/0_navbar.js b/src/scripts/tutti/0_navbar.js index e45cceae..2e65c28c 100644 --- a/src/scripts/tutti/0_navbar.js +++ b/src/scripts/tutti/0_navbar.js @@ -1,3 +1,36 @@ +/** + * Little API for managing the document title. + * + * This allows the document title to be composed of individually adjustable + * properties. + */ +var DocumentTitleAPI = { + // Properties that make up the document title: + page_title: document.title, + notification_count: 0, + + // Updates the page title given the current state. + update: function() { + if (this.notification_count > 0){ + document.title = '(' + this.notification_count + ') ' + this.page_title; + } else { + document.title = this.page_title; + } + }, + + // Sets just the notification count and updates the document title. + set_notification_count: function(new_notif_count) { + this.notification_count = new_notif_count; + this.update(); + }, + + // Sets just the page title and updates the document title. + set_page_title: function(new_page_title) { + this.page_title = new_page_title; + this.update(); + }, +}; + var page_title = document.title; function updateTitle(unread_on_load, page_title){