From 8967f5fdac4d9d42675c3dc1724982ba74b1dc9c Mon Sep 17 00:00:00 2001 From: RaffaeleMorganti Date: Fri, 20 Sep 2019 22:42:21 +0200 Subject: [PATCH] Fix regression --- external/pdfjs-2.1.266-dist/web/viewer.js | 16 +++++---- pdf-turn/pdf-turn.js | 44 +++++++---------------- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/external/pdfjs-2.1.266-dist/web/viewer.js b/external/pdfjs-2.1.266-dist/web/viewer.js index 3632044..a63cb80 100644 --- a/external/pdfjs-2.1.266-dist/web/viewer.js +++ b/external/pdfjs-2.1.266-dist/web/viewer.js @@ -1269,6 +1269,13 @@ var PDFViewerApplication = { } } + //$FB: prevent start in bookflip mode + if(scrollMode === _ui_utils.ScrollMode.FLIP) { + scrollMode = _ui_utils.ScrollMode.VERTICAL; + bookFlip.toStart = true; + $('#viewer').css({ opacity: 0 }); + } + if (pageMode && sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) { sidebarView = apiPageModeToSidebarView(pageMode); } @@ -3775,10 +3782,7 @@ function getVisibleElements(scrollEl, views) { numViews = views.length; var firstVisibleElementInd = numViews === 0 ? 0 : binarySearchFirstItem(views, horizontal ? isElementRightAfterViewLeft : isElementBottomAfterViewTop); - //%FB: get current page, 2 pages before and 2 pages after (need different handling) - if(bookFlip.active && scrollEl.id=='viewerContainer'){ - visible = bookFlip.load(views); - }else{ + if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) { firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top); } @@ -3813,7 +3817,6 @@ function getVisibleElements(scrollEl, views) { percent: percent }); } - } var first = visible[0], last = visible[visible.length - 1]; @@ -10815,8 +10818,7 @@ function () { var currentScale = this._currentScale; var currentScaleValue = this._currentScaleValue; var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue; - //%FB: fix page number in bookflip mode - var pageNumber = (bookFlip.active) ? this._currentPageNumber : firstPage.id; + var pageNumber = firstPage.id; var pdfOpenParams = '#page=' + pageNumber; pdfOpenParams += '&zoom=' + normalizedScaleValue; diff --git a/pdf-turn/pdf-turn.js b/pdf-turn/pdf-turn.js index 0b62ea4..04a0d90 100644 --- a/pdf-turn/pdf-turn.js +++ b/pdf-turn/pdf-turn.js @@ -15,12 +15,14 @@ var bookFlip = { toStart: false, //PDFjs require flipbook at start onLoad: true, //start PDFjs into flipbook mode _intoView: null,//link handler default function backup + _visPages: null,//visible pages function backup // event listeners when bookFlip need different handling init: function(){ $(document).on('rotationchanging', () => {bookFlip.rotate()}); $(document).on('scalechanging', () => {bookFlip.resize()}); $(document).on('pagechanging', () => {bookFlip.flip()}); + $(document).on('documentinit', () => {bookFlip.stop()}); $(document).on('scrollmodechanged', () => { var scroll = PDFViewerApplication.pdfViewer.scrollMode; @@ -46,20 +48,6 @@ var bookFlip = { } }); - $(document).on('documentloaded', () => { - bookFlip.stop(); - var scrollMode = PDFViewerApplicationOptions.get('scrollModeOnLoad'); - if (scrollMode === -1) { - scrollMode = PDFViewerApplication.store.file.scrollMode; - } - if(scrollMode === 3) { - bookFlip.toStart = true; - $('#viewer').css({ opacity: 0 }); - PDFViewerApplication.store.file.scrollMode = 0; - if(this.onLoad)PDFViewerApplicationOptions.set('scrollModeOnLoad',-1); - } - }); - $(document).on('baseviewerinit', () => { if(this.onLoad)PDFViewerApplicationOptions.set('scrollModeOnLoad',3); @@ -108,6 +96,9 @@ var bookFlip = { this._intoView = PDFViewerApplication.pdfViewer.scrollPageIntoView; PDFViewerApplication.pdfViewer.scrollPageIntoView = (data) => {return bookFlip.link(data)}; + this._visPages = PDFViewerApplication.pdfViewer._getVisiblePages; + PDFViewerApplication.pdfViewer._getVisiblePages = () => {return bookFlip.load()}; + $('.spreadModeButtons').removeClass('toggled'); $('#' + selected).addClass('toggled'); @@ -162,11 +153,12 @@ var bookFlip = { $('#viewer').turn('destroy'); $('#viewer').removeAttr('style'); + PDFViewerApplication.pdfViewer.scrollPageIntoView = this._intoView; + PDFViewerApplication.pdfViewer._getVisiblePages = this._visPages; + PDFViewerApplication.eventBus._listeners.switchspreadmode = this._evSpread; PDFViewerApplication.pdfViewer.spreadMode = this.__spread; - PDFViewerApplication.pdfViewer.scrollPageIntoView = this._intoView; - $('#viewer .page').removeAttr('style'); $('#viewer').removeClass('shadow'); $('#viewer').addClass('pdfViewer'); @@ -213,15 +205,15 @@ var bookFlip = { PDFViewerApplication.page = data.pageNumber; }, // load pages near shown page - load: function(views){ + load: function(){ if(!this.active)return; + var views = PDFViewerApplication.pdfViewer._pages; var arr = []; var page = PDFViewerApplication.page; var min = Math.max(page - ((this._spread === 0) ? 2 : (page%2) ? 4 : 3), 0); - var pos = Math.max(((this._spread === 0) ? page : page - (page%2)) -1, 0); var max = Math.min(page + ((this._spread === 0) ? 1 : (page%2) ? 2 : 3), views.length); - for (var i = pos, ii = max; i < ii; i++) { + for (var i = min, ii = max; i < ii; i++) { arr.push({ id: views[i].id, x: 0, @@ -230,18 +222,8 @@ var bookFlip = { percent: 100 }); } - for (var i = min, ii = pos; i < ii; i++) { - arr.push({ - id: views[i].id, - x: 0, - y: 0, - view: views[i], - percent: 100 - }); - } - if(this._spread !== 0 && (page%2) && page !== 1) [arr[0],arr[1]] = [arr[1],arr[0]] - - return arr; + + return {first:arr[page - min - 1],last:arr[arr.length-1],views:arr}; }, _spreadType: function(){ return (this._spread === 0) ? 'single' : 'double';