From: scollett Date: Mon, 12 Oct 2009 18:13:16 +0000 (-0700) Subject: Added basic thumbnail view (single row) based one page view X-Git-Url: http://git.rot13.org/?p=bookreader.git;a=commitdiff_plain;h=e5e40720823fa718584839b7351d560ae57ee5ea Added basic thumbnail view (single row) based one page view --- diff --git a/GnuBook/GnuBook.js b/GnuBook/GnuBook.js index 761eee8..3d48ce9 100644 --- a/GnuBook/GnuBook.js +++ b/GnuBook/GnuBook.js @@ -66,6 +66,7 @@ function GnuBook() { // Mode constants this.constMode1up = 1; this.constMode2up = 2; + this.constModeThumb = 3; // Zoom levels this.reductionFactors = [0.5, 1, 2, 4, 8, 16]; @@ -138,6 +139,8 @@ GnuBook.prototype.init = function() { e.data.displayedIndices = []; e.data.updateSearchHilites(); //deletes hilights but does not call remove() e.data.loadLeafs(); + } else if (3 == e.data.mode){ + e.data.prepareThumbnailView; } else { //console.log('drawing 2 page view'); @@ -172,7 +175,11 @@ GnuBook.prototype.init = function() { this.resizePageView(); this.firstIndex = startIndex; this.jumpToIndex(startIndex); - } else { + } else if (3 == this.mode) { + this.firstIndex = startIndex; + this.jumpToIndex(startIndex); + this.prepareThumbnailView(); + } else { //this.resizePageView(); this.displayedIndices=[0]; @@ -256,6 +263,8 @@ GnuBook.prototype.setupKeyListeners = function() { GnuBook.prototype.drawLeafs = function() { if (1 == this.mode) { this.drawLeafsOnePage(); + } else if(3 == this.mode) { + this.drawLeafsThumbnail(); } else { this.drawLeafsTwoPage(); } @@ -543,6 +552,139 @@ GnuBook.prototype.drawLeafsOnePage = function() { } +// drawLeafsThumbnail() +//______________________________________________________________________________ +GnuBook.prototype.drawLeafsThumbnail = function() { + //alert('drawing leafs!'); + this.timer = null; + + + var scrollTop = $('#GBcontainer').attr('scrollTop'); + var scrollBottom = scrollTop + $('#GBcontainer').height(); + //console.log('top=' + scrollTop + ' bottom='+scrollBottom); + + var indicesToDisplay = []; + + var i; + var leafTop = 0; + var leafBottom = 0; + var viewHeight = 0; + var width = 0; + for (i=0; i=scrollTop=' + (leafTop>=scrollTop)); + var topInView = (leafTop >= scrollTop) && (leafTop <= scrollBottom); + var bottomInView = (leafBottom >= scrollTop) && (leafBottom <= scrollBottom); + var middleInView = (leafTop <=scrollTop) && (leafBottom>=scrollBottom); + if (topInView | bottomInView | middleInView) { + //console.log('displayed: ' + this.displayedIndices); + //console.log('to display: ' + i); + indicesToDisplay.push(i); + } + leafTop += height +10; + leafBottom += 10; + } + + var firstIndexToDraw = indicesToDisplay[0]; + this.firstIndex = firstIndexToDraw; + + // Update hash, but only if we're currently displaying a leaf + // Hack that fixes #365790 + if (this.displayedIndices.length > 0) { + this.updateLocationHash(); + } + + if ((0 != firstIndexToDraw) && (1 < this.reduce)) { + firstIndexToDraw--; + indicesToDisplay.unshift(firstIndexToDraw); + } + + var lastIndexToDraw = indicesToDisplay[indicesToDisplay.length-1]; + if ( ((this.numLeafs-1) != lastIndexToDraw) && (1 < this.reduce) ) { + indicesToDisplay.push(lastIndexToDraw+1); + } + + leafTop = 0; + var i; + for (i=0; i>1; + if (left<0) left = 0; + $(div).css('left', left+'px'); + $(div).css('width', width+'px'); + $(div).css('height', height+'px'); + //$(div).text('loading...'); + + // thumbnails are hyperlinked, do not need drag handler + //this.setDragHandler(div); + + // link to page in single page mode + var link = document.createElement("a"); + link.href = '#page/' + (this.getPageNum(index)) +'/mode/1up' ; + $(div).append(link); + + $('#GBpageview').append(div); + + var img = document.createElement("img"); + img.src = this.getPageURI(index); + $(img).css('width', width+'px'); + $(img).css('height', height+'px'); + img.style.border = "0"; + $(link).append(img); + + + } else { + //console.log("not displaying " + indicesToDisplay[i] + ' score=' + jQuery.inArray(indicesToDisplay[i], this.displayedIndices)); + } + + leafTop += height +10; + + } + + for (i=0; i"); + + this.resizePageView(); + + this.jumpToIndex(startLeaf); + this.displayedIndices = []; + + this.drawLeafsThumbnail(); + + // Bind mouse handlers + // Disable mouse click to avoid selected/highlighted page images - bug 354239 + gbPageView.bind('mousedown', function(e) { + // $$$ check here for right-click and don't disable. Also use jQuery style + // for stopping propagation. See https://bugs.edge.launchpad.net/gnubook/+bug/362626 + return false; + }) + // Special hack for IE7 + gbPageView[0].onselectstart = function(e) { return false; }; +} + // prepareTwoPageView() //______________________________________________________________________________ // Some decisions about two page view: @@ -1401,7 +1590,7 @@ GnuBook.prototype.twoPageSetCursor = function() { // Returns the currently active index. GnuBook.prototype.currentIndex = function() { // $$$ we should be cleaner with our idea of which index is active in 1up/2up - if (this.mode == this.constMode1up || this.mode == this.constMode2up) { + if (this.mode == this.constMode1up || this.mode == this.constMode2up || this.mode == this.constModeThumb) { return this.firstIndex; } else { throw 'currentIndex called for unimplemented mode ' + this.mode; @@ -2867,6 +3056,8 @@ GnuBook.prototype.paramsFromFragment = function(urlFragment) { params.mode = this.constMode1up; } else if ('2up' == urlHash['mode']) { params.mode = this.constMode2up; + } else if ('Thumb' == urlHash['mode']) { + params.mode = this.constModeThumb; } // Index and page @@ -2930,6 +3121,8 @@ GnuBook.prototype.fragmentFromParams = function(params) { fragments.push('mode', '1up'); } else if (params.mode == this.constMode2up) { fragments.push('mode', '2up'); + } else if (params.mode == this.constModeThumb) { + fragments.push('mode', 'thumb'); } else { throw 'fragmentFromParams called with unknown mode ' + params.mode; }