Suggest user refresh the BookReader if we lost the network connection.
[bookreader.git] / BookReader / BookReader.js
index c788ec1..26aebbe 100644 (file)
@@ -240,6 +240,21 @@ BookReader.prototype.init = function() {
         }
     });
     
+    if (this.protected) {
+        $('.BRpagediv1up').live('contextmenu dragstart', this, function(e) {
+            return false;
+        });
+        
+        $('.BRpageimage').live('contextmenu dragstart', this, function(e) {
+            return false;
+        });
+
+        $('.BRpagedivthumb').live('contextmenu dragstart', this, function(e) {
+            return false;
+        });
+        
+    }
+    
     $('.BRpagediv1up').bind('mousedown', this, function(e) {
         // $$$ the purpose of this is to disable selection of the image (makes it turn blue)
         //     but this also interferes with right-click.  See https://bugs.edge.launchpad.net/gnubook/+bug/362626
@@ -2393,8 +2408,11 @@ BookReader.prototype.setMouseHandlers2UP = function() {
     this.setClickHandler2UP( this.prefetchedImgs[this.twoPage.currentIndexL],
         { self: this },
         function(e) {
-            if (e.button == 2) {
+            if (e.which == 3) {
                 // right click
+                if (e.data.self.protected) {
+                    return false;
+                }
                 return true;
             }
                         
@@ -2409,8 +2427,11 @@ BookReader.prototype.setMouseHandlers2UP = function() {
     this.setClickHandler2UP( this.prefetchedImgs[this.twoPage.currentIndexR],
         { self: this },
         function(e) {
-            if (e.button == 2) {
+            if (e.which == 3) {
                 // right click
+                if (e.data.self.protected) {
+                    return false;
+                }
                 return true;
             }
             
@@ -2694,7 +2715,7 @@ BookReader.prototype.BRSearchCallback = function(results) {
         var errStr  = 'No matches were found.';
         var timeout = 1000;
         if (false === results.indexed) {
-            errStr  = "<p>This book isn't in the search engine yet.</p><p>Please <a href='http://openlibrary.org/contact?path=archive.org/stream/"+this.bookId+"/search'>drop us a line</a> so we can fix it. Thanks!</p>";
+            errStr  = "<p>This book hasn't been indexed for searching yet. We've just started indexing it, so search should be available soon. Please try again later. Thanks!</p>";
             timeout = 5000;
         }
         $(br.popup).html(errStr);
@@ -3573,7 +3594,7 @@ BookReader.prototype.initToolbar = function(mode, ui) {
         //+     "<button class='BRicon full'></button>"
         +   "</span>"
         +   "<span><a class='logo' href='" + this.logoURL + "'></a></span>"
-        +   "<span id='BRreturn'><span>Back to</span><a href='" + this.bookUrl + "'>" + this.bookTitle + "</a></span>" // XXX escape
+        +   "<span id='BRreturn'><a></a></span>"
         +   "<div id='BRnavCntlTop' class='BRnabrbuvCntl'></div>"
         + "</div>"
         /*
@@ -3590,6 +3611,14 @@ BookReader.prototype.initToolbar = function(mode, ui) {
         */
         );
 
+    // Browser hack - bug with colorbox on iOS 3 see https://bugs.launchpad.net/bookreader/+bug/686220
+    if ( navigator.userAgent.match(/ipad/i) && $.browser.webkit && (parseInt($.browser.version, 10) <= 531) ) {
+       $('#BRtoolbarbuttons .info').hide();
+       $('#BRtoolbarbuttons .share').hide();
+    }
+
+    $('#BRreturn a').attr('href', this.bookUrl).text(this.bookTitle);
+
     $('#BRtoolbar .BRnavCntl').addClass('BRup');
     $('#BRtoolbar .pause').hide();    
     
@@ -3900,14 +3929,6 @@ BookReader.prototype.bindNavigationHandlers = function() {
     $('.BRpageimage').die('mousedown.swipe').live('mousedown.swipe',
         { 'br': this },
         this.swipeMousedownHandler
-    )
-    .die('mousemove.swipe').live('mousemove.swipe',
-        { 'br': this },
-        this.swipeMousemoveHandler
-    )
-    .die('mouseup.swipe').live('mouseup.swipe',
-        { 'br': this },
-        this.swipeMouseupHandler
     );
     
     this.bindMozTouchHandlers();
@@ -3960,17 +3981,37 @@ BookReader.prototype.initSwipeData = function(clientX, clientY) {
 BookReader.prototype.swipeMousedownHandler = function(event) {
     //console.log('swipe mousedown');
     //console.log(event);
-    
+
     var self = event.data['br'];
+
+    // We should be the last bubble point for the page images
+    // Disable image drag and select, but keep right-click
+    if (event.which == 3) {
+        if (self.protected) {
+            return false;
+        }
+        return true;
+    }
+    
+    $(event.target).bind('mouseout.swipe',
+        { 'br': self},
+        self.swipeMouseupHandler
+    ).bind('mouseup.swipe',
+        { 'br': self},
+        self.swipeMouseupHandler
+    ).bind('mousemove.swipe',
+        { 'br': self },
+        self.swipeMousemoveHandler
+    );    
+    
     self.initSwipeData(event.clientX, event.clientY);
     self._swipe.mightBeSwiping = true;
     self._swipe.mightBeDragging = true;
     
-    // We should be the last bubble point for the page images
-    // Disable image drag and select, but keep right-click
-    if ($(event.originalTarget).hasClass('BRpageimage') && event.button != 2) {
-        event.preventDefault();
-    }
+    event.preventDefault();
+    event.returnValue  = false;  
+    event.cancelBubble = true;          
+    return false;
 }
 
 BookReader.prototype.swipeMousemoveHandler = function(event) {
@@ -4019,19 +4060,29 @@ BookReader.prototype.swipeMousemoveHandler = function(event) {
     }
     _swipe.lastX = event.clientX;
     _swipe.lastY = event.clientY;
+    
+    event.preventDefault();
+    event.returnValue  = false;
+    event.cancelBubble = true;         
+    return false;
 }
 BookReader.prototype.swipeMouseupHandler = function(event) {
     var _swipe = event.data['br']._swipe;
     //console.log('swipe mouseup - did swipe ' + _swipe.didSwipe);
     _swipe.mightBeSwiping = false;
     _swipe.mightBeDragging = false;
+
+    $(event.target).unbind('mouseout.swipe').unbind('mouseup.swipe').unbind('mousemove.swipe');
+    
     if (_swipe.didSwipe || _swipe.didDrag) {
         // Swallow event if completed swipe gesture
         event.preventDefault();
-        event.stopPropagation();
+        event.returnValue  = false;
+        event.cancelBubble = true;         
+        return false;
     }
+    return true;
 }
-
 BookReader.prototype.bindMozTouchHandlers = function() {
     var self = this;
     
@@ -4547,7 +4598,7 @@ BookReader.prototype.gotOpenLibraryRecord = function(self, olObject) {
         }
 
         // $$$mang cleanup
-        self.bookUrl = 'http://openlibrary.org' + olObject.key;
+        self.bookUrl = self.olHost + olObject.key;
         self.bookTitle = olObject['title'];
         $('#BRreturn a').attr( {'href': self.bookUrl, 'title': "Go to this book's page on Open Library" } );
         $('#BRreturn a').text(self.bookTitle);
@@ -4555,6 +4606,36 @@ BookReader.prototype.gotOpenLibraryRecord = function(self, olObject) {
         $('#BRinfo').remove();
         $('#BRshare').after(self.blankInfoDiv());
         self.buildInfoDiv($('#BRinfo'));
+        
+        // Check for borrowed book
+        if (self.olAuth) {
+            var returnUrl = self.olHost + olObject.key + '/do_return/borrow';
+            var borrowUrl = self.olHost + olObject.key + '/borrow';
+            
+            /*
+            $('<a/>')
+                .attr('href', borrowUrl)
+                .text('Return this book')
+                .click(function(event) {
+                    event.preventDefault();
+                    $('#BRreturnform').trigger('submit');
+                })
+                .appendTo('#BRreturn');
+            */
+            
+            $('<form id="BRreturnform" action="' + returnUrl + '" method="post"><input type="submit" value="Return book" onclick="olAuth.deleteCookies();"/><input type="hidden" name="action" value="return" /></form>')
+                .appendTo('#BRreturn');
+
+        } else {
+            $('<a/>').attr( { 'href': self.bookUrl, 'title': 'Go to this book\'s page on Open Library' } )
+                .text('On openlibrary.org')
+                .appendTo('#BRreturn');
+        }
+        
+        $('#BRreturn').css({ 'line-height': '19px'} );
+        $('#BRreturn a').css( {'height': '18px' } );
+
+        
     }
 }