Skip to content

Commit

Permalink
Fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
RaffaeleMorganti committed Sep 20, 2019
1 parent 086d754 commit 8967f5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 38 deletions.
16 changes: 9 additions & 7 deletions external/pdfjs-2.1.266-dist/web/viewer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 13 additions & 31 deletions pdf-turn/pdf-turn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand All @@ -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';
Expand Down

0 comments on commit 8967f5f

Please # to comment.