From e2e2e27acbbf9d5bbb7d85423d81dac26f7a73f1 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 4 Feb 2019 18:29:54 +0100 Subject: [PATCH] fix #2574 @0.25 --- js/libs/fluidbook/fluidbook.js | 3 + js/libs/fluidbook/fluidbook.print.js | 90 ++++++++++++++-------------- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index df24f730..4e06e0ee 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -647,6 +647,9 @@ Fluidbook.prototype = { return this.datas.numerotation[page - 1]; }, virtualToPhysical: function (page) { + if(page===undefined){ + return false; + } var i = this.datas.numerotation.indexOf(page.toString()); if (i == -1) { return false; diff --git a/js/libs/fluidbook/fluidbook.print.js b/js/libs/fluidbook/fluidbook.print.js index e3606490..a1ed160d 100644 --- a/js/libs/fluidbook/fluidbook.print.js +++ b/js/libs/fluidbook/fluidbook.print.js @@ -20,9 +20,8 @@ FluidbookPrint.prototype = { element = $(this), mode = element.data('mode'), // Either 'print' or 'download' print = (mode == 'print'), - choice = $('input[name="pageChoice"]:checked').val(), - rangeStart = $this.fluidbook.virtualToPhysical($('#pageRangeStart').val()), - rangeEnd = $this.fluidbook.virtualToPhysical($('#pageRangeEnd').val()); + choice = $('input[name="pageChoice"]:checked').val(); + switch (choice) { case 'left': @@ -42,25 +41,28 @@ FluidbookPrint.prototype = { $this.fluidbook.bookmarks.openPDF(element, print); break; case 'range': - if (isNaN(rangeStart) || - isNaN(rangeEnd) || - (rangeStart < 1) || - (rangeEnd > $this.fluidbook.datas.pages) || - (rangeStart > rangeEnd) - ) { - alert(__('Invalid page range. Please try again.')); - return false; - } - var pageRange = rangeStart + '-' + rangeEnd; - $this.fluidbook._openFile(dynamicPDF + pageRange, element, 'pdf', pageRange + '.pdf', print); - break;default: + var rangeStart = $this.fluidbook.virtualToPhysical($('#pageRangeStart').val()); + var rangeEnd = $this.fluidbook.virtualToPhysical($('#pageRangeEnd').val()); + if (isNaN(rangeStart) || + isNaN(rangeEnd) || + (rangeStart < 1) || + (rangeEnd > $this.fluidbook.datas.pages) || + (rangeStart > rangeEnd) + ) { + alert(__('Invalid page range. Please try again.')); + return false; + } + var pageRange = rangeStart + '-' + rangeEnd; + $this.fluidbook._openFile(dynamicPDF + pageRange, element, 'pdf', pageRange + '.pdf', print); + break; + default: return false; } }); // Automatically select page range option when clicking in the input fields - $(document).on('focus', '.page-range-input', function() { - $('#pageRange').prop('checked', true); + $(document).on('focus', '.page-range-input', function () { + $('#pageRange').prop('checked', true); }); // When there are no bookmarks a click on the bookmarks option will open the bookmarks help modal @@ -151,17 +153,17 @@ FluidbookPrint.prototype = { // Full Brochure if (this.fluidbook.datas.printFullBrochure) { - view += ''; // .print-option + view += ''; // .print-option } // Bookmarks @@ -185,22 +187,22 @@ FluidbookPrint.prototype = { // Page range inputs if (this.fluidbook.datas.printPageRange) { - // leftPageNumber may be false if on first page - var rangeStart = Math.max(leftPageNumber, 1); - - // Current page + 1 unless we're out of range. - // It has to be calculated this way because sometimes there is no rightPageNumber - var rangeEnd = Math.min(rangeStart + 1, this.fluidbook.datas.pages); - - view += ''; // .print-option + // leftPageNumber may be false if on first page + var rangeStart = Math.max(leftPageNumber, 1); + + // Current page + 1 unless we're out of range. + // It has to be calculated this way because sometimes there is no rightPageNumber + var rangeEnd = Math.min(rangeStart + 1, this.fluidbook.datas.pages); + + view += ''; // .print-option } view += ''; // .print-dialogue -- 2.39.5