added getter for the pages array

This commit is contained in:
Bala Clark 2011-08-28 19:49:24 +02:00
parent 3759157f6b
commit 683d804127

View file

@ -117,7 +117,7 @@ function ComicBook(id, srcs, opts) {
/** /**
* Tell the library app where the user is up to * Tell the library app where the user is up to
**/ */
function setLastPage(pageNo) { function setLastPage(pageNo) {
if (!options.data.comicId) { throw 'options.data.comicId is not set.'; } if (!options.data.comicId) { throw 'options.data.comicId is not set.'; }
$.post('/comic/setlastpage', { page: pageNo, comic: options.data.comicId }); $.post('/comic/setlastpage', { page: pageNo, comic: options.data.comicId });
@ -141,7 +141,21 @@ function ComicBook(id, srcs, opts) {
//setInterval(function() { checkHash(); }, 300); // TODO: enable this when there is no onhashchange event //setInterval(function() { checkHash(); }, 300); // TODO: enable this when there is no onhashchange event
} }
/* /**
* Get the image for a given page.
*
* @return Image
*/
ComicBook.prototype.getPage = function(i) {
if (typeof pages[i] === "object") {
return pages[i];
} else {
throw "Invalid page index: " + i;
}
};
/**
* @see #preload * @see #preload
*/ */
ComicBook.prototype.draw = function () { ComicBook.prototype.draw = function () {
@ -153,7 +167,7 @@ function ComicBook(id, srcs, opts) {
else { this.drawPage(); } else { this.drawPage(); }
}; };
/* /**
* Zoom the canvas * Zoom the canvas
* *
* @param new_scale {Number} Scale the canvas to this ratio * @param new_scale {Number} Scale the canvas to this ratio
@ -161,7 +175,7 @@ function ComicBook(id, srcs, opts) {
ComicBook.prototype.zoom = function (new_scale) { ComicBook.prototype.zoom = function (new_scale) {
options.zoomMode = "manual"; options.zoomMode = "manual";
scale = new_scale; scale = new_scale;
if (typeof pages[pointer] === "object") { this.drawPage(); } if (typeof this.getPage(pointer) === "object") { this.drawPage(); }
}; };
/** /**
@ -231,8 +245,8 @@ function ComicBook(id, srcs, opts) {
var zoom_scale; var zoom_scale;
var offsetW = 0, offsetH = 0; var offsetW = 0, offsetH = 0;
var page = pages[pointer]; var page = this.getPage(pointer);
var page2 = pages[pointer + 1]; var page2 = this.getPage(pointer + 1);
if (typeof page !== "object") { throw "invalid page type '"+ typeof page +"'"; } if (typeof page !== "object") { throw "invalid page type '"+ typeof page +"'"; }
@ -341,7 +355,7 @@ function ComicBook(id, srcs, opts) {
*/ */
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 is_double_page_spread = (this.getPage(pointer-1).width > this.getPage(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" || is_double_page_spread) ? 1 : 2; pointer -= (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;