From 514bff706515ad7bf8cf566b005686e3b3fdd276 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 8 Sep 2017 18:21:11 +0200 Subject: [PATCH] Add slide number in the title in slide2 --- www/common/sframe-common-outer.js | 18 +++++++++++++++++- www/common/sframe-common-title.js | 1 - www/common/sframe-common.js | 3 +++ www/common/sframe-protocol.js | 6 ++++++ www/slide/inner.js | 14 +------------- www/slide/slide.js | 1 + 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index b7bb1c21b..1041884b5 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -107,12 +107,28 @@ define([ }); }); + var currentTitle; + var currentTabTitle; + var setDocumentTitle = function () { + if (!currentTabTitle) { + document.title = currentTitle || 'CryptPad'; + return; + } + var title = currentTabTitle.replace(/\{title\}/g, currentTitle || 'CryptPad'); + document.title = title; + }; sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) { - document.title = newTitle; + currentTitle = newTitle; + setDocumentTitle(); Cryptpad.renamePad(newTitle, undefined, function (err) { if (err) { cb('ERROR'); } else { cb(); } }); }); + sframeChan.on('EV_SET_TAB_TITLE', function (newTabTitle) { + currentTabTitle = newTabTitle; + setDocumentTitle(); + }); + sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) { Cryptpad.setDisplayName(newName, function (err) { diff --git a/www/common/sframe-common-title.js b/www/common/sframe-common-title.js index 4766ea369..61a5fb46e 100644 --- a/www/common/sframe-common-title.js +++ b/www/common/sframe-common-title.js @@ -32,7 +32,6 @@ define(['jquery'], function ($) { } }; - // update title: href is optional; if not specified, we use window.location.href exp.updateTitle = function (newTitle, cb) { cb = cb || $.noop; if (newTitle === exp.title) { return; } diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index e42f32236..1a70446f9 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -83,6 +83,9 @@ define([ funcs.notify = function () { ctx.sframeChan.event('EV_NOTIFY'); }; + funcs.setTabTitle = function (newTitle) { + ctx.sframeChan.event('EV_SET_TAB_TITLE', newTitle); + }; funcs.setLoginRedirect = function (cb) { cb = cb || $.noop; diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index 1afba7820..4e2be59ec 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -43,7 +43,13 @@ define({ // This changes the pad title in drive ONLY, the pad title needs to be changed inside of the // iframe and synchronized with the other users. This will not trigger a EV_METADATA_UPDATE // because the metadata contained in EV_METADATA_UPDATE does not contain the pad title. + // It also sets the page (tab) title to the selected title, unles it is overridden by + // the EV_SET_TAB_TITLE event. 'Q_SET_PAD_TITLE_IN_DRIVE': true, + // Set the page title (tab title) to the selected value which will override the pad title. + // The new title value can contain {title}, which will be replaced by the pad title when it + // is set or modified. + 'EV_SET_TAB_TITLE': true, // Update the user's display-name which will be shown to contacts and people in the same pads. 'Q_SETTINGS_SET_DISPLAY_NAME': true, diff --git a/www/slide/inner.js b/www/slide/inner.js index b822d94e6..a4092ae0e 100644 --- a/www/slide/inner.js +++ b/www/slide/inner.js @@ -124,16 +124,6 @@ define([ } }; - var setTabTitle = function (title) { - console.error('TODO'); // TODO iframe - return; - var slideNumber = ''; - if (Slide.shown) { //Slide.index && Slide.content.length) { - slideNumber = ' (' + Slide.index + '/' + Slide.content.length + ')'; - } - document.title = title + slideNumber; - }; - var $contentContainer = $('#cp-app-slide-editor'); var $modal = $('#cp-app-slide-modal'); var $content = $('#cp-app-slide-modal-content'); @@ -593,15 +583,13 @@ define([ }); Slide.onChange(function (o, n, l) { - console.log('TODO: remove that part?'); var slideNumber = ''; if (n !== null) { if (Slide.shown) { slideNumber = ' (' + (++n) + '/' + l + ')'; } } - // TODO iframe - document.title = Title.title + slideNumber; + common.setTabTitle('{title}' + slideNumber); }); setEditable(!readOnly); diff --git a/www/slide/slide.js b/www/slide/slide.js index 3b75c87a7..91181964f 100644 --- a/www/slide/slide.js +++ b/www/slide/slide.js @@ -128,6 +128,7 @@ define([ updateFontSize(); return; } + Common.setTabTitle(); // Remove the slide number from the title Common.setPresentUrl(false); change(Slide.index, null); $('.cp-app-slide-present-button').show();