From cc5da9b9c378653b88b2d7a0cedfee361a7624a8 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Wed, 10 Jun 2020 15:47:41 -0400 Subject: [PATCH] Add endpoints to customize or disable iD's changing of the document title (close #7503) Use the initial title as the default base title --- modules/behavior/hash.js | 4 +++- modules/core/context.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index fad6d43cf..d68bb6c22 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -49,7 +49,7 @@ export function behaviorHash(context) { function computedTitle(includeChangeCount) { - var baseTitle = 'iD'; + var baseTitle = context.documentTitleBase() || 'iD'; var contextual; var changeCount; var titleID; @@ -89,6 +89,8 @@ export function behaviorHash(context) { } function updateTitle(includeChangeCount) { + if (!context.setsDocumentTitle()) return; + var newTitle = computedTitle(includeChangeCount); if (document.title !== newTitle) { document.title = newTitle; diff --git a/modules/core/context.js b/modules/core/context.js index 0b54db23a..011960358 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -58,6 +58,24 @@ export function coreContext() { return context; }; + /* Document title */ + /* (typically shown as the label for the browser window/tab) */ + + // If true, iD will update the title based on what the user is doing + let _setsDocumentTitle = true; + context.setsDocumentTitle = function(val) { + if (!arguments.length) return _setsDocumentTitle; + _setsDocumentTitle = val; + return context; + }; + // The part of the title that is always the same + let _documentTitleBase = document.title; + context.documentTitleBase = function(val) { + if (!arguments.length) return _documentTitleBase; + _documentTitleBase = val; + return context; + }; + /* User interface and keybinding */ let _ui;