Add ability to go to previous or next pages when printing.
authorMichael Ang <mang@archive.org>
Mon, 21 Sep 2009 21:00:49 +0000 (21:00 +0000)
committerMichael Ang <mang@archive.org>
Mon, 21 Sep 2009 21:00:49 +0000 (21:00 +0000)
GnuBook/GnuBook.js

index 2861113..9ac1ee4 100644 (file)
@@ -2418,7 +2418,10 @@ GnuBook.prototype.printPage = function() {
         indexToPrint = this.twoPage.currentIndexL;
     }
     
+    this.indexToPrint = indexToPrint;
+    
     var htmlStr =  '<p style="text-align:center;"><b><a href="javascript:void(0);" onclick="window.frames[0].focus(); window.frames[0].print(); return false;">Click here to print this page</a></b></p>';
+    htmlStr += '<p align="right"><a href="#" onclick="gb.updatePrintFrame(-1); return false;">Prev</a> <a href="#" onclick="gb.updatePrintFrame(1); return false;">Next</a></p>';
     htmlStr += '<div id="printDiv" name="printDiv"></div>';
     htmlStr += '<p style="text-align:center;"><a href="" onclick="gb.printPopup = null; $(this.parentNode.parentNode).remove(); return false">Close popup</a></p>';    
     
@@ -2434,7 +2437,7 @@ GnuBook.prototype.printPage = function() {
         
     $(iframe).load(function() {
         var doc = GnuBook.util.getIFrameDocument(this);
-        $('body', doc).html(self.getPrintFrameContent(indexToPrint));
+        $('body', doc).html(self.getPrintFrameContent(self.indexToPrint));
     });
     
     $('#printDiv').append(iframe);
@@ -2471,6 +2474,17 @@ GnuBook.prototype.getPrintFrameContent = function(index) {
     return iframeStr;
 }
 
+GnuBook.prototype.updatePrintFrame = function(delta) {
+    var newIndex = this.indexToPrint + delta;
+    newIndex = GnuBook.util.clamp(newIndex, 0, this.numLeafs - 1);
+    if (newIndex == this.indexToPrint) {
+        return;
+    }
+    this.indexToPrint = newIndex;
+    var doc = GnuBook.util.getIFrameDocument($('#printFrame')[0]);
+    $('body', doc).html(this.getPrintFrameContent(this.indexToPrint));
+}
+
 // showEmbedCode()
 //______________________________________________________________________________
 GnuBook.prototype.showEmbedCode = function() {