Remove all pages from the DOM at once, rather than using a loop, in PDFViewer._regroupSpreads
There's no good reason to iterate through an arbitrary number of DOM elements this way, since a document could contain thousands of pages, when everything can be easily removed at once; compare with e.g. `BaseViewer._resetView` and `PDFThumbnailViewer._resetView`. Furthermore given that it's a `PDFViewer` instance, the `this.viewer` property can be accessed directly. Besides, `_setDocumentViewerElement` only exists as a helper method for `setDocument` in the base class and none of this code applies for `PDFSinglePageViewer` instances either.
This commit is contained in:
parent
36111a1f40
commit
9b0ed6f821
@ -88,13 +88,13 @@ class PDFViewer extends BaseViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_regroupSpreads() {
|
_regroupSpreads() {
|
||||||
const container = this._setDocumentViewerElement, pages = this._pages;
|
const viewer = this.viewer, pages = this._pages;
|
||||||
while (container.firstChild) {
|
// Temporarily remove all the pages from the DOM.
|
||||||
container.firstChild.remove();
|
viewer.textContent = '';
|
||||||
}
|
|
||||||
if (this.spreadMode === SpreadMode.NONE) {
|
if (this.spreadMode === SpreadMode.NONE) {
|
||||||
for (let i = 0, iMax = pages.length; i < iMax; ++i) {
|
for (let i = 0, iMax = pages.length; i < iMax; ++i) {
|
||||||
container.appendChild(pages[i].div);
|
viewer.appendChild(pages[i].div);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const parity = this.spreadMode - 1;
|
const parity = this.spreadMode - 1;
|
||||||
@ -103,10 +103,10 @@ class PDFViewer extends BaseViewer {
|
|||||||
if (spread === null) {
|
if (spread === null) {
|
||||||
spread = document.createElement('div');
|
spread = document.createElement('div');
|
||||||
spread.className = 'spread';
|
spread.className = 'spread';
|
||||||
container.appendChild(spread);
|
viewer.appendChild(spread);
|
||||||
} else if (i % 2 === parity) {
|
} else if (i % 2 === parity) {
|
||||||
spread = spread.cloneNode(false);
|
spread = spread.cloneNode(false);
|
||||||
container.appendChild(spread);
|
viewer.appendChild(spread);
|
||||||
}
|
}
|
||||||
spread.appendChild(pages[i].div);
|
spread.appendChild(pages[i].div);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user