mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 12:13:58 -06:00
FIX: category class in body + memory leak
This commit is contained in:
parent
f9717da28f
commit
31f0300b06
@ -1,21 +1,28 @@
|
||||
// Mix this in to a view that has a `categoryFullSlug` 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.
|
||||
|
||||
import Ember from "ember";
|
||||
const { on, observer } = Ember;
|
||||
|
||||
export default {
|
||||
_enterView: function() { this.get('categoryFullSlug'); }.on('init'),
|
||||
_categoryChanged: on("didInsertElement", observer("categoryFullSlug", function() {
|
||||
const categoryFullSlug = this.get("categoryFullSlug");
|
||||
|
||||
_removeClasses() {
|
||||
$('body').removeClass((_, css) => (css.match(/\bcategory-\S+/g) || []).join(' '));
|
||||
},
|
||||
|
||||
_categoryChanged: function() {
|
||||
const categoryFullSlug = this.get('categoryFullSlug');
|
||||
this._removeClasses();
|
||||
this._removeClass();
|
||||
|
||||
if (categoryFullSlug) {
|
||||
$('body').addClass('category-' + categoryFullSlug);
|
||||
$("body").addClass("category-" + categoryFullSlug);
|
||||
}
|
||||
}.observes('categoryFullSlug').on('init'),
|
||||
})),
|
||||
|
||||
_leaveView: function() { this._removeClasses(); }.on('willDestroyElement')
|
||||
_leave: on("willDestroyElement", function() {
|
||||
console.log("[" + this.get("elementId") + "] _leave");
|
||||
this.removeObserver("categoryFullSlug");
|
||||
this._removeClass();
|
||||
}),
|
||||
|
||||
_removeClass() {
|
||||
$("body").removeClass((_, css) => (css.match(/\bcategory-\S+/g) || []).join(" "));
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user