2013-05-03 11:57:08 +00:00
|
|
|
/**
|
2014-01-22 10:12:51 +00:00
|
|
|
* @name LoadingBar Module
|
|
|
|
* @description This module is used to show and hide the loading bar.
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2014 by Tobias Reich
|
2013-05-03 11:57:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
loadingBar = {
|
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
status: null,
|
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
show: function(status, errorText) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
if (status==="error") {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
loadingBar.status = "error";
|
|
|
|
|
2014-02-25 22:37:05 +00:00
|
|
|
if (!errorText) errorText = "Whoops, it looks like something went wrong. Please reload the site and try again!";
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
lychee.loadingBar
|
|
|
|
.removeClass("loading uploading error")
|
|
|
|
.addClass(status)
|
2014-01-22 10:12:51 +00:00
|
|
|
.html("<h1>Error: <span>" + errorText + "</span></h1>")
|
2013-06-17 18:40:04 +00:00
|
|
|
.show()
|
|
|
|
.css("height", "40px");
|
2014-01-22 10:12:51 +00:00
|
|
|
if (visible.controls()) lychee.header.addClass("error");
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
clearTimeout(lychee.loadingBar.data("timeout"));
|
|
|
|
lychee.loadingBar.data("timeout", setTimeout(function() { loadingBar.hide(true) }, 3000));
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-02-25 22:37:05 +00:00
|
|
|
} else if (loadingBar.status===null) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
loadingBar.status = "loading";
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
clearTimeout(lychee.loadingBar.data("timeout"));
|
|
|
|
lychee.loadingBar.data("timeout", setTimeout(function() {
|
2013-05-03 11:57:08 +00:00
|
|
|
lychee.loadingBar
|
|
|
|
.show()
|
2013-06-17 18:40:04 +00:00
|
|
|
.removeClass("loading uploading error")
|
|
|
|
.addClass("loading");
|
2014-01-22 10:12:51 +00:00
|
|
|
if (visible.controls()) lychee.header.addClass("loading");
|
2013-06-17 18:40:04 +00:00
|
|
|
}, 1000));
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
hide: function(force_hide) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-02-25 22:37:05 +00:00
|
|
|
if ((loadingBar.status!=="error"&&loadingBar.status!==null)||force_hide) {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
loadingBar.status = null;
|
|
|
|
clearTimeout(lychee.loadingBar.data("timeout"));
|
|
|
|
lychee.loadingBar.html("").css("height", "3px");
|
2014-01-22 10:12:51 +00:00
|
|
|
if (visible.controls()) lychee.header.removeClass("error loading");
|
2013-09-08 17:50:31 +00:00
|
|
|
setTimeout(function() { lychee.loadingBar.hide() }, 300);
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-25 22:37:05 +00:00
|
|
|
};
|