Merge branch 'newui' of https://github.com/rajbot/bookreader into raj-merge
authorMichael Ang <mang@archive.org>
Wed, 10 Nov 2010 20:51:58 +0000 (20:51 +0000)
committerMichael Ang <mang@archive.org>
Wed, 10 Nov 2010 20:51:58 +0000 (20:51 +0000)
BookReader/BookReader.js
BookReaderIA/datanode/BookReaderJSIA.php
BookReaderIA/datanode/BookReaderMeta.inc.php
BookReaderIA/inc/BookReader.inc

index 9911930..60ceea9 100644 (file)
@@ -191,18 +191,9 @@ BookReader.prototype.init = function() {
     $("#BookReader").empty();
         
     this.initToolbar(this.mode, this.ui); // Build inside of toolbar div
-    
-    $("#BookReader").append("<div id='BRcontainer'></div>");
+    $("#BookReader").append("<div id='BRcontainer' dir='ltr'></div>");
     $("#BRcontainer").append("<div id='BRpageview'></div>");
         
-    // Autohide nav after showing for awhile
-    var self = this;
-    if (this.uiAutoHide) {
-        $(window).bind('load', function() {
-            setTimeout(function() { self.hideNavigation(); }, 3000);
-        });
-    };
-
     $("#BRcontainer").bind('scroll', this, function(e) {
         e.data.loadLeafs();
     });
@@ -212,6 +203,7 @@ BookReader.prototype.init = function() {
 
     $(window).bind('resize', this, function(e) {
         //console.log('resize!');
+
         if (1 == e.data.mode) {
             //console.log('centering 1page view');
             if (e.data.autofit) {
@@ -265,9 +257,7 @@ BookReader.prototype.init = function() {
         this.firstIndex = startIndex;
         this.prepareThumbnailView();
         this.jumpToIndex(startIndex);
-    } else {
-        //this.resizePageView();
-        
+    } else {        
         this.displayedIndices=[0];
         this.firstIndex = startIndex;
         this.displayedIndices = [this.firstIndex];
@@ -283,11 +273,12 @@ BookReader.prototype.init = function() {
     // it should start (doesn't jump after init)
     this.initNavbar();
     this.bindNavigationHandlers();
-    
+
     // Start AJAX request for OL data
     if (this.getOpenLibraryRecord) {
         this.getOpenLibraryRecord(this.gotOpenLibraryRecord);
     }
+
 }
 
 BookReader.prototype.setupKeyListeners = function() {
@@ -1578,7 +1569,7 @@ BookReader.prototype.prepareTwoPageView = function(centerPercentageX, centerPerc
     
     //this.indicesToDisplay=[firstLeaf, firstLeaf+1];
     //console.log('indicesToDisplay: ' + this.indicesToDisplay[0] + ' ' + this.indicesToDisplay[1]);
-    
+        
     this.drawLeafsTwoPage();
     this.updateToolbarZoom(this.reduce);
     
@@ -1673,7 +1664,7 @@ BookReader.prototype.calculateSpreadSize = function() {
         // set based on reduction factor
         spreadSize = this.getSpreadSizeFromReduce(firstIndex, secondIndex, this.reduce);
     }
-    
+        
     // Both pages together
     this.twoPage.height = spreadSize.height;
     this.twoPage.width = spreadSize.width;
@@ -1745,7 +1736,7 @@ BookReader.prototype.getIdealSpreadSize = function(firstIndex, secondIndex) {
         height: this._getPageHeight(secondIndex),
         width: this._getPageWidth(secondIndex)
     }
-    
+        
     var firstIndexRatio  = first.height / first.width;
     var secondIndexRatio = second.height / second.width;
     //console.log('firstIndexRatio = ' + firstIndexRatio + ' secondIndexRatio = ' + secondIndexRatio);
@@ -1753,10 +1744,8 @@ BookReader.prototype.getIdealSpreadSize = function(firstIndex, secondIndex) {
     var ratio;
     if (Math.abs(firstIndexRatio - canon5Dratio) < Math.abs(secondIndexRatio - canon5Dratio)) {
         ratio = firstIndexRatio;
-        //console.log('using firstIndexRatio ' + ratio);
     } else {
         ratio = secondIndexRatio;
-        //console.log('using secondIndexRatio ' + ratio);
     }
 
     var totalLeafEdgeWidth = parseInt(this.numLeafs * 0.1);
@@ -3736,10 +3725,10 @@ BookReader.prototype.initToolbar = function(mode, ui) {
         // $$$ Don't hardcode ids
     jToolbar.find('.share').colorbox({inline: true, opacity: "0.5", href: "#shareThis"});
     jToolbar.find('.info').colorbox({inline: true, opacity: "0.5", href: "#aboutThis"});
-        
+    
     $("body").append(
         [
-            '<div style="display: hidden;">',
+            '<div style="display: none;">',
                 this.makeShareDiv(),
                 this.makeAboutDiv(),
             '</div>'
@@ -4557,15 +4546,16 @@ BookReader.prototype._getPageURI = function(index, reduce, rotate) {
 BookReader.prototype.gotOpenLibraryRecord = function(self, olObject) {
     // $$$ could refactor this so that 'this' is available
     if (olObject) {
+        // console.log(olObject);
         if (olObject['table_of_contents']) {
             // XXX check here that TOC is valid
             self.updateTOC(olObject['table_of_contents']);
         }
-    }
-    
-    // $$$mang cleanup
-    $('#BRreturn a').attr('href', 'http://openlibrary.org' + olObject.key);
 
+        // $$$mang cleanup
+        this.bookUrl = 'http://openlibrary.org' + olObject.key;
+        $('#BRreturn a').attr('href', this.bookUrl);
+    }
 }
 
 // Library functions
@@ -4602,6 +4592,15 @@ BookReader.util = {
         return (outer.document || outer);
     },
     
+    escapeHTML: function (str) {
+        return(
+            str.replace(/&/g,'&amp;').
+                replace(/>/g,'&gt;').
+                replace(/</g,'&lt;').
+                replace(/"/g,'&quot;')
+        );
+    },
+    
     decodeURIComponentPlus: function(value) {
         // Decodes a URI component and converts '+' to ' '
         return decodeURIComponent(value).replace(/\+/g, ' ');
@@ -5145,37 +5144,39 @@ BookReader.prototype.makeAboutDiv = function()
             '<div class="BRfloatHead">About this book',
                 '<a class="floatShut" href="javascript:;" onclick="$.fn.colorbox.close();"><span class="shift">Close</span></a>',
             '</div>',
-            '<div class="BRfloatBody">',
-                '<div class="BRfloatCover">',
-                    '<a href="Open Library Book Page"><img src="Open Library Book Cover" alt="Book Title" height="140"/></a>',
-                '</div>',
+            '<div class="BRfloatBody">'
+    ];
+    
+    // Use 3rd-party provided function if available
+    if (this.getInfoDiv) {
+        html.push(this.getInfoDiv());
+    } else {
+        html = html.concat([
                 '<div class="BRfloatMeta">',
                     '<div class="BRfloatTitle">',
-                        '<h2><a href="Open Library Book Page" class="title">Book Title</a></h2>',
-                        'by',
-                        '<a href="Open Library Author Page">Book Author</a>',
+                        '<h2><a href="', br.bookUrl, '" class="title">', BookReader.util.escapeHTML(br.bookTitle), '</a></h2>',
                     '</div>',
-                    '<p>Published MONTH YEAR by <a href="Open Library Publisher Page">Publisher name</a></p>',
-                    '<p>Written in <a href="Open Library Language page">Language</a></p>',
-                    '<h3>Other Formats</h3>',
-                    '<ul class="links">',
-                        '<li><a href="PDF Link">PDF</a><span>|</span></li>',
-                        '<li><a href="Text Link">Plain Text</a><span>|</span></li>',
-                        '<li><a href="DAISY Link">DAISY</a><span>|</span></li>',
-                        '<li><a href="PDF Link">ePub</a><span>|</span></li>',
-                        '<li><a href="Kindle Link">Send to Kindle</a><span>|</span></li>',
-                        '<li><a href="archive.org Page for Book">More...</a></li>',
-                    '</ul>',
-                    '<p class="moreInfo"><span></span>More information on <a href="Open Libarary Book Page">openlibrary.org</a>.</p>',
                 '</div>',
-            '</div>',
-            '<div class="BRfloatFoot">',
-                '<a href="http://openlibrary.org/contact" class="problem">Report a problem</a>',
-                '<span>|</span>',
-                '<a href="http://openlibrary.org/dev/docs/bookreader">About the Bookreader</a>',
-            '</div>',
-        '</div>'
-    ].join('\n');
+        ]);
+    }
     
-    return html;
+    html = html.concat([
+            '</div>', // BRfloatBody
+            '<div class="BRfloatFoot">'
+    ]);
+    
+    if (this.getInfoFooter) {
+        html.push(this.getInfoFooter());
+    } else {
+        html.push(
+                '<a href="http://openlibrary.org/dev/docs/bookreader">About the BookReader</a>'
+        );
+    }
+    
+    html = html.concat([
+            '</div>', // BRfloatfoot
+        '</div>' // BRfloat
+    ]);
+    
+    return html.join('\n');
 }
index 5b2dcad..016e988 100644 (file)
@@ -358,6 +358,52 @@ br.getOpenLibraryRecord = function(callback) {
     });
 }
 
+// getInfoDiv
+br.getInfoDiv = function() {
+    // $$$ it might make more sense to have a URL on openlibrary.org that returns this info
+
+    var escapedTitle = BookReader.util.escapeHTML(this.bookTitle);
+    var domainRe = /(\w+\.(com|org))/;
+    var domain = domainRe.exec(this.bookUrl)[1];
+    // XXX use different icon for archive.org
+    var html = [
+                '<div class="BRfloatCover">',
+                    '<a href="', this.bookUrl, '"><img src="http://www.archive.org/download/', this.bookId, '/page/cover_t.jpg" alt="', escapedTitle, '" height="140"/></a>',
+                '</div>',
+                '<div class="BRfloatMeta">',
+                    '<div class="BRfloatTitle">',
+                        '<h2><a href="', this.bookUrl, '" class="title">', escapedTitle, '</a></h2>',
+                        // $$$ lookup on OL
+                        // 'by',
+                        // '<a href="Open Library Author Page">Book Author</a>',
+                    '</div>',
+                    '<p>Published ', this.bookPublished,
+                    //, <a href="Open Library Publisher Page">Publisher name</a>',
+                    '</p>',
+                    //'<p>Written in <a href="Open Library Language page">Language</a></p>',
+                    '<h3>Other Formats</h3>',
+                    '<ul class="links">',
+                        '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '.pdf">PDF</a><span>|</span></li>',
+                        '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '_djvu.txt">Plain Text</a><span>|</span></li>',
+                        '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '_daisy.zip">DAISY</a><span>|</span></li>',
+                        '<li><a href="http://www.archive.org/download/', this.bookId, '/', this.subPrefix, '.epub">ePub</a><span>|</span></li>',
+                        '<li><a href="https://www.amazon.com/gp/digital/fiona/web-to-kindle?clientid=IA&itemid=', this.bookId, '&docid=', this.subPrefix, '">Send to Kindle</a><span>|</span></li>',
+                        '<li><a href="', this.bookUrl, '">More...</a></li>',
+                    '</ul>',
+                    '<p class="moreInfo"><span></span>More information on <a href="'+ this.bookUrl + '">' + domain + '</a>.</p>',
+                '</div>',
+            '</div>',
+            '<div class="BRfloatFoot">',
+                // XXX add link to bug tracker
+                '<a href="http://openlibrary.org/contact" class="problem">Report a problem</a>',
+                '<span>|</span>',
+                '<a href="http://openlibrary.org/dev/docs/bookreader">About the Bookreader</a>',
+            '</div>'
+    ];
+    
+    return html.join('\n');
+}
+
 br.pageW =  [
             <?
             $i=0;
index d73ed4e..abc47f3 100644 (file)
@@ -397,7 +397,7 @@ class BookReaderMeta {
     
     function imageFilePath($leafNum, $subPrefix, $format) {
         $pathParts = pathinfo($subPrefix);
-        $almostIdentifier = $pathParts['filename'];
+        $almostIdentifier = $pathParts['basename'];
         return sprintf("%s_%s/%s_%04d.%s", $almostIdentifier, $format, $almostIdentifier, intval($leafNum), $format);
     }
     
index f849d67..b949dcb 100644 (file)
@@ -102,7 +102,8 @@ class BookReader
     $version = "r28";
     
     if (BookReader::getDevHost($server)) {
-        // on dev host - add time to force reload
+        // On dev host - add time to force reload
+        // If debugging on IE, remove this line otherwise breakpoints will be invalid after reload
         $version .= '_' . time();
     }
     
@@ -112,6 +113,7 @@ class BookReader
     }
     
     $metaURL = BookReader::jsMetadataURL($server, $identifier, $mainDir, $subPrefix);
+    $locateURL = BookReader::jsLocateURL($identifier, $subPrefix);
     
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
@@ -176,15 +178,13 @@ class BookReader
   brConfig["mode"] = 2;
 <? } ?>
 </script>
-<!-- The script included below is dynamically generated JavaScript that includes the book metadata and page image access functions -->
+<!-- The script included below is dynamically generated JavaScript that includes the book metadata and page image access functions.
+     The ia{number}.us.archive.org server referenced below can and does change, so this URL should NOT be used for permanent access.  -->
 <script type="text/javascript" src="<? echo($metaURL); ?>"></script>
+<!-- This URL will find the item and redirect to the correct server.  Remove the line above and use the URL below for stable access. -->
+<!-- <script type="text/javascript" src="<? echo($locateURL); ?>"></script> -->
 
 <script type="text/javascript">
-    // $$$ hack to workaround sizing bug when starting in two-up mode
-    $(document).ready(function() {
-        $(window).trigger('resize');
-    });
-    
     // Usage stats
     if(window.archive_analytics) { window.archive_analytics.values['bookreader'] = 'open'};
 </script>
@@ -241,6 +241,17 @@ class BookReader
     return $url;
   }
   
+  // This returns a URL that finds the item then returns a redirect to BookReaderJSIA.php
+  // on the item's server.
+  public static function jsLocateURL($identifier, $subPrefix = '')
+  {
+    $locateURL = 'http://www.archive.org/bookreader/BookReaderJSLocate.php?id=' . $identifier;
+    if ($subPrefix) {
+        $locateURL .= '&subPrefix=' . $subPrefix;
+    }
+    return $locateURL;
+  }
+  
   // Return the URL for the requested /download/$path, or null
   public static function getURL($path, $item) {
     // $path should look like {itemId}/{operator}/{filename}