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-03-30 15:43:49 +00:00
|
|
|
if (status==='error') {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
// Set status
|
|
|
|
loadingBar.status = 'error';
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
// Parse text
|
|
|
|
if (errorText) errorText = errorText.replace('<br>', '');
|
|
|
|
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
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
// Move header down
|
|
|
|
if (visible.controls()) lychee.header.addClass('error');
|
|
|
|
|
|
|
|
// Modify loading
|
2013-06-17 18:40:04 +00:00
|
|
|
lychee.loadingBar
|
2014-03-30 15:43:49 +00:00
|
|
|
.removeClass('loading uploading error')
|
2013-06-17 18:40:04 +00:00
|
|
|
.addClass(status)
|
2014-03-30 15:43:49 +00:00
|
|
|
.html('<h1>Error: <span>' + errorText + '</span></h1>')
|
2013-06-17 18:40:04 +00:00
|
|
|
.show()
|
2014-03-30 15:43:49 +00:00
|
|
|
.css('height', '40px');
|
|
|
|
|
|
|
|
// Set timeout
|
|
|
|
clearTimeout(lychee.loadingBar.data('timeout'));
|
|
|
|
lychee.loadingBar.data('timeout', setTimeout(function() { loadingBar.hide(true) }, 3000));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loadingBar.status===null) {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
// Set status
|
|
|
|
loadingBar.status = 'loading';
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
// Set timeout
|
|
|
|
clearTimeout(lychee.loadingBar.data('timeout'));
|
|
|
|
lychee.loadingBar.data('timeout', setTimeout(function() {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
// Move header down
|
|
|
|
if (visible.controls()) lychee.header.addClass('loading');
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
// Modify loading
|
2013-05-03 11:57:08 +00:00
|
|
|
lychee.loadingBar
|
2014-03-30 15:43:49 +00:00
|
|
|
.removeClass('loading uploading error')
|
|
|
|
.addClass('loading')
|
|
|
|
.show();
|
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
}, 1000));
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
return true;
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
hide: function(force) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
if ((loadingBar.status!=='error'&&loadingBar.status!==null)||force) {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2014-03-30 15:43:49 +00:00
|
|
|
// Remove status
|
2013-06-17 18:40:04 +00:00
|
|
|
loadingBar.status = null;
|
2014-03-30 15:43:49 +00:00
|
|
|
|
|
|
|
// Move header up
|
|
|
|
if (visible.controls()) lychee.header.removeClass('error loading');
|
|
|
|
|
|
|
|
// Modify loading
|
|
|
|
lychee.loadingBar
|
|
|
|
.html('')
|
|
|
|
.css('height', '3px');
|
|
|
|
|
|
|
|
// Set timeout
|
|
|
|
clearTimeout(lychee.loadingBar.data('timeout'));
|
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
|
|
|
};
|