Make up/down buttons smoothly scroll one vertical view in 1up and thumbnail modes.
[bookreader.git] / BookReader / BookReader.js
index e581dda..83535bf 100644 (file)
@@ -613,7 +613,7 @@ BookReader.prototype.drawLeafsThumbnail = function() {
     // reset the bottom position based on thumbnails
     $('#BRpageview').height(bottomPos);
 
-    var pageViewBuffer = Math.floor(($('#BRcontainer').attr('scrollWidth') - maxRight) / 2) - 14;      
+    var pageViewBuffer = Math.floor(($('#BRcontainer').attr('scrollWidth') - maxRight) / 2) - 14;
     var scrollTop = $('#BRcontainer').attr('scrollTop');
     var scrollBottom = scrollTop + $('#BRcontainer').height();
 
@@ -677,7 +677,7 @@ BookReader.prototype.drawLeafsThumbnail = function() {
                 div = document.createElement("div");
                 div.id = 'pagediv'+leaf;
                 div.style.position = "absolute";
-                div.className = "BRpagedivthumb";                              
+                div.className = "BRpagedivthumb";
 
                 left += this.padding;
                 $(div).css('top', leafTop + 'px');
@@ -687,6 +687,7 @@ BookReader.prototype.drawLeafsThumbnail = function() {
                 //$(div).text('loading...');
 
                 // link to page in single page mode
+                // $$$ direct JS calls instead should reduce visual disruption
                 link = document.createElement("a");
                 link.href = '#page/' + (this.getPageNum(leaf)) +'/mode/1up' ;
                 $(div).append(link);
@@ -694,7 +695,8 @@ BookReader.prototype.drawLeafsThumbnail = function() {
                 $('#BRpageview').append(div);
 
                 img = document.createElement("img");
-                img.src = this.getPageURI(leaf);
+                var thumbReduce = Math.floor(this.getPageWidth(leaf) / this.thumbWidth);
+                img.src = this._getPageURI(leaf, thumbReduce);
                 $(img).css('width', leafWidth+'px');
                 $(img).css('height', leafHeight+'px');
                 img.style.border = "0";
@@ -1100,7 +1102,7 @@ BookReader.prototype.jumpToIndex = function(index, pageX, pageY) {
             this.flipFwdToIndex(index);
         }
 
-    } else if (3 == this.mode){        
+    } else if (3 == this.mode) {
         var viewWidth = $('#BRcontainer').attr('scrollWidth') - 20; // width minus buffer
         var i;
         var leafWidth = 0;
@@ -1252,7 +1254,7 @@ BookReader.prototype.prepareThumbnailView = function() {
     
     this.resizePageView();
     
-       this.displayedRows = [];
+    this.displayedRows = [];
     this.drawLeafsThumbnail();
         
     // Bind mouse handlers
@@ -1787,6 +1789,37 @@ BookReader.prototype.last = function() {
     this.jumpToIndex(this.lastDisplayableIndex());
 }
 
+// scrollDown()
+//______________________________________________________________________________
+// Scrolls down one screen view
+BookReader.prototype.scrollDown = function() {
+    if ($.inArray(this.mode, [this.constMode2up, this.constModeThumb])) {
+        $('#BRcontainer').animate(
+            { scrollTop: '+=' + $('#BRcontainer').height() * 0.95 + 'px'},
+            450, 'easeInOutQuint'
+        );
+        return true;
+    } else {
+        return false;
+    }
+}
+
+// scrollUp()
+//______________________________________________________________________________
+// Scrolls up one screen view
+BookReader.prototype.scrollUp = function() {
+    if ($.inArray(this.mode, [this.constMode2up, this.constModeThumb])) {
+        $('#BRcontainer').animate(
+            { scrollTop: '-=' + $('#BRcontainer').height() * 0.95 + 'px'},
+            450, 'easeInOutQuint'
+        );
+        return true;
+    } else {
+        return false;
+    }
+}
+
+
 // flipBackToIndex()
 //______________________________________________________________________________
 // to flip back one spread, pass index=null
@@ -2423,7 +2456,7 @@ BookReader.prototype.BRSearchCallback = function(txt) {
             //console.log(pages[i].getAttribute('file').substr(1) +'-'+ parseInt(pages[i].getAttribute('file').substr(1), 10));
     
             
-            var re = new RegExp (/_(\d{4})/);
+            var re = new RegExp (/_(\d{4})\.djvu/);
             var reMatch = re.exec(pages[i].getAttribute('file'));
             var index = parseInt(reMatch[1], 10);
             //var index = parseInt(pages[i].getAttribute('file').substr(1), 10);
@@ -3020,6 +3053,7 @@ BookReader.prototype.initToolbar = function(mode, ui) {
         +   "<form class='BRpageform' action='javascript:' onsubmit='br.jumpToPage(this.elements[0].value)'> <span class='label'>Page:<input id='BRpagenum' type='text' size='3' onfocus='br.autoStop();'></input></span></form>"
         +   "<div class='BRtoolbarmode2' style='display: none'><button class='BRicon rollover book_leftmost' /><button class='BRicon rollover book_left' /><button class='BRicon rollover book_right' /><button class='BRicon rollover book_rightmost' /></div>"
         +   "<div class='BRtoolbarmode1' style='display: none'><button class='BRicon rollover book_top' /><button class='BRicon rollover book_up' /> <button class='BRicon rollover book_down' /><button class='BRicon rollover book_bottom' /></div>"
+        +   "<div class='BRtoolbarmode3' style='display: none'><button class='BRicon rollover book_top' /><button class='BRicon rollover book_up' /> <button class='BRicon rollover book_down' /><button class='BRicon rollover book_bottom' /></div>"
         +   "<button class='BRicon rollover play' /><button class='BRicon rollover pause' style='display: none' />"
         + "</span>"
         
@@ -3138,12 +3172,20 @@ BookReader.prototype.bindToolbarNavHandlers = function(jToolbar) {
     });
         
     jToolbar.find('.book_up').bind('click', function(e) {
-        self.prev();
+        if ($.inArray(self.mode, [self.constMode2up, self.constModeThumb])) {
+            self.scrollUp();
+        } else {
+            self.prev();
+        }
         return false;
     });        
         
     jToolbar.find('.book_down').bind('click', function(e) {
-        self.next();
+        if ($.inArray(self.mode, [self.constMode2up, self.constModeThumb])) {
+            self.scrollDown();
+        } else {
+            self.next();
+        }
         return false;
     });
 
@@ -3607,6 +3649,7 @@ BookReader.prototype._getPageURI = function(index, reduce, rotate) {
     
     if ('undefined' == typeof(reduce)) {
         // reduce not passed in
+        // $$$ this probably won't work for thumbnail mode
         var ratio = this.getPageHeight(index) / this.twoPage.height;
         var scale;
         // $$$ we make an assumption here that the scales are available pow2 (like kakadu)