Merge branch 'newui' of git@github.com:openlibrary/bookreader into newui
authorrajbot <raj@archive.org>
Wed, 10 Nov 2010 20:49:03 +0000 (20:49 +0000)
committerrajbot <raj@archive.org>
Wed, 10 Nov 2010 20:49:03 +0000 (20:49 +0000)
BookReader/BookReader.js
BookReaderIA/datanode/BookReaderJSIA.php
BookReaderIA/inc/BookReader.inc

index 9911930..f2cc8a8 100644 (file)
@@ -212,6 +212,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 +266,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 +282,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 +1578,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 +1673,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 +1745,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 +1753,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 +3734,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 +4555,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 +4601,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 +5153,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 f849d67..94f6773 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();
     }
     
@@ -177,14 +178,7 @@ class BookReader
 <? } ?>
 </script>
 <!-- The script included below is dynamically generated JavaScript that includes the book metadata and page image access functions -->
-<script type="text/javascript" src="<? echo($metaURL); ?>"></script>
-
-<script type="text/javascript">
-    // $$$ hack to workaround sizing bug when starting in two-up mode
-    $(document).ready(function() {
-        $(window).trigger('resize');
-    });
-    
+<script type="text/javascript" src="<? echo($metaURL); ?>"></script>    
     // Usage stats
     if(window.archive_analytics) { window.archive_analytics.values['bookreader'] = 'open'};
 </script>