From 7240b0fe6259fd504a0ba1081d5275a4eb72839b Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Wed, 14 Nov 2018 17:00:52 +0100 Subject: [PATCH] WIP #1806 @7.5 --- js/libs/fluidbook/fluidbook.bookmarks.js | 2 - js/libs/fluidbook/fluidbook.js | 14 +++- js/libs/fluidbook/fluidbook.menu.js | 3 + js/libs/fluidbook/fluidbook.print.js | 87 ++++++++++++++++++------ style/print.less | 52 +++++++++++++- 5 files changed, 129 insertions(+), 29 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.bookmarks.js b/js/libs/fluidbook/fluidbook.bookmarks.js index 8a906126..4171ba1f 100644 --- a/js/libs/fluidbook/fluidbook.bookmarks.js +++ b/js/libs/fluidbook/fluidbook.bookmarks.js @@ -267,11 +267,9 @@ FluidbookBookmarks.prototype = { }, getLinkedPages: function (page) { var group = this.getGroupOfPage(page); - console.log('group : ' + group); if (group === -1 || isNaN(group)) { return []; } - console.log(this.getPagesOfGroup(group)); return this.getPagesOfGroup(group); }, addBookmark: function (page, cornersOnly) { diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 2879cdef..80a259bd 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -816,12 +816,20 @@ Fluidbook.prototype = { $("#pagesnumbers .right").html(this.getPageNumberOfSide('right')); $("#pagesnumbers").removeClass('hidden'); }, + getPhysicalPageNumberOfSide: function (side) { // Side should be 'left' or 'right' + var pageSide = $("#currentDoublePage").find('.' + side); + if (pageSide.length == 0) { + return false; + } + + return $(pageSide).data('page'); + }, getPageNumberOfSide: function (side) { - var p = $("#currentDoublePage").find('.' + side); - if (p.length == 0) { + var physical = this.getPhysicalPageNumberOfSide(side); + if (!physical) { return ''; } - return this.physicalToVirtual($(p).data('page')); + return this.physicalToVirtual(physical); }, clickLogo: function () { if (this.datas.url_link == '' || this.datas.url_link == 'http://') { diff --git a/js/libs/fluidbook/fluidbook.menu.js b/js/libs/fluidbook/fluidbook.menu.js index 16764737..3c578b13 100644 --- a/js/libs/fluidbook/fluidbook.menu.js +++ b/js/libs/fluidbook/fluidbook.menu.js @@ -468,6 +468,9 @@ FluidbookMenu.prototype = { $("#view").append('
' + printDialogue + '
'); + // Auto select first option (the options are dynamic so we can't do it until now) + $('.print-dialogue .print-option:first-of-type input[type="radio"]').prop('checked', true); + if (callback != undefined) { callback(); } diff --git a/js/libs/fluidbook/fluidbook.print.js b/js/libs/fluidbook/fluidbook.print.js index e879fa1d..9ef637f4 100644 --- a/js/libs/fluidbook/fluidbook.print.js +++ b/js/libs/fluidbook/fluidbook.print.js @@ -6,58 +6,98 @@ function FluidbookPrint(fluidbook) { FluidbookPrint.prototype = { init: function () { + var $this = this; + // Handle click on Print button inside dialogue $(document).on('click', '#confirmPrint', function(event) { event.preventDefault(); - // ToDo: handle print option selection - either send for full document or generate dynamic workshop URL. Need to also consider what happens if Fluidbook is self-hosted or offline (maybe here is not the best place to handle that) + // ToDo: Consider what happens if Fluidbook is self-hosted or offline (maybe here is not the best place to handle that) + + var dynamicPDF = 'https://workshop.fluidbook.com/s/e/' + $this.fluidbook.datas.cid + '/', + leftPageNumber = $this.fluidbook.getPhysicalPageNumberOfSide('left'), + rightPageNumber = $this.fluidbook.getPhysicalPageNumberOfSide('right'), + element = $(this), + choice = $('input[name="printChoice"]:checked').val(); + + switch (choice) { + case 'left': + $this.fluidbook._openFile(dynamicPDF + leftPageNumber, element, 'pdf', leftPageNumber + '.pdf', true); + break; + case 'right': + $this.fluidbook._openFile(dynamicPDF + rightPageNumber, element, 'pdf', rightPageNumber + '.pdf', true); + break; + case 'double': + var pageRange = leftPageNumber + '-' + rightPageNumber; + $this.fluidbook._openFile(dynamicPDF + pageRange, element, 'pdf', pageRange + '.pdf', true); + break; + case 'all': + $this.fluidbook.openPDF(element, true); + break; + case 'bookmarks': + $this.fluidbook.bookmarks.openPDF(element, true); + break; + default: + return false; + } + }); }, getView: function () { // Todo: handle RTL differences for page numbers? See fluidbook.index.js for example - var leftPageNumber = parseInt(this.fluidbook.getPageNumberOfSide('left')), - rightPageNumber = parseInt(this.fluidbook.getPageNumberOfSide('right')), + var leftPageNumber = this.fluidbook.getPhysicalPageNumberOfSide('left'), + rightPageNumber = this.fluidbook.getPhysicalPageNumberOfSide('right'), isFirstPage = (this.fluidbook.currentPage == 0), isLastPage = (this.fluidbook.currentPage == this.fluidbook.datas.pages), + isSinglePageMode = (this.fluidbook.resize.orientation == 'portrait'); printDialogue = ''; printDialogue += '
'; printDialogue += '