mirror of
https://github.com/flarum/framework.git
synced 2025-05-22 14:49:57 +08:00
Add an API to show a count in the document title
This commit is contained in:
@ -184,6 +184,7 @@ export default class DiscussionPage extends mixin(Component, evented) {
|
|||||||
this.discussion = discussion;
|
this.discussion = discussion;
|
||||||
|
|
||||||
app.setTitle(discussion.title());
|
app.setTitle(discussion.title());
|
||||||
|
app.setTitleCount(0);
|
||||||
|
|
||||||
// When the API responds with a discussion, it will also include a number of
|
// When the API responds with a discussion, it will also include a number of
|
||||||
// posts. Some of these posts are included because they are on the first
|
// posts. Some of these posts are included because they are on the first
|
||||||
|
@ -96,6 +96,7 @@ export default class IndexPage extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.setTitle('');
|
app.setTitle('');
|
||||||
|
app.setTitleCount(0);
|
||||||
|
|
||||||
// Work out the difference between the height of this hero and that of the
|
// Work out the difference between the height of this hero and that of the
|
||||||
// previous hero. Maintain the same scroll position relative to the bottom
|
// previous hero. Maintain the same scroll position relative to the bottom
|
||||||
|
@ -107,6 +107,9 @@ export default class App {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.requestError = null;
|
this.requestError = null;
|
||||||
|
|
||||||
|
this.title = '';
|
||||||
|
this.titleCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,10 +142,29 @@ export default class App {
|
|||||||
* Set the <title> of the page.
|
* Set the <title> of the page.
|
||||||
*
|
*
|
||||||
* @param {String} title
|
* @param {String} title
|
||||||
|
* @param {Boolean} [separator] Whether or not to separate the given title and
|
||||||
|
* the forum's title.
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
setTitle(title) {
|
setTitle(title) {
|
||||||
document.title = (title ? title + ' - ' : '') + this.forum.attribute('title');
|
this.title = title;
|
||||||
|
this.updateTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a number to display in the <title> of the page.
|
||||||
|
*
|
||||||
|
* @param {Integer} count
|
||||||
|
*/
|
||||||
|
setTitleCount(count) {
|
||||||
|
this.titleCount = count;
|
||||||
|
this.updateTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTitle() {
|
||||||
|
document.title = (this.titleCount ? `(${this.titleCount}) ` : '') +
|
||||||
|
(this.title ? this.title + ' - ' : '') +
|
||||||
|
this.forum.attribute('title');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user