Don't allow setting various properties, such as currentPageNumber
/currentScale
/currentScaleValue
/pagesRotation
, before {PDFViewer, PDFThumbnailViewer}.setDocument
has been called
Currently a number of these properties do not work correctly if set *before* calling `setDocument`; please refer to the discussion starting in https://github.com/mozilla/pdf.js/pull/8539#issuecomment-309706629. Rather than trying to have *some* of these methods working, but not others, it seems much more consistent to simply always require that `setDocument` has been called.
This commit is contained in:
parent
9bed695ebd
commit
735b58c3d5
@ -95,8 +95,15 @@ class PDFThumbnailViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set pagesRotation(rotation) {
|
set pagesRotation(rotation) {
|
||||||
|
if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
|
||||||
|
throw new Error('Invalid thumbnails rotation angle.');
|
||||||
|
}
|
||||||
|
if (!this.pdfDocument) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._pagesRotation = rotation;
|
this._pagesRotation = rotation;
|
||||||
for (let i = 0, l = this._thumbnails.length; i < l; i++) {
|
|
||||||
|
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
||||||
this._thumbnails[i].update(rotation);
|
this._thumbnails[i].update(rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,6 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
throw new Error('Invalid page number.');
|
throw new Error('Invalid page number.');
|
||||||
}
|
}
|
||||||
if (!this.pdfDocument) {
|
if (!this.pdfDocument) {
|
||||||
this._currentPageNumber = val;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// The intent can be to just reset a scroll position and/or scale.
|
// The intent can be to just reset a scroll position and/or scale.
|
||||||
@ -217,9 +216,9 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
* @param {string} val - The page label.
|
* @param {string} val - The page label.
|
||||||
*/
|
*/
|
||||||
set currentPageLabel(val) {
|
set currentPageLabel(val) {
|
||||||
var pageNumber = val | 0; // Fallback page number.
|
let pageNumber = val | 0; // Fallback page number.
|
||||||
if (this._pageLabels) {
|
if (this._pageLabels) {
|
||||||
var i = this._pageLabels.indexOf(val);
|
let i = this._pageLabels.indexOf(val);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
pageNumber = i + 1;
|
pageNumber = i + 1;
|
||||||
}
|
}
|
||||||
@ -243,8 +242,6 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
throw new Error('Invalid numeric scale');
|
throw new Error('Invalid numeric scale');
|
||||||
}
|
}
|
||||||
if (!this.pdfDocument) {
|
if (!this.pdfDocument) {
|
||||||
this._currentScale = val;
|
|
||||||
this._currentScaleValue = val !== UNKNOWN_SCALE ? val.toString() : null;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._setScale(val, false);
|
this._setScale(val, false);
|
||||||
@ -262,8 +259,6 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
*/
|
*/
|
||||||
set currentScaleValue(val) {
|
set currentScaleValue(val) {
|
||||||
if (!this.pdfDocument) {
|
if (!this.pdfDocument) {
|
||||||
this._currentScale = isNaN(val) ? UNKNOWN_SCALE : val;
|
|
||||||
this._currentScaleValue = val.toString();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._setScale(val, false);
|
this._setScale(val, false);
|
||||||
@ -283,13 +278,13 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
|
if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
|
||||||
throw new Error('Invalid pages rotation angle.');
|
throw new Error('Invalid pages rotation angle.');
|
||||||
}
|
}
|
||||||
this._pagesRotation = rotation;
|
|
||||||
|
|
||||||
if (!this.pdfDocument) {
|
if (!this.pdfDocument) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (var i = 0, l = this._pages.length; i < l; i++) {
|
this._pagesRotation = rotation;
|
||||||
var pageView = this._pages[i];
|
|
||||||
|
for (let i = 0, ii = this._pages.length; i < ii; i++) {
|
||||||
|
let pageView = this._pages[i];
|
||||||
pageView.update(pageView.scale, rotation);
|
pageView.update(pageView.scale, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user