Skip to content

Commit e9a4830

Browse files
Merge pull request #20142 from calixteman/bug1957680
Trigger a fake scrollend event in case it hasn't been triggered by the browser (bug 1957680)
2 parents 17527d8 + 2877764 commit e9a4830

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

web/app.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,19 +2227,18 @@ const PDFViewerApplication = {
22272227
mainContainer);
22282228
}
22292229

2230+
let scrollendTimeoutID, scrollAbortController;
22302231
const scrollend = () => {
22312232
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
22322233
({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } =
22332234
mainContainer);
22342235
}
2235-
2236-
this._isScrolling = false;
2237-
mainContainer.addEventListener("scroll", scroll, {
2238-
passive: true,
2239-
signal,
2240-
});
2241-
mainContainer.removeEventListener("scrollend", scrollend);
2242-
mainContainer.removeEventListener("blur", scrollend);
2236+
clearTimeout(scrollendTimeoutID);
2237+
if (this._isScrolling) {
2238+
scrollAbortController.abort();
2239+
scrollAbortController = null;
2240+
this._isScrolling = false;
2241+
}
22432242
};
22442243
const scroll = () => {
22452244
if (this._isCtrlKeyDown) {
@@ -2253,10 +2252,27 @@ const PDFViewerApplication = {
22532252
return;
22542253
}
22552254

2256-
mainContainer.removeEventListener("scroll", scroll);
2257-
this._isScrolling = true;
2258-
mainContainer.addEventListener("scrollend", scrollend, { signal });
2259-
mainContainer.addEventListener("blur", scrollend, { signal });
2255+
if (!this._isScrolling) {
2256+
scrollAbortController = new AbortController();
2257+
const abortSignal = AbortSignal.any([
2258+
scrollAbortController.signal,
2259+
signal,
2260+
]);
2261+
2262+
mainContainer.addEventListener("scrollend", scrollend, {
2263+
signal: abortSignal,
2264+
});
2265+
mainContainer.addEventListener("blur", scrollend, {
2266+
signal: abortSignal,
2267+
});
2268+
this._isScrolling = true;
2269+
}
2270+
clearTimeout(scrollendTimeoutID);
2271+
// Why 100 ? Because of:
2272+
// https://developer.chrome.com/blog/scrollend-a-new-javascript-event
2273+
// Maybe we could find a better value... ideally the `scrollend` event
2274+
// should be correctly fired.
2275+
scrollendTimeoutID = setTimeout(scrollend, 100);
22602276
};
22612277
mainContainer.addEventListener("scroll", scroll, {
22622278
passive: true,

0 commit comments

Comments
 (0)