-
-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathprefill.js
More file actions
63 lines (50 loc) · 1.43 KB
/
prefill.js
File metadata and controls
63 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import Events from "./events";
export default class Prefill {
constructor(ias, options) {
this.ias = ias;
this.enabled = options;
}
prefill() {
if (!this.enabled) {
return;
}
this.ias.emitter.emit(Events.PREFILL);
return Promise.all([this._prefillNext(), this._prefillPrev()]).then(() => {
this.ias.emitter.emit(Events.PREFILLED);
// @todo reevaluate if we should actually call `measure` here.
this.ias.measure();
});
}
_prefillNext() {
// Respect the loadOnScroll flag. When trigger mode is active,
// Trigger.bind() calls disableLoadOnScroll() during the BINDED event,
// which fires before prefill runs. Without this guard, prefill would
// call next() unconditionally and bypass trigger mode, causing an
// unexpected auto-load on reload when the scroll position is restored
// near the sentinel. See: https://github.com/webcreate/infinite-ajax-scroll/issues/886
if (!this.ias.loadOnScroll) {
return;
}
let distance = this.ias.distance();
if (distance > 0) {
return;
}
return this.ias.next()
.then((hasNextUrl) => {
if (!hasNextUrl) {
return;
}
let distance = this.ias.distance();
if (distance < 0) {
return this._prefillNext();
}
})
;
}
_prefillPrev() {
if (!this.ias.options.prev) {
return;
}
return this.ias.prev();
}
}