Skip to content

Commit

Permalink
set document title without header config
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer committed Aug 31, 2020
1 parent 5135bb4 commit 76d9ca4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
27 changes: 27 additions & 0 deletions core/src/core-api/ux.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
6 changes: 4 additions & 2 deletions core/src/navigation/services/header.js
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -20,6 +20,7 @@ export const processHeaderSettings = component => {
if (!header) {
return;
}

// Set Title and Logo
if (header.title) {
component.set({ defaultTitle: header.title || '' });
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions docs/luigi-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
Expand Down

0 comments on commit 76d9ca4

Please sign in to comment.