]> _ Git - fluidbook-html5.git/commitdiff
WIP #1806 @7
authorStephen Cameron <stephen@cubedesigners.com>
Mon, 12 Nov 2018 18:01:59 +0000 (19:01 +0100)
committerStephen Cameron <stephen@cubedesigners.com>
Mon, 12 Nov 2018 18:01:59 +0000 (19:01 +0100)
js/libs/fluidbook/fluidbook.bookmarks.js
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/fluidbook.nav.js
style/fluidbook.less
style/print.less [new file with mode: 0644]

index 1a5bdeac0eb412531b2a5ded3eafa6f67cc580ba..d8e7d1b1ec03069901fa0094fd3a8438860711a8 100644 (file)
@@ -56,7 +56,7 @@ FluidbookBookmarks.prototype = {
                 $this.fluidbook.alertInternetRequired();
                 return false;
             }
-            $this.fluidbook._openFile($this.getPDF(), $(this), 'pdf', $this.getBookmarksCompacted() + '.pdf');
+            $this.openPDF($(this), true);
             return false;
         });
 
@@ -81,6 +81,10 @@ FluidbookBookmarks.prototype = {
     sortnumeric: function (a, b) {
         return a - b;
     },
+    openPDF: function(element, print) {
+      print = print || false;
+      this.fluidbook._openFile(this.getPDF(), element, 'pdf', this.getBookmarksCompacted() + '.pdf', print);
+    },
     getPDF: function () {
         return 'https://workshop.fluidbook.com/s/e/' + this.fluidbook.datas.cid + '/' + this.getBookmarksCompacted();
     },
@@ -477,10 +481,16 @@ FluidbookBookmarks.prototype = {
 
         }
         if (this.fluidbook.datas.print || this.fluidbook.datas.pdf) {
+            // ToDo: differentiate between download & print?
             index += '<a class="print" href="#">' + downloadLabel + '</a>';
         }
         index += '</div>';
         index += '</div>';
         return index;
+    },
+
+    // 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]';
     }
 };
index 10200c8b8895551abd31de36a5b2982f2536f643..31ab0666b21c77330a5772e7c1d0df657a65ce92 100644 (file)
@@ -97,6 +97,8 @@ FluidbookMenu.prototype = {
             this.openIframe(param1, cb);
         } else if (view == 'search') {
             this.openSearch(param1, cb);
+        } else if (view == 'print') {
+            this.openPrint(cb);
         } else {
             this['open' + camelView](param1, param2, cb);
         }
@@ -459,6 +461,95 @@ 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
+
+        $("#view").append('<div class="mview" data-menu="print">' + printDialogue + '</div>');
+        if (callback != undefined) {
+            callback();
+        }
+    },
+
     closeView: function (callback, all, animate) {
         if (callback === undefined) {
             callback = function () {
index 12081a4ebcc5f9e2c42a9578955f815f4aa20d0c..680cb7aac0af9b74368b44981fdecc8919bc6be5 100644 (file)
@@ -414,7 +414,7 @@ FluidbookNav.prototype = {
             } else if (icon == 'pdf' && this.fluidbook.datas.pdf) {
                 link = this.addLink(navType, 'nav-download', '#', 'download', 'download', 'download');
             } else if (icon == 'print' && this.fluidbook.datas.print) {
-                link = this.addLink(navType, 'nav-print', '#', 'print', 'print', 'print');
+                link = this.addLink(navType, 'nav-print', '#/print', 'print', 'print', 'print');
             } else if (icon == 'basket' && this.fluidbook.cart != undefined && this.fluidbook.cart.enabled) {
                 link = this.addLink(navType, 'nav-basket', '#/cart', 'cart', 'basket', 'basket');
                 $(this.fluidbook).on('fluidbook.cart.updateIcon', {link: $(link).attr('id')}, function (e, data) {
@@ -694,10 +694,10 @@ FluidbookNav.prototype = {
         });
 
         // Print icon
-        $(document).on('click', '.icon-print', function () {
-            $this.fluidbook.print($(this));
-            return false;
-        });
+        // $(document).on('click', '.icon-print', function () {
+        //     $this.fluidbook.print($(this));
+        //     return false;
+        // });
 
         // Bookmarks icon
         $(document).on('click', '.icon-bookmarks', function () {
index 21c5571cc07eb8d6d2f0269d861ad4ab95ab6997..08a5276e6712d2dd2a426139889d34019717d4f9 100644 (file)
@@ -1363,6 +1363,10 @@ html.ios body.portrait #interface {
                }
        }
 
+       &[data-menu="print"] {
+               max-width: 820px;
+       }
+
        &[data-menu="bookmarks-help"] {
                .content {
                        padding: 40px 70px 100px 70px;
@@ -2932,4 +2936,6 @@ body > input {
        }
 }
 
+@import "print.less";
+
 @import "additional.less";
diff --git a/style/print.less b/style/print.less
new file mode 100644 (file)
index 0000000..5773d10
--- /dev/null
@@ -0,0 +1,22 @@
+/* Printing Options */
+.print-dialogue {
+  display: flex;
+  flex-wrap: wrap;
+  text-align: left;
+  padding: 1em 2em;
+
+  > label {
+    flex: 0 1 33%;
+    margin-bottom: 2em;
+    position: relative;
+  }
+
+  input[type="radio"] {
+    margin-right: 1em;
+  }
+
+  .doubleThumb {
+    margin-bottom: 1em;
+  }
+
+}