]> _ Git - fluidbook-html5.git/commitdiff
WIP #2498 @5
authorStephen Cameron <stephen@cubedesigners.com>
Tue, 15 Jan 2019 16:18:16 +0000 (17:18 +0100)
committerStephen Cameron <stephen@cubedesigners.com>
Tue, 15 Jan 2019 16:18:16 +0000 (17:18 +0100)
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/fluidbook.print.js
style/mixins.less
style/print.less

index c85bdd1c442379af5953d94cb495706383c4a93c..df9501329044f31056039c948eb014558f12fe35 100644 (file)
@@ -851,8 +851,16 @@ FluidbookMenu.prototype = {
                 });
                 break;
             case 'print':
-            case 'download':
+          case 'download':
                 w = 820;
+
+                // If the option to print the full brochure is disabled,
+                // we change the print dialogue to a 2 column mode and narrower width
+                if (!this.fluidbook.datas.printFullBrochure) {
+                    w = 560;
+                }
+
+                // Enable fullscreen when there's no longer enough width for the popup
                 if (ww < w) {
                     fullscreen = true;
                 }
index 2bbed8eed77ce7d876b462f69d313992bff7c81b..bc5b0841a06d6bdb280d65426fa8f79b44dc4c8d 100644 (file)
@@ -20,7 +20,9 @@ FluidbookPrint.prototype = {
                 element = $(this),
                 mode = element.data('mode'), // Either 'print' or 'download'
                 print = (mode == 'print'),
-                choice = $('input[name="pageChoice"]:checked').val();
+                choice = $('input[name="pageChoice"]:checked').val(),
+                rangeStart = parseInt($('#pageRangeStart').val()),
+                rangeEnd = parseInt($('#pageRangeEnd').val());
 
             switch (choice) {
               case 'left':
@@ -39,11 +41,29 @@ FluidbookPrint.prototype = {
               case 'bookmarks':
                 $this.fluidbook.bookmarks.openPDF(element, print);
                 break;
+              case 'range':
+                if (isNaN(rangeStart) ||
+                    isNaN(rangeEnd) ||
+                    (rangeStart < 1) ||
+                    (rangeEnd > $this.fluidbook.datas.pages) ||
+                    (rangeStart > rangeEnd)
+                ) {
+                  alert(__('Invalid page range. Please try again.'));
+                  return false;
+                }
+                var pageRange = rangeStart + '-' + rangeEnd;
+                $this.fluidbook._openFile(dynamicPDF + pageRange, element, 'pdf', pageRange + '.pdf', print);
+                break;
               default:
                 return false;
             }
         });
 
+        // Automatically select page range option when clicking in the input fields
+        $(document).on('focus', '.page-range-input', function() {
+          $('#pageRange').prop('checked', true);
+        });
+
         // When there are no bookmarks a click on the bookmarks option will open the bookmarks help modal
         $(document).on('click', '.bookmarks-option.disabled', function(event) {
             event.preventDefault();
@@ -131,17 +151,19 @@ FluidbookPrint.prototype = {
         }
 
         // Full Brochure
-        view += '<div class="print-option">';
-        view += '<label for="allPages">';
-        view += '<div class="doubleThumb">';
-        view += '<div class="thumb left">';
-        view += this.fluidbook.loader.getThumbImage(1, null, true);
-        view += '</div>'; // .thumb
-        view += '</div>'; // .doubleThumb
-        view += '</label>';
-        view += '<input type="radio" name="pageChoice" value="all" id="allPages">'
-        view += '<label for="allPages" class="print-label-text">' + __('entire brochure') + '</label>';
-        view += '</div>'; // .print-option
+        if ((mode === 'print' && this.fluidbook.datas.printFullBrochure) || mode === 'download') {
+          view += '<div class="print-option">';
+          view += '<label for="allPages">';
+          view += '<div class="doubleThumb">';
+          view += '<div class="thumb left">';
+          view += this.fluidbook.loader.getThumbImage(1, null, true);
+          view += '</div>'; // .thumb
+          view += '</div>'; // .doubleThumb
+          view += '</label>';
+          view += '<input type="radio" name="pageChoice" value="all" id="allPages">'
+          view += '<label for="allPages" class="print-label-text">' + __('entire brochure') + '</label>';
+          view += '</div>'; // .print-option
+        }
 
         // Bookmarks
         if (this.fluidbook.datas.bookmark) {
@@ -154,12 +176,33 @@ FluidbookPrint.prototype = {
           view += this.fluidbook.bookmarks.getPrintPreview();
           view += '</div>'; // .doubleThumb
           view += '</label>';
-          view += '<input type="radio" name="pageChoice" value="bookmarks" id="bookmarkedPages" '+ bookmarksDisabled +'>'
+          view += '<input type="radio" name="pageChoice" value="bookmarks" id="bookmarkedPages" '+ bookmarksDisabled +'>';
           view += '<label for="bookmarkedPages" class="print-label-text">' + __('bookmarks') + '</label>';
           view += '</div>'; // .print-option
         }
 
-        view += '<div class="print-option"></div>'; // Extra empty div to ensure flexbox space-between works as expected
+        view += '<div class="print-option blank"></div>'; // Extra empty div to ensure flexbox space-between works as expected
+
+        // Page range inputs
+        if (mode === 'print' && this.fluidbook.datas.printPageRange) {
+
+          // leftPageNumber may be false if on first page
+          var rangeStart = Math.max(leftPageNumber, 1);
+
+          // Current page + 1 unless we're out of range.
+          // It has to be calculated this way because sometimes there is no rightPageNumber
+          var rangeEnd = Math.min(rangeStart + 1, this.fluidbook.datas.pages);
+
+          view += '<div class="print-option page-range-option">';
+          view += '<input type="radio" name="pageChoice" value="range" id="pageRange">';
+          view += '<label for="pageRange">';
+          view += __('From page');
+          view += '<input class="page-range-input" type="text" id="pageRangeStart" value="' + rangeStart + '" autocomplete="off">';
+          view += __('to');
+          view += '<input class="page-range-input" type="text" id="pageRangeEnd" value="' + rangeEnd + '" autocomplete="off">';
+          view += '</label>';
+          view += '</div>'; // .print-option
+        }
 
         view += '</div>'; // .print-dialogue
 
index ae1e82c4ad3cc9ce4756f2e7c9ec527e0804bacd..e563fe2d73818efc8de36cd55a20df3e61f30b87 100644 (file)
 .menu-color-a(@background,@button) {
        background: @background;
 
+       input[type="text"] {
+               background: @button;
+       }
+
        .fonctions {
                a {
                        background-color: @button;
@@ -63,4 +67,4 @@
        &.hidden {
                opacity: 0;
        }
-}
\ No newline at end of file
+}
index 927858f1f8d2b3c41e902a5b8bc24282eb2d0050..a48156d5a33d9d1ae2893bd83e8c0ad968251387 100644 (file)
@@ -6,6 +6,7 @@
   justify-content: space-between;
   padding: 1.5em 2em 1em;
   margin-bottom: -2em; // Offset the margin-bottom on each <label> so there's no extra margin on last row
+  min-width: 320px;
 
   .print-option {
     flex: 0 0 200px;
 
     @media (max-width: 753px) {
       flex-basis: 50%;
+
+      &.blank {
+        display: none;
+      }
+
+      &:last-child {
+        margin-bottom: 3em;
+      }
     }
     @media (max-width: 550px) {
       flex-basis: 100%;
     }
   }
 
+  // Page range options
+  .page-range-option {
+    position: absolute;
+    left: 32px;
+    bottom: 40px;
+    margin-bottom: 0 !important;
+
+    @media (max-width: 559px) {
+      position: relative;
+      left: unset;
+      bottom: unset;
+      flex-basis: 100%;
+      margin-bottom: 3em !important;
+    }
+  }
+
+  .page-range-input {
+    width: 3.2em;
+    margin: 0 0.7em;
+    line-height: 1.8;
+    padding: 0 0.5em;
+    font-size: 14px;
+    border: none;
+    color: currentColor;
+  }
+
+
   // Custom radio buttons (requires input + label to be siblings in HTML)
   // Based on http://adrianroselli.com/2017/05/under-engineered-custom-radio-buttons-and-checkboxen.html
 
     width: 22px;
     height: 22px;
     margin-right: 0.5em;
-    margin-top: -0.1em;
+    margin-top: -1px; // Using ems caused rounding problems with position
     vertical-align: middle;
     cursor: pointer;
     text-align: center;