]> _ Git - fluidbook-html5.git/commitdiff
WIP #1806 @7.5
authorStephen Cameron <stephen@cubedesigners.com>
Tue, 13 Nov 2018 16:54:11 +0000 (17:54 +0100)
committerStephen Cameron <stephen@cubedesigners.com>
Tue, 13 Nov 2018 16:54:11 +0000 (17:54 +0100)
js/libs/fluidbook/fluidbook.bookmarks.js
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/fluidbook.print.js [new file with mode: 0644]
style/print.less

index d8e7d1b1ec03069901fa0094fd3a8438860711a8..8a90612624574db85e50abcb6dc45a0557654870 100644 (file)
@@ -491,6 +491,39 @@ FluidbookBookmarks.prototype = {
 
     // Used by the print function. Will return maximum of 3 pages or a blank page if no bookmarks.
     getPrintPreview: function() {
-        return '[bookmark images go here]';
+
+        if (!this.hasBookmarkedPages()) {
+            return '<div class="thumb left blank"></div>';
+        }
+
+
+        var maxImages = 3, // How many images maximum to show in the bookmarks print preview thumbnail
+            count = 0,
+            html = '',
+            groups = this.getBookmarkedGroups();
+
+        html += '<div class="bookmark-thumbnails">';
+
+        for (var g = 0; g < groups.length; g++) {
+            count++;
+            var group = groups[g];
+
+            html += '<div class="thumb">' + this.fluidbook.loader.getThumbImage(group.page);
+
+            if (this.fluidbook.bookmarks.enabled) {
+              html += this.fluidbook.bookmarks.getBookmarkForPage(group.page, true, true);
+            }
+
+            html += '</div>';
+
+            // Stop once we have enough images for the preview
+            if (count >= maxImages) {
+                break;
+            }
+        }
+
+        html += '</div>';
+
+        return html;
     }
 };
index 94bcb5ac3254b1bacb81b8f6c6294a697ca8df3e..2879cdeff04428d4f292551d0acd6a57b9453018 100644 (file)
@@ -55,6 +55,7 @@ Fluidbook.prototype = {
         this.audiodescription = new FluidbookAudioDescription(this);
         this.sound = new FluidbookSound(this);
         this.slideshow = new FluidbookSlideshow(this);
+        this.printing = new FluidbookPrint(this);
 
 
         if (this.datas.basket) {
index 31ab0666b21c77330a5772e7c1d0df657a65ce92..167647377b734dabe6c854b0c2db0d9839b136aa 100644 (file)
@@ -462,89 +462,12 @@ FluidbookMenu.prototype = {
     },
 
     openPrint: function (callback) {
-        // 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')),
-            isFirstPage = (this.fluidbook.currentPage == 0),
-            isLastPage = (this.fluidbook.currentPage == this.fluidbook.datas.pages),
-            printDialogue = '<div class="caption">' + this.closeButton() + '<h2>' + __('Print') + '</h2></div>';
-        printDialogue += '<div class="content">';
-        printDialogue += '<div class="print-dialogue">';
-
-        // ToDo: implement http://adrianroselli.com/2017/05/under-engineered-custom-radio-buttons-and-checkboxen.html - might need 2 labels for each input so thumbnails are clickable too.
-
-        // Left Page (empty when on first page)
-        if (!isFirstPage) {
-            printDialogue += '<label for="leftPage">';
-            printDialogue += '<div class="doubleThumb">';
-            printDialogue += '<div class="thumb left">';
-            printDialogue += this.fluidbook.loader.getThumbImage(leftPageNumber, null, true);
-            printDialogue += '</div>'; // .thumb
-            printDialogue += '<div class="thumb right blank"></div>';
-            printDialogue += '</div>'; // .doubleThumb
-            printDialogue += '<input type="radio" name="printChoice" value="'+ leftPageNumber +'" id="leftPage">';
-            printDialogue += '<span class="print-label-text">' + __('Left page') + '</span>';
-            printDialogue += '</label>';
-        }
-
-        // Right Page (empty when when on last page)
-        if (!isLastPage) {
-            printDialogue += '<label for="rightPage">';
-            printDialogue += '<div class="doubleThumb">';
-            printDialogue += '<div class="thumb left blank"></div>';
-            printDialogue += '<div class="thumb right">';
-            printDialogue += this.fluidbook.loader.getThumbImage(rightPageNumber, null, true);
-            printDialogue += '</div>'; // .thumb
-            printDialogue += '</div>'; // .doubleThumb
-            printDialogue += '<input type="radio" name="printChoice" value="'+ leftPageNumber +'" id="rightPage">';
-            printDialogue += '<span class="print-label-text">' + __('Right page') + '</span>';
-            printDialogue += '</label>';
-        }
-
-        // Double Page
-        if (!isFirstPage && !isLastPage) {
-            printDialogue += '<label for="doublePage">';
-            printDialogue += '<div class="doubleThumb">';
-            printDialogue += '<div class="thumb left">';
-            printDialogue += this.fluidbook.loader.getThumbImage(leftPageNumber, null, true);
-            printDialogue += '</div>';
-            printDialogue += '<div class="thumb right">';
-            printDialogue += this.fluidbook.loader.getThumbImage(rightPageNumber, null, true);
-            printDialogue += '</div>'; // .thumb
-            printDialogue += '</div>'; // .doubleThumb
-            printDialogue += '<input type="radio" name="printChoice" value="'+ leftPageNumber +','+ rightPageNumber +'" id="doublePage">'
-            printDialogue += '<span class="print-label-text">' + __('Double page') + '</span>';
-            printDialogue += '</label>';
-        }
-
-        // Full Brochure
-        printDialogue += '<label for="allPages">';
-        printDialogue += '<div class="doubleThumb">';
-        printDialogue += '<div class="thumb left">';
-        printDialogue += this.fluidbook.loader.getThumbImage(1, null, true);
-        printDialogue += '</div>'; // .thumb
-        printDialogue += '</div>'; // .doubleThumb
-        printDialogue += '<input type="radio" name="printChoice" value="all" id="allPages">'
-        printDialogue += '<span class="print-label-text">' + __('Full brochure') + '</span>';
-        printDialogue += '</label>';
-
-        // Bookmarks
-        var hasBookmarks = this.fluidbook.bookmarks.hasBookmarkedPages(),
-            bookmarksDisabled = hasBookmarks ? '' : 'disabled';
-
-        printDialogue += '<label for="bookmarkedPages">';
-        printDialogue += '<div class="doubleThumb bookmarks '+ bookmarksDisabled +'">';
-        printDialogue += this.fluidbook.bookmarks.getPrintPreview();
-        printDialogue += '</div>'; // .doubleThumb
-        printDialogue += '<input type="radio" name="printChoice" value="bookmarks" id="bookmarkedPages" '+ bookmarksDisabled +'>'
-        printDialogue += '<span class="print-label-text">' + __('My bookmarks') + '</span>';
-        printDialogue += '</label>';
-
-
-        printDialogue += '</div>'; // .print-dialogue
-        printDialogue += '</div>'; // .content
+        var printDialogue = '<div class="caption">' + this.closeButton() + '<h2>' + __('Print') + '</h2></div>';
+
+        printDialogue += this.fluidbook.printing.getView();
 
         $("#view").append('<div class="mview" data-menu="print">' + printDialogue + '</div>');
+
         if (callback != undefined) {
             callback();
         }
diff --git a/js/libs/fluidbook/fluidbook.print.js b/js/libs/fluidbook/fluidbook.print.js
new file mode 100644 (file)
index 0000000..e879fa1
--- /dev/null
@@ -0,0 +1,110 @@
+function FluidbookPrint(fluidbook) {
+    this.fluidbook = fluidbook;
+    this.init();
+}
+
+FluidbookPrint.prototype = {
+    init: function () {
+
+        // 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)
+
+        });
+    },
+
+    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')),
+            isFirstPage = (this.fluidbook.currentPage == 0),
+            isLastPage = (this.fluidbook.currentPage == this.fluidbook.datas.pages),
+            printDialogue = '';
+
+        printDialogue += '<div class="content">';
+        printDialogue += '<div class="print-dialogue">';
+
+        // ToDo: implement http://adrianroselli.com/2017/05/under-engineered-custom-radio-buttons-and-checkboxen.html - might need 2 labels for each input so thumbnails are clickable too.
+
+        // Left Page (empty when on first page)
+        if (!isFirstPage) {
+            printDialogue += '<label for="leftPage">';
+            printDialogue += '<div class="doubleThumb">';
+            printDialogue += '<div class="thumb left">';
+            printDialogue += this.fluidbook.loader.getThumbImage(leftPageNumber, null, true);
+            printDialogue += '</div>'; // .thumb
+            printDialogue += '<div class="thumb right blank"></div>';
+            printDialogue += '</div>'; // .doubleThumb
+            printDialogue += '<input type="radio" name="printChoice" value="'+ leftPageNumber +'" id="leftPage">';
+            printDialogue += '<span class="print-label-text">' + (isLastPage ? __('Current page') : __('Left page')) + '</span>';
+            printDialogue += '</label>';
+        }
+
+        // Right Page (empty when when on last page)
+        if (!isLastPage) {
+            printDialogue += '<label for="rightPage">';
+            printDialogue += '<div class="doubleThumb">';
+            printDialogue += '<div class="thumb left blank"></div>';
+            printDialogue += '<div class="thumb right">';
+            printDialogue += this.fluidbook.loader.getThumbImage(rightPageNumber, null, true);
+            printDialogue += '</div>'; // .thumb
+            printDialogue += '</div>'; // .doubleThumb
+            printDialogue += '<input type="radio" name="printChoice" value="'+ leftPageNumber +'" id="rightPage">';
+            printDialogue += '<span class="print-label-text">' + (isFirstPage ? __('Current page') : __('Right page')) + '</span>';
+            printDialogue += '</label>';
+        }
+
+        // Double Page
+        if (!isFirstPage && !isLastPage) {
+            printDialogue += '<label for="doublePage">';
+            printDialogue += '<div class="doubleThumb">';
+            printDialogue += '<div class="thumb left">';
+            printDialogue += this.fluidbook.loader.getThumbImage(leftPageNumber, null, true);
+            printDialogue += '</div>';
+            printDialogue += '<div class="thumb right">';
+            printDialogue += this.fluidbook.loader.getThumbImage(rightPageNumber, null, true);
+            printDialogue += '</div>'; // .thumb
+            printDialogue += '</div>'; // .doubleThumb
+            printDialogue += '<input type="radio" name="printChoice" value="'+ leftPageNumber +','+ rightPageNumber +'" id="doublePage">'
+            printDialogue += '<span class="print-label-text">' + __('Double page') + '</span>';
+            printDialogue += '</label>';
+        }
+
+        // Full Brochure
+        printDialogue += '<label for="allPages">';
+        printDialogue += '<div class="doubleThumb">';
+        printDialogue += '<div class="thumb left">';
+        printDialogue += this.fluidbook.loader.getThumbImage(1, null, true);
+        printDialogue += '</div>'; // .thumb
+        printDialogue += '</div>'; // .doubleThumb
+        printDialogue += '<input type="radio" name="printChoice" value="all" id="allPages">'
+        printDialogue += '<span class="print-label-text">' + __('Full brochure') + '</span>';
+        printDialogue += '</label>';
+
+        // Bookmarks
+        var hasBookmarks = this.fluidbook.bookmarks.hasBookmarkedPages(),
+        bookmarksDisabled = hasBookmarks ? '' : 'disabled';
+
+        printDialogue += '<label for="bookmarkedPages">';
+        printDialogue += '<div class="doubleThumb bookmarks '+ bookmarksDisabled +'">';
+        printDialogue += this.fluidbook.bookmarks.getPrintPreview();
+        printDialogue += '</div>'; // .doubleThumb
+        printDialogue += '<input type="radio" name="printChoice" value="bookmarks" id="bookmarkedPages" '+ bookmarksDisabled +'>'
+        printDialogue += '<span class="print-label-text">' + __('My bookmarks') + '</span>';
+        printDialogue += '</label>';
+
+        printDialogue += '</div>'; // .print-dialogue
+
+        // Action buttons
+        printDialogue += '<div class="fonctions">';
+        printDialogue += '<a id="confirmPrint" href="#">'+ __('Print') +'</a>';
+        printDialogue += '</div>'; // .fonctions
+
+        printDialogue += '</div>'; // .content
+
+        return printDialogue;
+    }
+};
+
index 5773d10b83cc560cdd29e71fd889a426f21d047f..9292ec67e6f08f2f8b6da3e08f14cc547fbf96c0 100644 (file)
@@ -4,6 +4,7 @@
   flex-wrap: wrap;
   text-align: left;
   padding: 1em 2em;
+  margin-bottom: -2em; // Offset the margin-bottom on each <label> so there's no extra margin on last row
 
   > label {
     flex: 0 1 33%;
     margin-bottom: 1em;
   }
 
+  .thumb.right {
+    left: 100px; // Override default so there's no gap between pages
+  }
+
+  .bookmark-thumbnails {
+    .thumb {
+      &:before {
+        width: 113px; // Controls drop shadow on right side of thumbnail
+      }
+
+      &:nth-child(1) {
+        z-index: 3;
+      }
+      &:nth-child(2) {
+        left: 50px;
+        z-index: 2;
+      }
+      &:nth-child(3) {
+        left: 100px;
+        z-index: 1;
+      }
+    }
+
+    .bookmark {
+      pointer-events: none; // Disable hover/click on bookmark icons in this context
+    }
+  }
+
+
 }