added support for double page spreads

This commit is contained in:
Bala Clark 2010-12-26 19:15:43 +01:00
parent 115c154c87
commit 3aa2f5da84

View file

@ -62,6 +62,7 @@ function ComicBook(id, srcs, opts) {
var buffer = 1; // image preload buffer level var buffer = 1; // image preload buffer level
var loaded = []; // the images that have been loaded so far var loaded = []; // the images that have been loaded so far
var scale = 1; // page zoom scale, 1 = 100% var scale = 1; // page zoom scale, 1 = 100%
var is_double_page_spread = false;
// the current page, can pass a default as a url hash // the current page, can pass a default as a url hash
var pointer = (parseInt(location.hash.substring(1),10) - 1) || 0; var pointer = (parseInt(location.hash.substring(1),10) - 1) || 0;
@ -218,7 +219,11 @@ function ComicBook(id, srcs, opts) {
// reset the canvas to stop duplicate pages showing // reset the canvas to stop duplicate pages showing
canvas.width = 0; canvas.width = 0;
canvas.height = 0; canvas.height = 0;
// show double page spreads on a single page
is_double_page_spread = ((page.width > page.height || page2.width > page2.height) && options.displayMode === "double");
if (is_double_page_spread) { options.displayMode = "single"; }
if (options.displayMode === "double") { if (options.displayMode === "double") {
// for double page spreads, factor in the width of both pages // for double page spreads, factor in the width of both pages
@ -238,7 +243,7 @@ function ComicBook(id, srcs, opts) {
case "fitWidth": case "fitWidth":
document.body.style.overflowX = "hidden"; document.body.style.overflowX = "hidden";
zoom_scale = (window.innerWidth > width) ? ((window.innerWidth - width) / window.innerWidth) + 1 // scale up if the window is wider than the page zoom_scale = (window.innerWidth > width) ? ((window.innerWidth - width) / window.innerWidth) + 1 // scale up if the window is wider than the page
: window.innerWidth / width; // scale down if the window is narrower than the page : window.innerWidth / width; // scale down if the window is narrower than the page
break; break;
@ -290,6 +295,9 @@ function ComicBook(id, srcs, opts) {
$.each(options.enhance, function(action, options) { $.each(options.enhance, function(action, options) {
ComicBook.prototype.enhance[action](options); ComicBook.prototype.enhance[action](options);
}); });
// revert page mode back to double if it was auto switched for a double page spread
if (is_double_page_spread) { options.displayMode = "double"; }
}; };
/** /**
@ -299,7 +307,7 @@ function ComicBook(id, srcs, opts) {
*/ */
ComicBook.prototype.drawNextPage = function () { ComicBook.prototype.drawNextPage = function () {
if (pointer + 1 < pages.length) { if (pointer + 1 < pages.length) {
pointer += (options.displayMode === "single") ? 1 : 2; pointer += (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;
this.drawPage(); this.drawPage();
} }
}; };
@ -310,8 +318,11 @@ function ComicBook(id, srcs, opts) {
* @see #drawPage * @see #drawPage
*/ */
ComicBook.prototype.drawPrevPage = function () { ComicBook.prototype.drawPrevPage = function () {
is_double_page_spread = (pages[pointer-1].width > pages[pointer-1].height); // need to run double page check again here as we are going backwards
if (pointer > 0) { if (pointer > 0) {
pointer -= (options.displayMode === "single") ? 1 : 2; pointer -= (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;
this.drawPage(); this.drawPage();
} }
}; };