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/watch-read.js.es6
2019-03-20 14:43:25 +01:00

27 lines
704 B
JavaScript

import isElementInViewport from "discourse/lib/is-element-in-viewport";
export default Ember.Component.extend({
didInsertElement() {
this._super(...arguments);
const currentUser = this.currentUser;
if (!currentUser) {
return;
}
const path = this.get("path");
if (path === "faq" || path === "guidelines") {
$(window).on("load.faq resize.faq scroll.faq", () => {
const faqUnread = !currentUser.get("read_faq");
if (faqUnread && isElementInViewport($(".contents p").last())) {
this.action();
}
});
}
},
willDestroyElement() {
this._super(...arguments);
$(window).off("load.faq resize.faq scroll.faq");
}
});