BREAK: improve consistency by using 'category-<slug>' instead of 'category-<id>' as css class

This commit is contained in:
Régis Hanol 2015-01-26 23:11:41 +01:00
parent 31340de446
commit 088260f053
3 changed files with 9 additions and 9 deletions

View file

@ -1,23 +1,23 @@
// Mix this in to a view that has a `categoryId` property to automatically
// Mix this in to a view that has a `categorySlug` property to automatically
// add it to the body as the view is entered / left / model is changed.
// This is used for keeping the `body` style in sync for the background image.
export default {
_observeOnce: function() { this.get('categoryId'); }.on('init'),
_enterView: function() { this.get('categorySlug'); }.on('init'),
_removeClasses: function() {
$('body').removeClass(function(idx, css) {
return (css.match(/\bcategory-\d+/g) || []).join(' ');
return (css.match(/\bcategory-[^\b]+/g) || []).join(' ');
});
},
_categoryChanged: function() {
var categoryId = this.get('categoryId');
var categorySlug = this.get('categorySlug');
this._removeClasses();
if (categoryId) {
$('body').addClass('category-' + categoryId);
if (categorySlug) {
$('body').addClass('category-' + categorySlug);
}
}.observes('categoryId'),
}.observes('categorySlug'),
_leaveView: function() { this._removeClasses(); }.on('willDestroyElement')
};

View file

@ -1,5 +1,5 @@
import AddCategoryClass from 'discourse/mixins/add-category-class';
export default Em.View.extend(AddCategoryClass, {
categoryId: Em.computed.alias('controller.category.id'),
categorySlug: Em.computed.alias('controller.category.slug')
});

View file

@ -15,7 +15,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, Discourse.Scrolling, {
menuVisible: true,
SHORT_POST: 1200,
categoryId: Em.computed.alias('topic.category.id'),
categorySlug: Em.computed.alias('topic.category.slug'),
postStream: Em.computed.alias('controller.postStream'),