FIX: better handling of the 'read guidelines' badge
This commit is contained in:
parent
5d74cadf2f
commit
10ef30ab3c
|
@ -0,0 +1,11 @@
|
||||||
|
export default function (element) {
|
||||||
|
if (element instanceof jQuery) { element = element[0]; }
|
||||||
|
|
||||||
|
const $window = $(window),
|
||||||
|
rect = element.getBoundingClientRect();
|
||||||
|
|
||||||
|
return rect.top >= 0 &&
|
||||||
|
rect.left >= 0 &&
|
||||||
|
rect.bottom <= $window.height() &&
|
||||||
|
rect.right <= $window.width();
|
||||||
|
}
|
|
@ -1,13 +1,15 @@
|
||||||
|
import isElementInViewport from "discourse/lib/is-element-in-viewport";
|
||||||
|
|
||||||
var readFaq = false;
|
var readFaq = false;
|
||||||
|
|
||||||
export default Ember.View.extend(Discourse.ScrollTop, {
|
export default Ember.View.extend(Discourse.ScrollTop, {
|
||||||
|
|
||||||
_checkRead: function() {
|
_checkRead: function() {
|
||||||
var path = this.get('controller.model.path');
|
const path = this.get('controller.model.path');
|
||||||
if (path === "faq" || path === "guidelines") {
|
if (path === "faq" || path === "guidelines") {
|
||||||
var $window = $(window),
|
const controller = this.get('controller');
|
||||||
controller = this.get('controller');
|
$(window).on('load.faq resize.faq scroll.faq', function() {
|
||||||
$window.on('scroll.faq', function(){
|
if (!readFaq && isElementInViewport($(".contents p").last())) {
|
||||||
if(!readFaq && ($window.scrollTop() + $window.height() > $(document).height() - 10)) {
|
|
||||||
readFaq = true;
|
readFaq = true;
|
||||||
controller.send('markFaqRead');
|
controller.send('markFaqRead');
|
||||||
}
|
}
|
||||||
|
@ -16,6 +18,6 @@ export default Ember.View.extend(Discourse.ScrollTop, {
|
||||||
}.on('didInsertElement'),
|
}.on('didInsertElement'),
|
||||||
|
|
||||||
_stopChecking: function(){
|
_stopChecking: function(){
|
||||||
$(window).off('scroll.faq');
|
$(window).off('load.faq resize.faq scroll.faq');
|
||||||
}.on('willDestroyElement')
|
}.on('willDestroyElement')
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue