put back page rendering code into the preload method

This commit is contained in:
Bala Clark 2011-09-16 15:22:08 +02:00
parent 4d38b42d2e
commit c29c8b8275

View file

@ -452,9 +452,10 @@ function ComicBook(id, srcs, opts) {
*/ */
ComicBook.prototype.preload = function () { ComicBook.prototype.preload = function () {
this.showControl("loadingOverlay");
var i = pointer; // the current page counter for this method var i = pointer; // the current page counter for this method
var rendered = false;
this.showControl("loadingOverlay");
function loadImage(i) { function loadImage(i) {
@ -462,17 +463,41 @@ function ComicBook(id, srcs, opts) {
page.src = srcs[i]; page.src = srcs[i];
page.onload = function () { page.onload = function () {
pages[i] = this; pages[i] = this;
loaded.push(i); loaded.push(i);
$("#cb-status").text("loading " + Math.floor((loaded.length / no_pages) * 100) + "%"); var percentage_loaded = Math.floor((loaded.length / no_pages) * 100);
// TODO: put back in the page render code, page request code $("#cb-status").text("loading " + percentage_loaded + "%");
// double page mode needs an extra page added
var buffer = (options.displayMode === "double" && pointer < srcs.length-1) ? 1 : 0;
// start rendering the comic when the requested page is ready
if ((rendered === false && ($.inArray(pointer + buffer, loaded) !== -1)
||
(typeof page_requested === "number" && $.inArray(page_requested, loaded) !== -1))
) {
// if the user is waiting for a page to be loaded, render that one instead of the default pointer
if (typeof page_requested === "number") {
pointer = page_requested-1;
page_requested = false;
}
ComicBook.prototype.drawPage();
ComicBook.prototype.hideControl("loadingOverlay");
rendered = true;
}
if (percentage_loaded === 100) {
$("#cb-status").delay(500).fadeOut();
}
}; };
} }
// Loads the pages at a rate of 3 forward, 1 back. This should make scrolling // loads pages in both directions so you don't have to wait for all pages
// pages in both directions faster. // to be loaded before you can scroll backwards
function preload(start, stop) { function preload(start, stop) {
var forward_buffer = 3; // TODO: make this into a config option? var forward_buffer = 3; // TODO: make this into a config option?