Merge pull request #7502 from Snuffleupagus/pagechanging-outOfBounds
Remove the `previousPageNumber` parameter from the `pagechanging`/pagechange` events, and stop dispatching the events if the input is out of bounds
This commit is contained in:
commit
0925503ce7
11
web/app.js
11
web/app.js
@ -1526,11 +1526,12 @@ function webViewerInitialized() {
|
||||
});
|
||||
|
||||
appConfig.toolbar.pageNumber.addEventListener('change', function() {
|
||||
// Handle the user inputting a floating point number.
|
||||
PDFViewerApplication.page = (this.value | 0);
|
||||
|
||||
if (this.value !== (this.value | 0).toString()) {
|
||||
this.value = PDFViewerApplication.page;
|
||||
// Ensure that the page number input displays the correct value, even if the
|
||||
// value entered by the user was invalid (e.g. a floating point number).
|
||||
if (this.value !== PDFViewerApplication.page.toString()) {
|
||||
PDFViewerApplication._updateUIToolbar({});
|
||||
}
|
||||
});
|
||||
|
||||
@ -1971,8 +1972,8 @@ function webViewerPageChanging(e) {
|
||||
PDFViewerApplication._updateUIToolbar({
|
||||
pageNumber: page,
|
||||
});
|
||||
if (e.previousPageNumber !== page &&
|
||||
PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
||||
|
||||
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
||||
PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,6 @@
|
||||
var event = document.createEvent('UIEvents');
|
||||
event.initUIEvent('pagechange', true, true, window, 0);
|
||||
event.pageNumber = e.pageNumber;
|
||||
event.previousPageNumber = e.previousPageNumber;
|
||||
e.source.container.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('pagesinit', function (e) {
|
||||
|
@ -166,6 +166,9 @@ var PDFViewer = (function pdfViewer() {
|
||||
* @param {number} val - The page number.
|
||||
*/
|
||||
set currentPageNumber(val) {
|
||||
if ((val | 0) !== val) { // Ensure that `val` is an integer.
|
||||
throw new Error('Invalid page number.');
|
||||
}
|
||||
if (!this.pdfDocument) {
|
||||
this._currentPageNumber = val;
|
||||
return;
|
||||
@ -185,22 +188,14 @@ var PDFViewer = (function pdfViewer() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
var arg;
|
||||
|
||||
if (!(0 < val && val <= this.pagesCount)) {
|
||||
arg = {
|
||||
source: this,
|
||||
pageNumber: this._currentPageNumber,
|
||||
previousPageNumber: val
|
||||
};
|
||||
this.eventBus.dispatch('pagechanging', arg);
|
||||
this.eventBus.dispatch('pagechange', arg);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = {
|
||||
var arg = {
|
||||
source: this,
|
||||
pageNumber: val,
|
||||
previousPageNumber: this._currentPageNumber
|
||||
};
|
||||
this._currentPageNumber = val;
|
||||
this.eventBus.dispatch('pagechanging', arg);
|
||||
@ -223,7 +218,7 @@ var PDFViewer = (function pdfViewer() {
|
||||
* @param {number} val - Scale of the pages in percents.
|
||||
*/
|
||||
set currentScale(val) {
|
||||
if (isNaN(val)) {
|
||||
if (isNaN(val)) {
|
||||
throw new Error('Invalid numeric scale');
|
||||
}
|
||||
if (!this.pdfDocument) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user