mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 08:44:48 +08:00
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
import DiscourseURL from 'discourse/lib/url';
|
|
|
|
// Can add a body class from within a component, also will scroll to the top automatically.
|
|
export default Ember.Component.extend({
|
|
tagName: 'section',
|
|
|
|
_scrollTop() {
|
|
if (Ember.testing) { return; }
|
|
$(document).scrollTop(0);
|
|
},
|
|
|
|
didInsertElement() {
|
|
this._super();
|
|
|
|
const pageClass = this.get('pageClass');
|
|
if (pageClass) {
|
|
$('body').addClass(`${pageClass}-page`);
|
|
}
|
|
|
|
const bodyClass = this.get('bodyClass');
|
|
if (bodyClass) {
|
|
$('body').addClass(bodyClass);
|
|
}
|
|
|
|
if (this.get('scrollTop') === "false") {
|
|
return;
|
|
}
|
|
|
|
if (DiscourseURL.isJumpScheduled()) { return; }
|
|
Ember.run.scheduleOnce('afterRender', this, this._scrollTop);
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this._super();
|
|
const pageClass = this.get('pageClass');
|
|
if (pageClass) {
|
|
$('body').removeClass(`${pageClass}-page`);
|
|
}
|
|
|
|
const bodyClass = this.get('bodyClass');
|
|
if (bodyClass) {
|
|
$('body').removeClass(bodyClass);
|
|
}
|
|
}
|
|
});
|