don't allow navigating to non-existant pages
This commit is contained in:
parent
4e4d707b14
commit
624c9e823b
1 changed files with 18 additions and 4 deletions
|
@ -92,8 +92,11 @@ function ComicBook(id, srcs, opts) {
|
||||||
var page_requested = false; // used to request non preloaded pages
|
var page_requested = false; // used to request non preloaded pages
|
||||||
var shiv = false;
|
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
|
// 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
|
* Gets the window.innerWidth - scrollbars
|
||||||
|
@ -388,7 +391,7 @@ function ComicBook(id, srcs, opts) {
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.getPage = function(i) {
|
ComicBook.prototype.getPage = function(i) {
|
||||||
|
|
||||||
if (i < 0 || i > srcs.length) {
|
if (i < 0 || i > srcs.length-1) {
|
||||||
throw ComicBookException.INVALID_PAGE+' '+i;
|
throw ComicBookException.INVALID_PAGE+' '+i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,7 +646,13 @@ function ComicBook(id, srcs, opts) {
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.drawNextPage = function () {
|
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) {
|
if (pointer + 1 < pages.length) {
|
||||||
pointer += (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;
|
pointer += (options.displayMode === "single" || is_double_page_spread) ? 1 : 2;
|
||||||
|
@ -658,7 +667,12 @@ function ComicBook(id, srcs, opts) {
|
||||||
*/
|
*/
|
||||||
ComicBook.prototype.drawPrevPage = function () {
|
ComicBook.prototype.drawPrevPage = function () {
|
||||||
|
|
||||||
var page = this.getPage(pointer-1);
|
var page;
|
||||||
|
|
||||||
|
try {
|
||||||
|
page = this.getPage(pointer-1);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
if (!page) { return false; }
|
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
|
is_double_page_spread = (page.width > page.height); // need to run double page check again here as we are going backwards
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue