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
2017-08-13 14:24:29 +02:00

42 lines
830 B
JavaScript

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