Remove stray tabs in source files. Should have no functionality change. See https...
[bookreader.git] / BookReader / BookReader.js
index c5a6f97..2b6d701 100644 (file)
@@ -41,7 +41,7 @@ function BookReader() {
     this.mode    = 1; //1 or 2
     this.ui = 'full'; // UI mode
     
-    this.displayedIndices = [];        
+    this.displayedIndices = [];
     //this.indicesToDisplay = [];
     this.imgs = {};
     this.prefetchedImgs = {}; //an object with numeric keys cooresponding to page index
@@ -1451,10 +1451,10 @@ BookReader.prototype.currentIndex = function() {
 BookReader.prototype.right = function() {
     if ('rl' != this.pageProgression) {
         // LTR
-        br.next();
+        this.next();
     } else {
         // RTL
-        br.prev();
+        this.prev();
     }
 }
 
@@ -1463,9 +1463,9 @@ BookReader.prototype.right = function() {
 // Flip to the rightmost page
 BookReader.prototype.rightmost = function() {
     if ('rl' != this.pageProgression) {
-        br.last();
+        this.last();
     } else {
-        br.first();
+        this.first();
     }
 }
 
@@ -1475,10 +1475,10 @@ BookReader.prototype.rightmost = function() {
 BookReader.prototype.left = function() {
     if ('rl' != this.pageProgression) {
         // LTR
-        br.prev();
+        this.prev();
     } else {
         // RTL
-        br.next();
+        this.next();
     }
 }
 
@@ -1487,9 +1487,9 @@ BookReader.prototype.left = function() {
 // Flip to the leftmost page
 BookReader.prototype.leftmost = function() {
     if ('rl' != this.pageProgression) {
-        br.first();
+        this.first();
     } else {
-        br.last();
+        this.last();
     }
 }
 
@@ -2121,13 +2121,13 @@ BookReader.prototype.search = function(term) {
     term = term.replace(/\//g, ' '); // strip slashes
     this.searchTerm = term;
     $('#BookReaderSearchScript').remove();
-       var script  = document.createElement("script");
-       script.setAttribute('id', 'BookReaderSearchScript');
-       script.setAttribute("type", "text/javascript");
-       script.setAttribute("src", 'http://'+this.server+'/BookReader/flipbook_search_br.php?url='+escape(this.bookPath + '_djvu.xml')+'&term='+term+'&format=XML&callback=br.BRSearchCallback');
-       document.getElementsByTagName('head')[0].appendChild(script);
-       $('#BookReaderSearchBox').val(term);
-       $('#BookReaderSearchResults').html('Searching...');
+    var script  = document.createElement("script");
+    script.setAttribute('id', 'BookReaderSearchScript');
+    script.setAttribute("type", "text/javascript");
+    script.setAttribute("src", 'http://'+this.server+'/BookReader/flipbook_search_br.php?url='+escape(this.bookPath + '_djvu.xml')+'&term='+term+'&format=XML&callback=br.BRSearchCallback');
+    document.getElementsByTagName('head')[0].appendChild(script);
+    $('#BookReaderSearchBox').val(term);
+    $('#BookReaderSearchResults').html('Searching...');
 }
 
 // BRSearchCallback()
@@ -2199,7 +2199,7 @@ BookReader.prototype.BRSearchCallback = function(txt) {
     $('#BookReaderSearchResults').append('</ul>');
 
     // $$$ update again for case of loading search URL in new browser window (search box may not have been ready yet)
-       $('#BookReaderSearchBox').val(this.searchTerm);
+    $('#BookReaderSearchBox').val(this.searchTerm);
 
     this.updateSearchHilites();
 }
@@ -2853,63 +2853,65 @@ BookReader.prototype.switchToolbarMode = function(mode) {
 // Binds the toolbar handlers
 BookReader.prototype.bindToolbarNavHandlers = function(jToolbar) {
 
+    var self = this; // closure
+
     jToolbar.find('.book_left').bind('click', function(e) {
-        br.left();
+        self.left();
         return false;
     });
          
     jToolbar.find('.book_right').bind('click', function(e) {
-        br.right();
+        self.right();
         return false;
     });
         
     jToolbar.find('.book_up').bind('click', function(e) {
-        br.prev();
+        self.prev();
         return false;
     });        
         
     jToolbar.find('.book_down').bind('click', function(e) {
-        br.next();
+        self.next();
         return false;
     });
 
     jToolbar.find('.print').bind('click', function(e) {
-        br.printPage();
+        self.printPage();
         return false;
     });
         
     jToolbar.find('.embed').bind('click', function(e) {
-        br.showEmbedCode();
+        self.showEmbedCode();
         return false;
     });
 
     jToolbar.find('.play').bind('click', function(e) {
-        br.autoToggle();
+        self.autoToggle();
         return false;
     });
 
     jToolbar.find('.pause').bind('click', function(e) {
-        br.autoToggle();
+        self.autoToggle();
         return false;
     });
     
     jToolbar.find('.book_top').bind('click', function(e) {
-        br.first();
+        self.first();
         return false;
     });
 
     jToolbar.find('.book_bottom').bind('click', function(e) {
-        br.last();
+        self.last();
         return false;
     });
     
     jToolbar.find('.book_leftmost').bind('click', function(e) {
-        br.leftmost();
+        self.leftmost();
         return false;
     });
   
     jToolbar.find('.book_rightmost').bind('click', function(e) {
-        br.rightmost();
+        self.rightmost();
         return false;
     });
 }
@@ -3327,6 +3329,27 @@ BookReader.prototype._getPageURI = function(index, reduce, rotate) {
         return this.imagesBaseURL + "/transparent.png";
     }
     
+    if ('undefined' == typeof(reduce)) {
+        // reduce not passed in
+        var ratio = this.getPageHeight(index) / this.twoPage.height;
+        var scale;
+        // $$$ we make an assumption here that the scales are available pow2 (like kakadu)
+        if (ratio < 2) {
+            scale = 1;
+        } else if (ratio < 4) {
+            scale = 2;
+        } else if (ratio < 8) {
+            scale = 4;
+        } else if (ratio < 16) {
+            scale = 8;
+        } else  if (ratio < 32) {
+            scale = 16;
+        } else {
+            scale = 32;
+        }
+        reduce = scale;
+    }
+    
     return this.getPageURI(index, reduce, rotate);
 }