BREAK: improve consistency by using 'category-<slug>' instead of 'category-<id>' as css class
This commit is contained in:
parent
31340de446
commit
088260f053
|
@ -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.
|
// 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.
|
// This is used for keeping the `body` style in sync for the background image.
|
||||||
export default {
|
export default {
|
||||||
_observeOnce: function() { this.get('categoryId'); }.on('init'),
|
_enterView: function() { this.get('categorySlug'); }.on('init'),
|
||||||
|
|
||||||
_removeClasses: function() {
|
_removeClasses: function() {
|
||||||
$('body').removeClass(function(idx, css) {
|
$('body').removeClass(function(idx, css) {
|
||||||
return (css.match(/\bcategory-\d+/g) || []).join(' ');
|
return (css.match(/\bcategory-[^\b]+/g) || []).join(' ');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_categoryChanged: function() {
|
_categoryChanged: function() {
|
||||||
var categoryId = this.get('categoryId');
|
var categorySlug = this.get('categorySlug');
|
||||||
this._removeClasses();
|
this._removeClasses();
|
||||||
|
|
||||||
if (categoryId) {
|
if (categorySlug) {
|
||||||
$('body').addClass('category-' + categoryId);
|
$('body').addClass('category-' + categorySlug);
|
||||||
}
|
}
|
||||||
}.observes('categoryId'),
|
}.observes('categorySlug'),
|
||||||
|
|
||||||
_leaveView: function() { this._removeClasses(); }.on('willDestroyElement')
|
_leaveView: function() { this._removeClasses(); }.on('willDestroyElement')
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import AddCategoryClass from 'discourse/mixins/add-category-class';
|
import AddCategoryClass from 'discourse/mixins/add-category-class';
|
||||||
|
|
||||||
export default Em.View.extend(AddCategoryClass, {
|
export default Em.View.extend(AddCategoryClass, {
|
||||||
categoryId: Em.computed.alias('controller.category.id'),
|
categorySlug: Em.computed.alias('controller.category.slug')
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, Discourse.Scrolling, {
|
||||||
menuVisible: true,
|
menuVisible: true,
|
||||||
SHORT_POST: 1200,
|
SHORT_POST: 1200,
|
||||||
|
|
||||||
categoryId: Em.computed.alias('topic.category.id'),
|
categorySlug: Em.computed.alias('topic.category.slug'),
|
||||||
|
|
||||||
postStream: Em.computed.alias('controller.postStream'),
|
postStream: Em.computed.alias('controller.postStream'),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue