Ghost/ghost/admin/app/utils/document-title.js
Kevin Ansfield 89b7ff3320 Routable tags
refs #5845
- Updates tag settings screen to match content screen behaviour. Each now tag has it's own route that is link-able from other areas of the app
- Updates a number of places where jQuery event handler code was not wrapped in Ember's run loop
2015-10-27 12:48:41 +00:00

57 lines
1.8 KiB
JavaScript

import Ember from 'ember';
export default function () {
Ember.Route.reopen({
// `titleToken` can either be a static string or a function
// that accepts a model object and returns a string (or array
// of strings if there are multiple tokens).
titleToken: null,
// `title` can either be a static string or a function
// that accepts an array of tokens and returns a string
// that will be the document title. The `collectTitleTokens` action
// stops bubbling once a route is encountered that has a `title`
// defined.
title: null,
_actions: {
collectTitleTokens: function (tokens) {
var titleToken = this.titleToken,
finalTitle;
if (typeof this.titleToken === 'function') {
titleToken = this.titleToken(this.currentModel);
}
if (Ember.isArray(titleToken)) {
tokens.unshift.apply(this, titleToken);
} else if (titleToken) {
tokens.unshift(titleToken);
}
if (this.title) {
if (typeof this.title === 'function') {
finalTitle = this.title(tokens);
} else {
finalTitle = this.title;
}
this.router.setTitle(finalTitle);
} else {
return true;
}
}
}
});
Ember.Router.reopen({
updateTitle: Ember.on('didTransition', function () {
this.send('collectTitleTokens', []);
}),
setTitle: function (title) {
window.document.title = title;
}
});
}