From 3848f6bd381d8aee703beff3df51b6d9ac8bb3e8 Mon Sep 17 00:00:00 2001 From: Michael Ang Date: Thu, 8 Apr 2010 19:04:40 +0000 Subject: [PATCH] Call switchMode from thumbnail image links. Documentation. --- BookReader/BookReader.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/BookReader/BookReader.js b/BookReader/BookReader.js index 5af1a8b..f235167 100644 --- a/BookReader/BookReader.js +++ b/BookReader/BookReader.js @@ -193,6 +193,8 @@ BookReader.prototype.init = function() { return false; }); + // $$$ refactor this so it's enough to set the first index and call preparePageView + // (get rid of mode-specific logic at this point) if (1 == this.mode) { this.resizePageView(); this.firstIndex = startIndex; @@ -285,6 +287,7 @@ BookReader.prototype.drawLeafs = function() { } else { this.drawLeafsTwoPage(); } + } // setDragHandler() @@ -588,7 +591,10 @@ BookReader.prototype.drawLeafsThumbnail = function() { var currentRow = 0; var leafIndex = 0; var leafMap = []; + + var self = this; + // Calculate the position of every thumbnail. $$$ cache instead of calculating on every draw for (i=0; i viewWidth){ @@ -608,7 +614,9 @@ BookReader.prototype.drawLeafsThumbnail = function() { leafMap[currentRow].leafs[leafIndex].left = rightPos; leafHeight = parseInt((this.getPageHeight(leafMap[currentRow].leafs[leafIndex].num)*this.thumbWidth)/this.getPageWidth(leafMap[currentRow].leafs[leafIndex].num), 10); - if (leafHeight > leafMap[currentRow].height) { leafMap[currentRow].height = leafHeight; } + if (leafHeight > leafMap[currentRow].height) { + leafMap[currentRow].height = leafHeight; + } if (leafIndex===0) { bottomPos += this.padding + leafMap[currentRow].height; } rightPos += leafWidth + this.padding; if (rightPos > maxRight) { maxRight = rightPos; } @@ -626,6 +634,7 @@ BookReader.prototype.drawLeafsThumbnail = function() { var leafBottom = 0; var rowsToDisplay = []; + // Determine the thumbnails in view for (i=0; i= scrollTop) && (leafTop <= scrollBottom); @@ -655,6 +664,7 @@ BookReader.prototype.drawLeafsThumbnail = function() { this.updateLocationHash(); } + // Create the thumbnail divs and images (lazy loaded) var j; var row; var left; @@ -692,11 +702,18 @@ 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).data('leaf', leaf); + $(link).bind('click', function(event) { + self.firstIndex = $(this).data('leaf'); + self.switchMode(self.constMode1up); + event.preventDefault(); + }); + + // $$$ we don't actually go to this URL (click is handled in handler above) link.href = '#page/' + (this.getPageNum(leaf)) +'/mode/1up' ; $(div).append(link); - + $('#BRpageview').append(div); img = document.createElement("img"); @@ -719,6 +736,7 @@ BookReader.prototype.drawLeafsThumbnail = function() { // highlight current page $('#pagediv'+this.currentIndex()).addClass('BRpagedivthumb_highlight'); + // Remove thumbnails that are not to be displayed var k; for (i=0; i