don't allow navigating to non-existant pages

This commit is contained in:
Bala Clark 2011-09-08 12:27:01 +02:00
parent 4e4d707b14
commit 624c9e823b

View file

@ -92,8 +92,11 @@ function ComicBook(id, srcs, opts) {
var page_requested = false; // used to request non preloaded pages
var shiv = false;
// page hash on first load
var hash = parseInt(location.hash.substring(1),10) - 1;
// the current page, can pass a default as a url hash
var pointer = (parseInt(location.hash.substring(1),10) - 1) || 0;
var pointer = (hash < srcs.length) ? hash : 0;
/**
* Gets the window.innerWidth - scrollbars
@ -388,7 +391,7 @@ function ComicBook(id, srcs, opts) {
*/
ComicBook.prototype.getPage = function(i) {
if (i < 0 || i > srcs.length) {
if (i < 0 || i > srcs.length-1) {
throw ComicBookException.INVALID_PAGE+' '+i;
}
@ -643,7 +646,13 @@ function ComicBook(id, srcs, opts) {
*/
ComicBook.prototype.drawNextPage = function () {
if (!this.getPage(pointer+1)) { return false; }
var page;
try {
page = this.getPage(pointer+1);
} catch (e) {}
if (!page) { return false; }
if (pointer + 1 < pages.length) {
pointer += (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;
@ -658,7 +667,12 @@ function ComicBook(id, srcs, opts) {
*/
ComicBook.prototype.drawPrevPage = function () {
var page = this.getPage(pointer-1);
var page;
try {
page = this.getPage(pointer-1);
} catch (e) {}
if (!page) { return false; }
is_double_page_spread = (page.width > page.height); // need to run double page check again here as we are going backwards