This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/scroll-tracker.js.es6
Robin Ward fcb1ca52f9 Revert Ember.run refactors
This reverts commit 5ca60fcb6b.
2019-10-29 17:10:47 -04:00

41 lines
873 B
JavaScript

import Component from "@ember/component";
import Scrolling from "discourse/mixins/scrolling";
export default Component.extend(Scrolling, {
didReceiveAttrs() {
this._super(...arguments);
this.set("trackerName", `scroll-tracker-${this.name}`);
},
didInsertElement() {
this._super(...arguments);
this.bindScrolling({ name: this.name });
},
didRender() {
this._super(...arguments);
const data = this.session.get(this.trackerName);
if (data && data.position >= 0 && data.tag === this.tag) {
Ember.run.next(() => $(window).scrollTop(data.position + 1));
}
},
willDestroyElement() {
this._super(...arguments);
this.unbindScrolling(this.name);
},
scrolled() {
this._super(...arguments);
this.session.set(this.trackerName, {
position: $(window).scrollTop(),
tag: this.tag
});
}
});