diff --git a/web/base_viewer.js b/web/base_viewer.js index 9ae9952f8..c7bf2f607 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -158,6 +158,10 @@ class PDFPageViewBuffer { return this.#buf.has(view); } + [Symbol.iterator]() { + return this.#buf.keys(); + } + #destroyFirstView() { const firstView = this.#buf.keys().next().value; @@ -1402,6 +1406,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); @@ -1415,6 +1436,8 @@ class BaseViewer { scrollAhead, preRenderExtra ); + this.#toggleLoadingIconSpinner(visiblePages.ids); + if (pageView) { this._ensurePdfPageLoaded(pageView).then(() => { this.renderingQueue.renderView(pageView); diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index ca87ab4d8..0f8171f0d 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -289,7 +289,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); @@ -523,6 +526,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"); diff --git a/web/pdf_viewer.css b/web/pdf_viewer.css index b9e640832..dc0feda97 100644 --- a/web/pdf_viewer.css +++ b/web/pdf_viewer.css @@ -129,6 +129,9 @@ bottom: 0; background: url("images/loading-icon.gif") center no-repeat; } +.pdfViewer .page .loadingIcon.notVisible { + background: none; +} .pdfPresentationMode .pdfViewer { margin-left: 0;