set page title at router controller level

This commit is contained in:
Sacha Greif 2014-12-11 12:38:53 +09:00
parent 4155fb22a1
commit 09885700b0
5 changed files with 36 additions and 9 deletions

View file

@ -106,7 +106,7 @@
<template name="afCheckbox_telescope">
<div class="checkbox">
<label>
<input type="checkbox" value="{{this.value}}" {{atts}} />aaaa
<input type="checkbox" value="{{this.value}}" {{atts}} />
</label>
</div>
</template>

View file

@ -115,10 +115,9 @@ Router._filters = {
},
setTitle: function() {
// set title
var title = getSetting("title");
var tagline = getSetting("tagline");
document.title = (tagline ? title+': '+tagline : title) || "";
// if getTitle is set, use it. Otherwise default to site title.
var title = (typeof this.getTitle === 'function') ? this.getTitle() : getSetting("title", "");
document.title = title;
}
};

View file

@ -7,7 +7,9 @@ var getDefaultViewController = function () {
// Controller for all posts lists
PostsListController = RouteController.extend({
template: getTemplate('posts_list'),
subscriptions: function () {
// take the first segment of the path to get the view, unless it's '/' in which case the view default to 'top'
// note: most of the time this.params.slug will be empty
@ -24,6 +26,7 @@ PostsListController = RouteController.extend({
this.postsListSub = coreSubscriptions.subscribe('postsList', this._terms);
this.postsListUsersSub = coreSubscriptions.subscribe('postsListUsers', this._terms);
},
data: function () {
this._terms = {
view: this.view,
@ -54,9 +57,15 @@ PostsListController = RouteController.extend({
ready: this.postsListSub.ready
};
},
getTitle: function () {
return i18n.t(this.view) + ' - ' + getSetting('title');
},
onAfterAction: function() {
Session.set('view', this.view);
},
fastRender: true
});
@ -96,6 +105,10 @@ PostPageController = RouteController.extend({
return Posts.findOne(this.params._id);
},
getTitle: function () {
return this.post().title + ' - ' + getSetting('title');
},
onBeforeAction: function() {
if (! this.post()) {
if (this.postSubscription.ready()) {

View file

@ -8,10 +8,12 @@ var coreSubscriptions = new SubsManager({
});
PostsDailyController = RouteController.extend({
template: function() {
return getTemplate('postsDaily');
},
subscriptions: function() {
subscriptions: function () {
this.days = this.params.days ? this.params.days : daysPerPage;
// this.days = Session.get('postsDays') ? Session.get('postsDays') : 3;
@ -28,12 +30,18 @@ PostsDailyController = RouteController.extend({
this.postsUsersSubscription = coreSubscriptions.subscribe('postsListUsers', terms);
},
data: function() {
data: function () {
Session.set('postsDays', this.days);
return {
days: this.days
};
},
getTitle: function () {
return i18n.t('daily') + ' - ' + getSetting('title');
},
fastRender: true
});

View file

@ -10,9 +10,15 @@ Meteor.startup(function () {
Router.onBeforeAction(Router._filters.isAdmin, {only: ['categories']});
PostsCategoryController = PostsListController.extend({
view: 'category'
});
view: 'category',
getTitle: function () {
var category = Categories.findOne({slug: this.params.slug});
return category.name + ' - ' + getSetting('title');
}
});
// Categories
@ -20,6 +26,7 @@ Meteor.startup(function () {
name: 'posts_category',
controller: PostsCategoryController,
onAfterAction: function() {
this.slug = this.params.slug;
Session.set('categorySlug', this.params.slug);
}
});