diff --git a/lib/ComicBook.js b/lib/ComicBook.js index 8b76821..6724b0c 100644 --- a/lib/ComicBook.js +++ b/lib/ComicBook.js @@ -69,8 +69,8 @@ function ComicBook(id, srcs, opts) { // enables the back button function checkHash() { - var hash = parseInt(location.hash.substring(1),10) - 1; - + var hash = parseInt(location.hash.substring(1),10) - 1 || 0; + if (hash !== pointer && loaded.indexOf(hash) > -1) { pointer = hash; ComicBook.prototype.draw(); @@ -148,7 +148,7 @@ function ComicBook(id, srcs, opts) { */ ComicBook.prototype.preload = function () { - var srcs = this.srcs; + //var srcs = this.srcs; if (no_pages < buffer) { buffer = no_pages; } // don't get stuck if the buffer level is higher than the number of pages @@ -163,7 +163,7 @@ function ComicBook(id, srcs, opts) { // I am using recursion instead of a forEach loop so that the next image is // only loaded when the previous one has completely finished function preload(i) { - + var page = new Image(); $("#status p").text("loading page " + (i + 1) + " of " + no_pages); @@ -186,8 +186,10 @@ function ComicBook(id, srcs, opts) { preload(i); } + //console.log(loaded[loaded.length-1], pointer, pointer + buffer); + // start rendering the comic when the buffer level has been reached (FIXME: buggy, fails if trying to load the last couple of pages) - if (loaded.length === pointer + buffer) { ComicBook.prototype.drawPage(); } + if (loaded[loaded.length-1] === pointer + buffer) { ComicBook.prototype.drawPage(); } if (loaded.length === no_pages) { $("#status").fadeOut(150).remove(); } }; }