Replace setScrollMode
/setSpreadMode
methods with getters/setters
Since all the other viewer methods use the getter/setter pattern, e.g. for setting page/scale/rotation, the way that the Scroll/Spread modes are set thus stands out. For consistency, this really ought to use the same pattern as the rest of the `BaseViewer`. (To avoid breaking third-party implementations, the old methods are kept around as aliases.)
This commit is contained in:
parent
9515f579c6
commit
a7ac27e385
@ -1250,10 +1250,10 @@ let PDFViewerApplication = {
|
||||
};
|
||||
let setViewerModes = (scroll, spread) => {
|
||||
if (Number.isInteger(scroll)) {
|
||||
this.pdfViewer.setScrollMode(scroll);
|
||||
this.pdfViewer.scrollMode = scroll;
|
||||
}
|
||||
if (Number.isInteger(spread)) {
|
||||
this.pdfViewer.setSpreadMode(spread);
|
||||
this.pdfViewer.spreadMode = spread;
|
||||
}
|
||||
};
|
||||
|
||||
@ -2019,10 +2019,10 @@ function webViewerRotateCcw() {
|
||||
PDFViewerApplication.rotatePages(-90);
|
||||
}
|
||||
function webViewerSwitchScrollMode(evt) {
|
||||
PDFViewerApplication.pdfViewer.setScrollMode(evt.mode);
|
||||
PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
|
||||
}
|
||||
function webViewerSwitchSpreadMode(evt) {
|
||||
PDFViewerApplication.pdfViewer.setSpreadMode(evt.mode);
|
||||
PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
|
||||
}
|
||||
function webViewerDocumentProperties() {
|
||||
PDFViewerApplication.pdfDocumentProperties.open();
|
||||
|
@ -1023,22 +1023,79 @@ class BaseViewer {
|
||||
});
|
||||
}
|
||||
|
||||
setScrollMode(mode) {
|
||||
/**
|
||||
* @return {number} One of the values in {ScrollMode}.
|
||||
*/
|
||||
get scrollMode() {
|
||||
return this._scrollMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} mode - The direction in which the document pages should be
|
||||
* laid out within the scrolling container.
|
||||
* The constants from {ScrollMode} should be used.
|
||||
*/
|
||||
set scrollMode(mode) {
|
||||
if (this._scrollMode === mode) {
|
||||
return; // The Scroll mode didn't change.
|
||||
}
|
||||
if (!Number.isInteger(mode) || !Object.values(ScrollMode).includes(mode)) {
|
||||
throw new Error(`Invalid scroll mode: ${mode}`);
|
||||
}
|
||||
this._scrollMode = mode;
|
||||
this.eventBus.dispatch('scrollmodechanged', { source: this, mode, });
|
||||
|
||||
this._updateScrollModeClasses();
|
||||
|
||||
if (!this.pdfDocument) {
|
||||
return;
|
||||
}
|
||||
const pageNumber = this._currentPageNumber;
|
||||
// Non-numeric scale values 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, true);
|
||||
}
|
||||
this.scrollPageIntoView({ pageNumber, });
|
||||
this.update();
|
||||
}
|
||||
|
||||
setScrollMode(mode) {
|
||||
this.scrollMode = mode;
|
||||
}
|
||||
|
||||
_updateScrollModeClasses() {
|
||||
// No-op in the base class.
|
||||
}
|
||||
|
||||
setSpreadMode(mode) {
|
||||
/**
|
||||
* @return {number} One of the values in {SpreadMode}.
|
||||
*/
|
||||
get spreadMode() {
|
||||
return this._spreadMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} mode - Group the pages in spreads, starting with odd- or
|
||||
* even-number pages (unless `SpreadMode.NONE` is used).
|
||||
* The constants from {SpreadMode} should be used.
|
||||
*/
|
||||
set spreadMode(mode) {
|
||||
if (this._spreadMode === mode) {
|
||||
return; // The Spread mode didn't change.
|
||||
}
|
||||
if (!Number.isInteger(mode) || !Object.values(SpreadMode).includes(mode)) {
|
||||
throw new Error(`Invalid spread mode: ${mode}`);
|
||||
}
|
||||
this._spreadMode = mode;
|
||||
this.eventBus.dispatch('spreadmodechanged', { source: this, mode, });
|
||||
|
||||
this._regroupSpreads();
|
||||
}
|
||||
|
||||
setSpreadMode(mode) {
|
||||
this.spreadMode = mode;
|
||||
}
|
||||
|
||||
_regroupSpreads() {
|
||||
|
@ -94,29 +94,6 @@ class PDFViewer extends BaseViewer {
|
||||
false : this._scrollMode === ScrollMode.HORIZONTAL);
|
||||
}
|
||||
|
||||
setScrollMode(mode) {
|
||||
if (mode === this._scrollMode) {
|
||||
return;
|
||||
}
|
||||
super.setScrollMode(mode);
|
||||
|
||||
this.eventBus.dispatch('scrollmodechanged', { mode, });
|
||||
this._updateScrollModeClasses();
|
||||
|
||||
if (!this.pdfDocument) {
|
||||
return;
|
||||
}
|
||||
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, true);
|
||||
}
|
||||
this.scrollPageIntoView({ pageNumber, });
|
||||
this.update();
|
||||
}
|
||||
|
||||
_updateScrollModeClasses() {
|
||||
const scrollMode = this._scrollMode, viewer = this.viewer;
|
||||
|
||||
@ -132,16 +109,6 @@ class PDFViewer extends BaseViewer {
|
||||
}
|
||||
}
|
||||
|
||||
setSpreadMode(mode) {
|
||||
if (mode === this._spreadMode) {
|
||||
return;
|
||||
}
|
||||
super.setSpreadMode(mode);
|
||||
|
||||
this.eventBus.dispatch('spreadmodechanged', { mode, });
|
||||
this._regroupSpreads();
|
||||
}
|
||||
|
||||
_regroupSpreads() {
|
||||
if (!this.pdfDocument) {
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user