1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #14276 from Snuffleupagus/issue-14242-2

Only show the `loadingIcon`-spinner on visible pages (issue 14242)
This commit is contained in:
Brendan Dahl 2021-11-18 13:43:58 -08:00 committed by GitHub
commit 9f4a2cf5ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 20 deletions

View file

@ -99,17 +99,6 @@ class PDFPageViewBuffer {
constructor(size) {
this.#size = size;
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
Object.defineProperty(this, "_buffer", {
get() {
return [...this.#buf];
},
});
}
}
push(view) {
@ -158,6 +147,10 @@ class PDFPageViewBuffer {
return this.#buf.has(view);
}
[Symbol.iterator]() {
return this.#buf.keys();
}
#destroyFirstView() {
const firstView = this.#buf.keys().next().value;
@ -1406,6 +1399,23 @@ class BaseViewer {
return this.scroll.down;
}
/**
* Only show the `loadingIcon`-spinner on visible pages (see issue 14242).
*/
#toggleLoadingIconSpinner(visibleIds) {
for (const id of visibleIds) {
const pageView = this._pages[id - 1];
pageView?.toggleLoadingIconSpinner(/* viewVisible = */ true);
}
for (const pageView of this.#buffer) {
if (visibleIds.has(pageView.id)) {
// Handled above, since the "buffer" may not contain all visible pages.
continue;
}
pageView.toggleLoadingIconSpinner(/* viewVisible = */ false);
}
}
forceRendering(currentlyVisiblePages) {
const visiblePages = currentlyVisiblePages || this._getVisiblePages();
const scrollAhead = this.#getScrollAhead(visiblePages);
@ -1419,6 +1429,8 @@ class BaseViewer {
scrollAhead,
preRenderExtra
);
this.#toggleLoadingIconSpinner(visiblePages.ids);
if (pageView) {
this._ensurePdfPageLoaded(pageView).then(() => {
this.renderingQueue.renderView(pageView);

View file

@ -291,7 +291,10 @@ class PDFPageView {
}
this.loadingIconDiv = document.createElement("div");
this.loadingIconDiv.className = "loadingIcon";
this.loadingIconDiv.className = "loadingIcon notVisible";
if (this._isStandalone) {
this.toggleLoadingIconSpinner(/* viewVisible = */ true);
}
this.loadingIconDiv.setAttribute("role", "img");
this.l10n.get("loading").then(msg => {
this.loadingIconDiv?.setAttribute("aria-label", msg);
@ -529,6 +532,13 @@ class PDFPageView {
return this.viewport.convertToPdfPoint(x, y);
}
/**
* @ignore
*/
toggleLoadingIconSpinner(viewVisible = false) {
this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
}
draw() {
if (this.renderingState !== RenderingStates.INITIAL) {
console.error("Must be in new state before drawing");

View file

@ -130,6 +130,9 @@
bottom: 0;
background: url("images/loading-icon.gif") center no-repeat;
}
.pdfViewer .page .loadingIcon.notVisible {
background: none;
}
.pdfPresentationMode .pdfViewer {
margin-left: 0;