From 68c7a88fed87329292de5788925c07b0be07a435 Mon Sep 17 00:00:00 2001 From: Pablo Vazquez Date: Thu, 5 Oct 2017 14:58:54 +0200 Subject: [PATCH] Use the nifty new DocumentTitleAPI to update notification count and page titles when browsing assets. This removes the need for updateTitle() --- src/scripts/tutti/0_navbar.js | 10 ---------- src/scripts/tutti/5_1_notifications.js | 11 ++++------- src/templates/nodes/edit_embed.pug | 5 +++-- src/templates/projects/view.pug | 7 +++---- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/scripts/tutti/0_navbar.js b/src/scripts/tutti/0_navbar.js index 2e65c28c..cb64a5f3 100644 --- a/src/scripts/tutti/0_navbar.js +++ b/src/scripts/tutti/0_navbar.js @@ -31,16 +31,6 @@ var DocumentTitleAPI = { }, }; -var page_title = document.title; - -function updateTitle(unread_on_load, page_title){ - - if (unread_on_load > 0){ - document.title = '(' + unread_on_load + ') ' + page_title; - } else { - document.title = page_title; - } -} /* Status Bar */ function statusBarClear(delay_class, delay_html){ diff --git a/src/scripts/tutti/5_1_notifications.js b/src/scripts/tutti/5_1_notifications.js index ac2ef93d..5cd5f248 100644 --- a/src/scripts/tutti/5_1_notifications.js +++ b/src/scripts/tutti/5_1_notifications.js @@ -98,9 +98,8 @@ function getNotifications(){ $notifications_count.html('' + unread_new + ''); $notifications_toggle.addClass('has-notifications'); - // Let Pillar know the notifications total has been updated. - // Used for example to update of the page title via updateTitle(); - $('body').trigger('pillar:notifications-total-updated', unread_new); + // Update notifications count on the document title + DocumentTitleAPI.set_notification_count(unread_new); } else { clearNotificationIcon(); @@ -328,11 +327,9 @@ $(function() { clearNotificationIcon(); - unread_on_load = 0; + // Update notifications count on the document title + DocumentTitleAPI.set_notification_count(0); - // Let Pillar know the notifications total has been updated. - // Used for example to update of the page title via updateTitle(); - $('body').trigger('pillar:notifications-total-updated', unread_on_load); }); }); diff --git a/src/templates/nodes/edit_embed.pug b/src/templates/nodes/edit_embed.pug index db0ead7a..f807106f 100644 --- a/src/templates/nodes/edit_embed.pug +++ b/src/templates/nodes/edit_embed.pug @@ -87,8 +87,9 @@ script(type="text/javascript"). $(function () { $('#tags').select2(); - page_title = 'Edit: {{ node.name }} — {{ project.name }}'; - updateTitle(unread_on_load, page_title); + // Set the page title on the document + var page_title = 'Edit: {{ node.name }} - {{ project.name }} — Blender Cloud'; + DocumentTitleAPI.set_page_title(page_title); /* Build the markdown preview when typing in textarea */ var convert = new Markdown.getSanitizingConverter(); diff --git a/src/templates/projects/view.pug b/src/templates/projects/view.pug index 05203fe8..29dbd0dc 100644 --- a/src/templates/projects/view.pug +++ b/src/templates/projects/view.pug @@ -340,10 +340,9 @@ script. updateToggleProjHeaderMenuItem(); - var nodeTitle = document.getElementById('node-title'); - page_title = $(nodeTitle).text() + " - {{ project.name }} - Blender Cloud"; - - updateTitle(unread_on_load, page_title); + // Set the page title on the document + var page_title = $('#node-title').text() + " - {{ project.name }} — Blender Cloud"; + DocumentTitleAPI.set_page_title(page_title); // TODO: Maybe remove this, now it's also in loadNodeContent(), but double-check // it's done like that in all users of updateUi().