mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 12:11:16 -05:00
FIX: category class in body + memory leak
This commit is contained in:
parent
f9717da28f
commit
31f0300b06
1 changed files with 18 additions and 11 deletions
|
@ -1,21 +1,28 @@
|
||||||
// Mix this in to a view that has a `categoryFullSlug` property to automatically
|
// 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.
|
// 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.
|
||||||
|
|
||||||
|
import Ember from "ember";
|
||||||
|
const { on, observer } = Ember;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
_enterView: function() { this.get('categoryFullSlug'); }.on('init'),
|
_categoryChanged: on("didInsertElement", observer("categoryFullSlug", function() {
|
||||||
|
const categoryFullSlug = this.get("categoryFullSlug");
|
||||||
|
|
||||||
_removeClasses() {
|
this._removeClass();
|
||||||
$('body').removeClass((_, css) => (css.match(/\bcategory-\S+/g) || []).join(' '));
|
|
||||||
},
|
|
||||||
|
|
||||||
_categoryChanged: function() {
|
|
||||||
const categoryFullSlug = this.get('categoryFullSlug');
|
|
||||||
this._removeClasses();
|
|
||||||
|
|
||||||
if (categoryFullSlug) {
|
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 a new issue