this.flipFwdToIndex(index);
}
- } else {
+ } else if (3 == this.mode){
+ var viewWidth = $('#GBcontainer').attr('scrollWidth') - 20; // width minus buffer
+ var i;
+ var leafWidth = 0;
+ var leafHeight = 0;
+ var rightPos = 0;
+ var bottomPos = 0;
+ var rowHeight = 0;
+ var leafTop = 0;
+ var leafIndex = 0;
+
+ for (i=0; i<(index+1); i++) {
+ leafWidth = parseInt(this.getPageWidth(i)/this.reduce, 10);
+ if (rightPos + (leafWidth + this.padding) > viewWidth){
+ rightPos = 0;
+ rowHeight = 0;
+ leafIndex = 0;
+ }
+ leafHeight = parseInt(this.getPageHeight(i)/this.reduce, 10);
+ if(leafHeight > rowHeight) { rowHeight = leafHeight; }
+ if (leafIndex==0) { leafTop = bottomPos; }
+ if (leafIndex==0) { bottomPos += this.padding + rowHeight; }
+ rightPos += leafWidth + this.padding;
+ leafIndex++;
+ }
+ this.firstIndex=index;
+ if ($('#GBcontainer').attr('scrollTop') == leafTop) {
+ this.loadLeafs();
+ } else {
+ $('#GBcontainer').animate({scrollTop: leafTop },'fast');
+ }
+ } else {
var i;
var leafTop = 0;
+ var leafLeft = 0;
var h;
for (i=0; i<index; i++) {
- h = parseInt(this.getPageHeight(i)/this.reduce);
+ h = parseInt(this._getPageHeight(i)/this.reduce);
leafTop += h + this.padding;
}
+
+ if (pageY) {
+ //console.log('pageY ' + pageY);
+ var offset = parseInt( (pageY) / this.reduce);
+ offset -= $('#GBcontainer').attr('clientHeight') >> 1;
+ //console.log( 'jumping to ' + leafTop + ' ' + offset);
+ leafTop += offset;
+ }
+
+ if (pageX) {
+ var offset = parseInt( (pageX) / this.reduce);
+ offset -= $('#GBcontainer').attr('clientWidth') >> 1;
+ leafLeft += offset;
+ }
+
//$('#GBcontainer').attr('scrollTop', leafTop);
- $('#GBcontainer').animate({scrollTop: leafTop },'fast');
+ $('#GBcontainer').animate({scrollTop: leafTop, scrollLeft: leafLeft },'fast');
}
}
// 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 || this.mode == this.constModeThumb) {
- return this.firstIndex;
- if (this.mode == this.constMode1up) {
++ if (this.mode == this.constMode1up || this.mode == this.constModeThumb) {
+ return this.firstIndex; // $$$ TODO page in center of view would be better
+ } else if (this.mode == this.constMode2up) {
+ // Only allow indices that are actually present in book
+ return GnuBook.util.clamp(this.firstIndex, 0, this.numLeafs - 1);
} else {
throw 'currentIndex called for unimplemented mode ' + this.mode;
}
GnuBook.prototype.initToolbar = function(mode, ui) {
- $("#GnuBook").append("<div id='GBtoolbar'><span style='float:left;'>"
- + "<a class='GBicon logo rollover' href='" + this.logoURL + "'> </a>"
- + " <button class='GBicon rollover zoom_out' onclick='gb.zoom(-1); return false;'/>"
- + "<button class='GBicon rollover zoom_in' onclick='gb.zoom(1); return false;'/>"
- + " <span class='label'>Zoom: <span id='GBzoom'>"+parseInt(100/this.reduce)+"</span></span>"
- + " <button class='GBicon rollover one_page_mode' onclick='gb.switchMode(1); return false;'/>"
- + " <button class='GBicon rollover two_page_mode' onclick='gb.switchMode(2); return false;'/>"
- + " <button class='GBicon rollover thumbnail_mode' onclick='gb.switchMode(3); return false;'/>"
- + " <a class='GBblack title' href='"+this.bookUrl+"' target='_blank'>"+this.shortTitle(50)+"</a>"
- + "</span></div>");
+ $("#GnuBook").append("<div id='GBtoolbar'>"
+ + "<span id='GBtoolbarbuttons' style='float: right'>"
+ + "<button class='GBicon print rollover' /> <button class='GBicon rollover embed' />"
+ + "<form class='GBpageform' action='javascript:' onsubmit='gb.jumpToPage(this.elements[0].value)'> <span class='label'>Page:<input id='GBpagenum' type='text' size='3' onfocus='gb.autoStop();'></input></span></form>"
+ + "<div class='GBtoolbarmode2' style='display: none'><button class='GBicon rollover book_leftmost' /><button class='GBicon rollover book_left' /><button class='GBicon rollover book_right' /><button class='GBicon rollover book_rightmost' /></div>"
+ + "<div class='GBtoolbarmode1' style='display: none'><button class='GBicon rollover book_top' /><button class='GBicon rollover book_up' /> <button class='GBicon rollover book_down' /><button class='GBicon rollover book_bottom' /></div>"
++ + "<button class='GBicon rollover thumbnail_mode' onclick='gb.switchMode(3); return false;'/>"
+ + "<button class='GBicon rollover play' /><button class='GBicon rollover pause' style='display: none' />"
+ + "</span>"
+
+ + "<span>"
+ + "<a class='GBicon logo rollover' href='" + this.logoURL + "'> </a>"
+ + " <button class='GBicon rollover zoom_out' onclick='gb.zoom(-1); return false;'/>"
+ + "<button class='GBicon rollover zoom_in' onclick='gb.zoom(1); return false;'/>"
+ + " <span class='label'>Zoom: <span id='GBzoom'>"+parseInt(100/this.reduce)+"</span></span>"
+ + " <button class='GBicon rollover one_page_mode' onclick='gb.switchMode(1); return false;'/>"
+ + " <button class='GBicon rollover two_page_mode' onclick='gb.switchMode(2); return false;'/>"
+ + "</span>"
+
+ + "<span id='#GBbooktitle'>"
+ + " <a class='GBblack title' href='"+this.bookUrl+"' target='_blank'>"+this.bookTitle+"</a>"
+ + "</span>"
+ + "</div>");
this.updateToolbarZoom(this.reduce); // Pretty format
'.zoom_out': 'Zoom out',
'.one_page_mode': 'One-page view',
'.two_page_mode': 'Two-page view',
+ '.thumbnail_mode': 'Thumbnail view',
+ '.print': 'Print this page',
'.embed': 'Embed bookreader',
'.book_left': 'Flip left',
'.book_right': 'Flip right',