Fallback progress bar for gzipped images

This commit is contained in:
copy 2014-02-22 21:55:36 +01:00
parent 64e7aad9e9
commit 3821d4fb71

View file

@ -432,24 +432,27 @@
}
}
function show_progress(msg, e)
function show_progress(info, e)
{
var el = $("loading");
el.style.display = "block";
if(e.lengthComputable)
if(e.lengthComputable || (info.total && typeof e.loaded === "number"))
{
var per100 = e.loaded / e.total * 100 | 0;
var per100 = e.loaded / (e.total || info.total) * 100 | 0;
per100 = Math.min(100, Math.max(0, per100));
el.textContent = msg + " " + per100 + "% [" +
el.textContent = info.msg + " " + per100 + "% [" +
String.chr_repeat("#", per100 >> 1) +
String.chr_repeat(" ", 50 - (per100 >> 1)) + "]";
}
else
{
el.textContent = "Loading ...";
if(!info.ticks)
info.ticks = 0;
el.textContent = info.msg + " " + String.chr_repeat(".", info.ticks++ % 50);
}
}
@ -490,7 +493,7 @@
// - doesn't support writing yet
var loader = new SyncFileBuffer(file);
loader.onprogress = show_progress.bind(this, "Loading disk image into memory");
loader.onprogress = show_progress.bind(this, { msg: "Loading disk image into memory" });
loader.onload = function()
{
@ -544,7 +547,7 @@
settings.fda = new SyncBuffer(buffer);
set_title("FreeDOS");
init(settings);
}, show_progress.bind(this, "Downloading image"));
}, show_progress.bind(this, { msg: "Downloading image", total: 737280 }));
$("start_freedos").blur();
$("boot_options").style.display = "none";
@ -557,7 +560,7 @@
settings.fda = new SyncBuffer(buffer);
set_title("Windows");
init(settings);
}, show_progress.bind(this, "Downloading image"));
}, show_progress.bind(this, { msg: "Downloading image", total: 1474560 }));
$("start_win101").blur();
$("boot_options").style.display = "none";
@ -571,7 +574,7 @@
settings.cdrom = new SyncBuffer(buffer);
set_title("Linux");
init(settings);
}, show_progress.bind(this, "Downloading image"));
}, show_progress.bind(this, { msg: "Downloading image", total: 5632000 }));
$("start_linux").blur();
$("boot_options").style.display = "none";
@ -584,7 +587,7 @@
settings.fda = new SyncBuffer(buffer);
set_title("KolibriOS");
init(settings);
}, show_progress.bind(this, "Downloading image"));
}, show_progress.bind(this, { msg: "Downloading image", total: 1474560 }));
$("start_koli").blur();
$("boot_options").style.display = "none";
@ -597,7 +600,7 @@
settings.fda = new SyncBuffer(buffer);
set_title("OpenBSD");
init(settings);
}, show_progress.bind(this, "Downloading image"));
}, show_progress.bind(this, { msg: "Downloading image", total: 1474560 }));
$("start_bsd").blur();
$("boot_options").style.display = "none";
@ -610,7 +613,7 @@
settings.fda = new SyncBuffer(buffer);
set_title("Sol OS");
init(settings);
}, show_progress.bind(this, "Downloading image"));
}, show_progress.bind(this, { msg: "Downloading image", total: 1474560 }));
$("start_sol").blur();
$("boot_options").style.display = "none";