mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
parent
d5f5d9b867
commit
d2d0937986
|
@ -1,21 +1,42 @@
|
||||||
import ENV from "discourse-common/config/environment";
|
import ENV from "discourse-common/config/environment";
|
||||||
import { EventTarget } from "rsvp";
|
import { EventTarget } from "rsvp";
|
||||||
|
|
||||||
// Track visible elemnts on the screen.
|
let _skipUpdate;
|
||||||
|
let _rootElement;
|
||||||
|
|
||||||
|
export function configureEyeline(opts) {
|
||||||
|
if (opts) {
|
||||||
|
_skipUpdate = opts.skipUpdate;
|
||||||
|
_rootElement = opts.rootElement;
|
||||||
|
} else {
|
||||||
|
_skipUpdate = ENV.environment === "test";
|
||||||
|
_rootElement = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configureEyeline();
|
||||||
|
|
||||||
|
// Track visible elements on the screen.
|
||||||
const Eyeline = function Eyeline(selector) {
|
const Eyeline = function Eyeline(selector) {
|
||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
};
|
};
|
||||||
|
|
||||||
Eyeline.prototype.update = function() {
|
Eyeline.prototype.update = function() {
|
||||||
if (ENV.environment === "test") {
|
if (_skipUpdate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const docViewTop = $(window).scrollTop(),
|
const docViewTop = _rootElement
|
||||||
windowHeight = $(window).height(),
|
? $(_rootElement).scrollTop()
|
||||||
docViewBottom = docViewTop + windowHeight,
|
: $(window).scrollTop();
|
||||||
$elements = $(this.selector),
|
const windowHeight = _rootElement
|
||||||
bottomOffset = $elements.last().offset();
|
? $(_rootElement).height()
|
||||||
|
: $(window).height();
|
||||||
|
const docViewBottom = docViewTop + windowHeight;
|
||||||
|
const $elements = $(this.selector);
|
||||||
|
const bottomOffset = _rootElement
|
||||||
|
? $elements.last().position()
|
||||||
|
: $elements.last().offset();
|
||||||
|
|
||||||
let atBottom = false;
|
let atBottom = false;
|
||||||
if (bottomOffset) {
|
if (bottomOffset) {
|
||||||
|
@ -25,7 +46,7 @@ Eyeline.prototype.update = function() {
|
||||||
|
|
||||||
return $elements.each((i, elem) => {
|
return $elements.each((i, elem) => {
|
||||||
const $elem = $(elem),
|
const $elem = $(elem),
|
||||||
elemTop = $elem.offset().top,
|
elemTop = _rootElement ? $elem.position().top : $elem.offset().top,
|
||||||
elemBottom = elemTop + $elem.height();
|
elemBottom = elemTop + $elem.height();
|
||||||
|
|
||||||
let markSeen = false;
|
let markSeen = false;
|
||||||
|
|
27
test/javascripts/components/load-more-test.js.es6
Normal file
27
test/javascripts/components/load-more-test.js.es6
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { configureEyeline } from "discourse/lib/eyeline";
|
||||||
|
import componentTest from "helpers/component-test";
|
||||||
|
|
||||||
|
moduleForComponent("load-more", { integration: true });
|
||||||
|
|
||||||
|
componentTest("updates once after initialization", {
|
||||||
|
template: `
|
||||||
|
{{#load-more selector=".numbers tr" action=loadMore}}
|
||||||
|
<table class="numbers"><tr></tr></table>
|
||||||
|
{{/load-more}}`,
|
||||||
|
|
||||||
|
beforeEach() {
|
||||||
|
this.set("loadMore", () => this.set("loadedMore", true));
|
||||||
|
configureEyeline({
|
||||||
|
skipUpdate: false,
|
||||||
|
rootElement: Discourse.rootElement
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
afterEach() {
|
||||||
|
configureEyeline();
|
||||||
|
},
|
||||||
|
|
||||||
|
test(assert) {
|
||||||
|
assert.ok(this.loadedMore);
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user