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
2020-03-12 13:29:55 -04:00

42 lines
902 B
JavaScript

import { next } from "@ember/runloop";
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) {
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
});
}
});