Refactor setScrollMode/setSpreadMode, in the viewer classes, such that they are no-ops in PDFSinglePageViewer instances

Since the Scroll/Spread modes doesn't make (any) sense in `PDFSinglePageViewer` instances, the general structure of these methods can be improved to reflect that.
This commit is contained in:
Jonas Jenwald 2018-06-21 20:54:57 +02:00
parent 8bd1244298
commit 6a086fa0b9
2 changed files with 30 additions and 22 deletions

View File

@ -1020,26 +1020,10 @@ class BaseViewer {
}
setScrollMode(mode) {
if (mode === this.scrollMode) {
return;
}
if (!Number.isInteger(mode) || !Object.values(ScrollMode).includes(mode)) {
throw new Error(`Invalid scroll mode: ${mode}`);
}
this.scrollMode = mode;
this._updateScrollModeClasses();
this.eventBus.dispatch('scrollmodechanged', { mode, });
const pageNumber = this._currentPageNumber;
// Non-numeric scale modes can be sensitive to the scroll orientation.
// Call this before re-scrolling to the current page, to ensure that any
// changes in scale don't move the current page.
if (isNaN(this._currentScaleValue)) {
this._setScale(this._currentScaleValue, this.isInPresentationMode);
}
this.scrollPageIntoView({ pageNumber, });
this.update();
}
_updateScrollModeClasses() {
@ -1047,16 +1031,10 @@ class BaseViewer {
}
setSpreadMode(mode) {
if (mode === this.spreadMode) {
return;
}
if (!Number.isInteger(mode) || !Object.values(SpreadMode).includes(mode)) {
throw new Error(`Invalid spread mode: ${mode}`);
}
this.spreadMode = mode;
this.eventBus.dispatch('spreadmodechanged', { mode, });
this._regroupSpreads();
}
_regroupSpreads() {

View File

@ -87,6 +87,26 @@ class PDFViewer extends BaseViewer {
});
}
setScrollMode(mode) {
if (mode === this.scrollMode) {
return;
}
super.setScrollMode(mode);
this.eventBus.dispatch('scrollmodechanged', { mode, });
this._updateScrollModeClasses();
const pageNumber = this._currentPageNumber;
// Non-numeric scale modes can be sensitive to the scroll orientation.
// Call this before re-scrolling to the current page, to ensure that any
// changes in scale don't move the current page.
if (isNaN(this._currentScaleValue)) {
this._setScale(this._currentScaleValue, this.isInPresentationMode);
}
this.scrollPageIntoView({ pageNumber, });
this.update();
}
_updateScrollModeClasses() {
const { scrollMode, viewer, } = this;
@ -102,6 +122,16 @@ class PDFViewer extends BaseViewer {
}
}
setSpreadMode(mode) {
if (mode === this.spreadMode) {
return;
}
super.setSpreadMode(mode);
this.eventBus.dispatch('spreadmodechanged', { mode, });
this._regroupSpreads();
}
_regroupSpreads() {
const viewer = this.viewer, pages = this._pages;
// Temporarily remove all the pages from the DOM.