ajsfw
Version:
Ajs Framework
84 lines (83 loc) • 3.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var ProgressBar = (function () {
function ProgressBar() {
}
ProgressBar.setDOMElement = function (progressBarElementId) {
ProgressBar._pbar = document.getElementById(progressBarElementId);
ProgressBar._perc = document.getElementById(progressBarElementId + "Perc");
ProgressBar._lbl = document.getElementById(progressBarElementId + "Label");
if (!ProgressBar._checkDOM()) {
window.console.error("Invalid progress bar DOM specification!");
return;
}
ProgressBar._pbar.addEventListener("animationend", function () { return ProgressBar._hideEnd(); });
ProgressBar._pbar.addEventListener("webkitanimationend", function () { return ProgressBar._hideEnd(); });
};
ProgressBar.setTotal = function (total) {
ProgressBar._total = total;
};
ProgressBar.setCurrent = function (current) {
ProgressBar._current = current;
};
ProgressBar.setLabel = function (label) {
ProgressBar._label = label;
};
ProgressBar.resourceLoading = function (label) {
if (ProgressBar._queue.indexOf(label) === -1) {
ProgressBar._queue.push(label);
ProgressBar._update();
}
};
ProgressBar.resourceLoaded = function (label) {
ProgressBar._current += 1;
if (ProgressBar._queue.indexOf(label) !== -1) {
ProgressBar._queue.splice(ProgressBar._queue.indexOf(label), 1);
}
ProgressBar._update();
};
ProgressBar.show = function () {
if (!ProgressBar._checkDOM()) {
window.console.error("Invalid progress bar DOM specification!");
return;
}
ProgressBar._pbar.style.display = "";
ProgressBar._pbar.setAttribute("hidden", "false");
};
ProgressBar.hide = function () {
if (!ProgressBar._checkDOM()) {
window.console.error("Invalid progress bar DOM specification!");
return;
}
ProgressBar._pbar.setAttribute("hidden", "true");
};
ProgressBar._hideEnd = function () {
ProgressBar._pbar.style.display = "none";
};
ProgressBar._update = function () {
if (!ProgressBar._checkDOM()) {
return;
}
var v = Math.floor((ProgressBar._current / ProgressBar._total) * 100);
if (v >= 100) {
v = 100;
ProgressBar.hide();
}
ProgressBar._perc.style.width = v + "%";
if (ProgressBar._label === "" && ProgressBar._queue.length > 0) {
ProgressBar._lbl.innerHTML = ProgressBar._queue.join("<br />");
}
else {
ProgressBar._lbl.innerHTML = ProgressBar._label;
}
};
ProgressBar._checkDOM = function () {
return !(ProgressBar._lbl === undefined || ProgressBar._lbl === null ||
ProgressBar._pbar === undefined || ProgressBar._pbar === null ||
ProgressBar._perc === undefined || ProgressBar._perc === null);
};
return ProgressBar;
}());
ProgressBar._label = "";
ProgressBar._queue = [];
exports.ProgressBar = ProgressBar;