From 76d9ca4d18344e1cd5c35986a820b3b6621a5df7 Mon Sep 17 00:00:00 2001 From: JohannesDoberer Date: Mon, 31 Aug 2020 15:37:56 +0200 Subject: [PATCH] set document title without header config --- core/src/core-api/ux.js | 27 ++++++++++++++++++++ core/src/navigation/services/header.js | 6 +++-- docs/luigi-core-api.md | 34 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/core/src/core-api/ux.js b/core/src/core-api/ux.js index 3c41529ff8..61354dd771 100644 --- a/core/src/core-api/ux.js +++ b/core/src/core-api/ux.js @@ -1,10 +1,14 @@ import { APP_LOADING_INDICATOR } from './../utilities/constants'; import { GenericHelpers } from '../utilities/helpers'; +import { get, writable } from 'svelte/store'; /** * Functions to use Luigi Core UX features. * @namespace UX */ class LuigiUX { + constructor() { + this.documentTitle = writable(); + } /** * Hides the app loading indicator. * @memberof UX @@ -99,6 +103,29 @@ class LuigiUX { ); } } + + /** + * Set the document title + * @memberof UX + * @param {string} documentTitle + * @since NEXTRELEASE + * @example Luigi.ux().setDocumentTitle('Luigi'); + */ + setDocumentTitle(documentTitle) { + this.documentTitle.set(documentTitle); + Luigi.configChanged('settings.header'); + } + + /** + * Get the document title + * @memberof UX + * @since NEXTRELEASE + * @returns a string, which is displayed in the tab. + * @example Luigi.ux().getDocumentTitle(); + */ + getDocumentTitle() { + return get(this.documentTitle); + } } export const ux = new LuigiUX(); diff --git a/core/src/navigation/services/header.js b/core/src/navigation/services/header.js index 4ed6b873b7..57dddf5146 100644 --- a/core/src/navigation/services/header.js +++ b/core/src/navigation/services/header.js @@ -1,5 +1,5 @@ import { StateHelpers, GenericHelpers } from '../../utilities/helpers'; -import { LuigiConfig, LuigiI18N } from './../../core-api'; +import { LuigiConfig, LuigiI18N, LuigiUX } from './../../core-api'; export const processHeaderSettings = component => { StateHelpers.doOnStoreChange( @@ -20,6 +20,7 @@ export const processHeaderSettings = component => { if (!header) { return; } + // Set Title and Logo if (header.title) { component.set({ defaultTitle: header.title || '' }); @@ -124,8 +125,9 @@ export const updateTitle = component => { selectedItem && selectedItem.title ? selectedItem.title : component.get().defaultTitle; + const documentTitle = LuigiUX.getDocumentTitle() || title; component.set({ title }); - document.title = LuigiI18N.getTranslation(title); + document.title = LuigiI18N.getTranslation(documentTitle); const subTitle = selectedItem ? selectedItem.subTitle || '' : component.get().defaultSubTitle; diff --git a/docs/luigi-core-api.md b/docs/luigi-core-api.md index 09b3a770f2..d90dbc32db 100644 --- a/docs/luigi-core-api.md +++ b/docs/luigi-core-api.md @@ -799,6 +799,40 @@ Returns **[promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/ - **since**: 0.6.4 +#### setDocumentTitle + +Set the document title + +##### Parameters + +- `documentTitle` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** + +##### Examples + +```javascript +Luigi.ux().setDocumentTitle('Luigi'); +``` + +**Meta** + +- **since**: NEXTRELEASE + +#### getDocumentTitle + +Get the document title + +##### Examples + +```javascript +Luigi.ux().getDocumentTitle(); +``` + +Returns **any** a string, which is displayed in the tab. + +**Meta** + +- **since**: NEXTRELEASE + ## Luigi.globalSearch()