Change the scrollMode/spreadMode to "private" properties on BaseViewer instances

This commit is contained in:
Jonas Jenwald 2018-06-29 14:14:11 +02:00
parent a9a93bd923
commit 9515f579c6
2 changed files with 14 additions and 14 deletions

View File

@ -162,8 +162,8 @@ class BaseViewer {
this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false;
this.maxCanvasPixels = options.maxCanvasPixels; this.maxCanvasPixels = options.maxCanvasPixels;
this.l10n = options.l10n || NullL10n; this.l10n = options.l10n || NullL10n;
this.scrollMode = options.scrollMode || ScrollMode.VERTICAL; this._scrollMode = options.scrollMode || ScrollMode.VERTICAL;
this.spreadMode = options.spreadMode || SpreadMode.NONE; this._spreadMode = options.spreadMode || SpreadMode.NONE;
this.defaultRenderingQueue = !options.renderingQueue; this.defaultRenderingQueue = !options.renderingQueue;
if (this.defaultRenderingQueue) { if (this.defaultRenderingQueue) {
@ -181,7 +181,7 @@ class BaseViewer {
if (this.removePageBorders) { if (this.removePageBorders) {
this.viewer.classList.add('removePageBorders'); this.viewer.classList.add('removePageBorders');
} }
if (this.scrollMode !== ScrollMode.VERTICAL) { if (this._scrollMode !== ScrollMode.VERTICAL) {
this._updateScrollModeClasses(); this._updateScrollModeClasses();
} }
} }
@ -441,7 +441,7 @@ class BaseViewer {
bindOnAfterAndBeforeDraw(pageView); bindOnAfterAndBeforeDraw(pageView);
this._pages.push(pageView); this._pages.push(pageView);
} }
if (this.spreadMode !== SpreadMode.NONE) { if (this._spreadMode !== SpreadMode.NONE) {
this._regroupSpreads(); this._regroupSpreads();
} }
@ -1027,7 +1027,7 @@ class BaseViewer {
if (!Number.isInteger(mode) || !Object.values(ScrollMode).includes(mode)) { if (!Number.isInteger(mode) || !Object.values(ScrollMode).includes(mode)) {
throw new Error(`Invalid scroll mode: ${mode}`); throw new Error(`Invalid scroll mode: ${mode}`);
} }
this.scrollMode = mode; this._scrollMode = mode;
} }
_updateScrollModeClasses() { _updateScrollModeClasses() {
@ -1038,7 +1038,7 @@ class BaseViewer {
if (!Number.isInteger(mode) || !Object.values(SpreadMode).includes(mode)) { if (!Number.isInteger(mode) || !Object.values(SpreadMode).includes(mode)) {
throw new Error(`Invalid spread mode: ${mode}`); throw new Error(`Invalid spread mode: ${mode}`);
} }
this.spreadMode = mode; this._spreadMode = mode;
} }
_regroupSpreads() { _regroupSpreads() {

View File

@ -27,7 +27,7 @@ class PDFViewer extends BaseViewer {
const left = pageDiv.offsetLeft + pageDiv.clientLeft; const left = pageDiv.offsetLeft + pageDiv.clientLeft;
const right = left + pageDiv.clientWidth; const right = left + pageDiv.clientWidth;
const { scrollLeft, clientWidth, } = this.container; const { scrollLeft, clientWidth, } = this.container;
if (this.scrollMode === ScrollMode.HORIZONTAL || if (this._scrollMode === ScrollMode.HORIZONTAL ||
left < scrollLeft || right > scrollLeft + clientWidth) { left < scrollLeft || right > scrollLeft + clientWidth) {
pageSpot = { left: 0, top: 0, }; pageSpot = { left: 0, top: 0, };
} }
@ -38,7 +38,7 @@ class PDFViewer extends BaseViewer {
_getVisiblePages() { _getVisiblePages() {
if (!this.isInPresentationMode) { if (!this.isInPresentationMode) {
return getVisibleElements(this.container, this._pages, true, return getVisibleElements(this.container, this._pages, true,
this.scrollMode === ScrollMode.HORIZONTAL); this._scrollMode === ScrollMode.HORIZONTAL);
} }
// The algorithm in getVisibleElements doesn't work in all browsers and // The algorithm in getVisibleElements doesn't work in all browsers and
// configurations when presentation mode is active. // configurations when presentation mode is active.
@ -91,11 +91,11 @@ class PDFViewer extends BaseViewer {
// Used to ensure that pre-rendering of the next/previous page works // Used to ensure that pre-rendering of the next/previous page works
// correctly, since Scroll/Spread modes are ignored in Presentation Mode. // correctly, since Scroll/Spread modes are ignored in Presentation Mode.
return (this.isInPresentationMode ? return (this.isInPresentationMode ?
false : this.scrollMode === ScrollMode.HORIZONTAL); false : this._scrollMode === ScrollMode.HORIZONTAL);
} }
setScrollMode(mode) { setScrollMode(mode) {
if (mode === this.scrollMode) { if (mode === this._scrollMode) {
return; return;
} }
super.setScrollMode(mode); super.setScrollMode(mode);
@ -118,7 +118,7 @@ class PDFViewer extends BaseViewer {
} }
_updateScrollModeClasses() { _updateScrollModeClasses() {
const { scrollMode, viewer, } = this; const scrollMode = this._scrollMode, viewer = this.viewer;
if (scrollMode === ScrollMode.HORIZONTAL) { if (scrollMode === ScrollMode.HORIZONTAL) {
viewer.classList.add('scrollHorizontal'); viewer.classList.add('scrollHorizontal');
@ -133,7 +133,7 @@ class PDFViewer extends BaseViewer {
} }
setSpreadMode(mode) { setSpreadMode(mode) {
if (mode === this.spreadMode) { if (mode === this._spreadMode) {
return; return;
} }
super.setSpreadMode(mode); super.setSpreadMode(mode);
@ -150,12 +150,12 @@ class PDFViewer extends BaseViewer {
// Temporarily remove all the pages from the DOM. // Temporarily remove all the pages from the DOM.
viewer.textContent = ''; 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) {
viewer.appendChild(pages[i].div); viewer.appendChild(pages[i].div);
} }
} else { } else {
const parity = this.spreadMode - 1; const parity = this._spreadMode - 1;
let spread = null; let spread = null;
for (let i = 0, iMax = pages.length; i < iMax; ++i) { for (let i = 0, iMax = pages.length; i < iMax; ++i) {
if (spread === null) { if (spread === null) {