fixed minor preload & hash nav bugs

This commit is contained in:
Bala Clark 2010-12-26 18:39:11 +01:00
parent e396f65748
commit 115c154c87

View file

@ -69,8 +69,8 @@ function ComicBook(id, srcs, opts) {
// enables the back button // enables the back button
function checkHash() { 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) { if (hash !== pointer && loaded.indexOf(hash) > -1) {
pointer = hash; pointer = hash;
ComicBook.prototype.draw(); ComicBook.prototype.draw();
@ -148,7 +148,7 @@ function ComicBook(id, srcs, opts) {
*/ */
ComicBook.prototype.preload = function () { 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 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 // I am using recursion instead of a forEach loop so that the next image is
// only loaded when the previous one has completely finished // only loaded when the previous one has completely finished
function preload(i) { function preload(i) {
var page = new Image(); var page = new Image();
$("#status p").text("loading page " + (i + 1) + " of " + no_pages); $("#status p").text("loading page " + (i + 1) + " of " + no_pages);
@ -186,8 +186,10 @@ function ComicBook(id, srcs, opts) {
preload(i); 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) // 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(); } if (loaded.length === no_pages) { $("#status").fadeOut(150).remove(); }
}; };
} }