Add print page feature. Only testing in FF3 so far. LP #294411.
authorrajbot <raj@archive.org>
Tue, 12 May 2009 00:47:25 +0000 (17:47 -0700)
committerrajbot <raj@archive.org>
Tue, 12 May 2009 00:47:25 +0000 (17:47 -0700)
GnuBook/GnuBook.css
GnuBook/GnuBook.js
GnuBook/GnuBookEmbed.css
GnuBookIA/GnuBookJSLocate.php
GnuBookIA/GnuBookPrint.php [new file with mode: 0644]

index 392208c..05fb36a 100644 (file)
@@ -91,6 +91,7 @@
 .GBicon.one_page_mode { background: url(images/one_page_mode_icon.png) no-repeat; }
 .GBicon.two_page_mode { background: url(images/two_page_mode_icon.png) no-repeat; }
 .GBicon.embed { background: url(images/embed_icon.png) no-repeat; }
+.GBicon.print { background: url(images/print_icon.png) no-repeat; }
 .GBicon.book_left { background: url(images/book_left_icon.png) no-repeat; }
 .GBicon.book_right { background: url(images/book_right_icon.png) no-repeat; }
 .GBicon.book_up { background: url(images/book_up_icon.png) no-repeat; }
index 5ce038b..56e6e19 100644 (file)
@@ -49,6 +49,7 @@ function GnuBook() {
     this.twoPagePopUp = null;
     this.leafEdgeTmp  = null;
     this.embedPopup = null;
+    this.printPopup = null;
     
     this.searchResults = {};
     
@@ -1685,6 +1686,38 @@ GnuBook.prototype.removeSearchHilites = function() {
     }
 }
 
+// printPage
+//______________________________________________________________________________
+GnuBook.prototype.printPage = function() {
+    if (null != this.printPopup) { // check if already showing
+        return;
+    }
+    this.printPopup = document.createElement("div");
+    $(this.printPopup).css({
+        position: 'absolute',
+        top:      '20px',
+        left:     ($('#GBcontainer').width()-400)/2 + 'px',
+        width:    '500px',
+        padding:  "20px",
+        border:   "3px double #999999",
+        zIndex:   3,
+        backgroundColor: "#fff"
+    }).appendTo('#GnuBook');
+
+    var indexToPrint;
+    if (1 == this.mode) {
+        indexToPrint = this.firstIndex;
+    } else {
+        indexToPrint = this.currentLeafL;
+    }
+
+    htmlStr =  '<p style="text-align:center;"><b><a href="javascript:void(0);" onclick="window.frames[0].print(); return false;">Click here to print this page</a></b></p>';
+    htmlStr += '<iframe name ="printFrame" id="printFrame" src="GnuBookPrint.php?id='+this.bookId+'&server='+this.server+'&zip='+this.zip+'&index='+this.leafMap[indexToPrint]+'&format='+this.imageFormat+'" width="500px" height="400px"></iframe>';
+    htmlStr += '<p style="text-align:center;"><a href="" onclick="gb.printPopup = null; $(this.parentNode.parentNode).remove(); return false">Close popup</a></p>';    
+
+    this.printPopup.innerHTML = htmlStr;    
+}
+
 // showEmbedCode()
 //______________________________________________________________________________
 GnuBook.prototype.showEmbedCode = function() {
@@ -1860,7 +1893,7 @@ GnuBook.prototype.initToolbar = function(mode) {
     
     // We build in mode 2
     jToolbar.append("<span id='GBtoolbarbuttons' style='float: right'>"
-        + "<button class='GBicon rollover embed' />"
+        + "<button class='GBicon print' /> <button class='GBicon rollover embed' />"
         + "<form class='GBpageform' action='javascript:' onsubmit='gb.jumpToPage(this.elements[0].value)'> <span class='label'>Page:<input id='GBpagenum' type='text' size='3' onfocus='gb.autoStop();'></input></span></form>"
         + "<div class='GBtoolbarmode2' style='display: inline'><button class='GBicon rollover book_leftmost' /><button class='GBicon rollover book_left' /><button class='GBicon rollover book_right' /><button class='GBicon rollover book_rightmost' /></div>"
         + "<div class='GBtoolbarmode1' style='display: hidden'><button class='GBicon rollover book_top' /><button class='GBicon rollover book_up' /> <button class='GBicon rollover book_down' /><button class='GBicon rollover book_bottom' /></div>"
@@ -1874,6 +1907,7 @@ GnuBook.prototype.initToolbar = function(mode) {
                    '.zoom_out': 'Zoom out',
                    '.one_page_mode': 'One-page view',
                    '.two_page_mode': 'Two-page view',
+                   '.print': 'Print this page',
                    '.embed': 'Embed bookreader',
                    '.book_left': 'Flip left',
                    '.book_right': 'Flip right',
@@ -1942,6 +1976,11 @@ GnuBook.prototype.bindToolbarNavHandlers = function(jToolbar) {
         gb.next();
         return false;
     });
+
+    jToolbar.find('.print').bind('click', function(e) {
+        gb.printPage();
+        return false;
+    });
         
     jToolbar.find('.embed').bind('click', function(e) {
         gb.showEmbedCode();
@@ -2031,4 +2070,4 @@ GnuBook.prototype.shortTitle = function(maximumCharacters) {
     var title = this.bookTitle.substr(0, maximumCharacters - 3);
     title += '...';
     return title;
-}
\ No newline at end of file
+}
index 1b77901..d79348c 100644 (file)
@@ -8,4 +8,4 @@
 
 #GBtoolbar .title {
     font-size: 0.9em;
-}
\ No newline at end of file
+}
index 5ec166f..b6476b1 100644 (file)
@@ -38,7 +38,7 @@ if (preg_match("/^www-(\w+)/", $_SERVER["SERVER_NAME"], $match)) {
     // $$$ the remapping isn't totally automatic yet and requires user to
     //     ln -s ~/petabox/www/datanode/GnuBook ~/public_html/GnuBook
     //     so we enable it only for known hosts
-    $devhosts = array('mang', 'testflip');
+    $devhosts = array('mang', 'testflip', 'rkumar');
     if (in_array($match[1], $devhosts)) {
         $serverBaseURL = $serverBaseURL . ":81/~" . $match[1];
     }
diff --git a/GnuBookIA/GnuBookPrint.php b/GnuBookIA/GnuBookPrint.php
new file mode 100644 (file)
index 0000000..94450d9
--- /dev/null
@@ -0,0 +1,35 @@
+<?
+/*
+Copyright(c)2008 Internet Archive. Software license AGPL version 3.
+
+This file is part of GnuBook.
+
+    GnuBook is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    GnuBook is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with GnuBook.  If not, see <http://www.gnu.org/licenses/>.
+
+GnuBookPrint.php exists to get around the same-origin policy that prevents
+us from calling print() on an iframe that comes from a cluster datanode.
+*/
+
+$id     = $_REQUEST['id'];
+$server = $_REQUEST['server'];
+$zip    = $_REQUEST['zip'];
+$index  = $_REQUEST['index'];
+$format = $_REQUEST['format'];
+
+$file = sprintf("%s_%s/%s_%04d.%s", $id, $format, $id, $index, $format);
+echo "<p style='text-align:center;'>";
+echo "<img src='http://{$server}/GnuBook/GnuBookImages.php?zip={$zip}&file={$file}&scale=1' height='100%'/>";
+echo "</p>";
+
+?>
\ No newline at end of file