Updated loadingBar.js (ES2015)

This commit is contained in:
Tobias Reich 2015-07-11 14:52:38 +02:00
parent 595e40549a
commit 63b2a2412d
4 changed files with 31 additions and 35 deletions

BIN
dist/main.js vendored Normal file → Executable file

Binary file not shown.

View File

@ -12,8 +12,8 @@ loadingBar = {
loadingBar.dom = function(selector) { loadingBar.dom = function(selector) {
if (selector===undefined||selector===null||selector==='') return loadingBar._dom; if (selector==null || selector==='') return loadingBar._dom
return loadingBar._dom.find(selector); return loadingBar._dom.find(selector)
} }
@ -22,56 +22,52 @@ loadingBar.show = function(status, errorText) {
if (status==='error') { if (status==='error') {
// Set status // Set status
loadingBar.status = 'error'; loadingBar.status = 'error'
// Parse text // Parse text
if (errorText) errorText = errorText.replace('<br>', ''); if (errorText) errorText = errorText.replace('<br>', '')
if (!errorText) errorText = 'Whoops, it looks like something went wrong. Please reload the site and try again!'; if (!errorText) errorText = 'Whoops, it looks like something went wrong. Please reload the site and try again!'
// Move header down // Move header down
if (visible.header()) header.dom().addClass('error'); if (visible.header()) header.dom().addClass('error')
// Modify loading // Modify loading
loadingBar.dom() loadingBar.dom()
.removeClass('loading uploading error') .removeClass('loading uploading error')
.html('<h1>Error: <span>' + errorText + '</span></h1>') .html(`<h1>Error: <span>${ errorText }</span></h1>`)
.addClass(status) .addClass(status)
.show(); .show()
// Set timeout // Set timeout
clearTimeout(loadingBar._timeout); clearTimeout(loadingBar._timeout)
loadingBar._timeout = setTimeout(function() { loadingBar._timeout = setTimeout(() => loadingBar.hide(true), 3000)
loadingBar.hide(true) return true
}, 3000);
return true;
} }
if (loadingBar.status===null) { if (loadingBar.status===null) {
// Set status // Set status
loadingBar.status = 'loading'; loadingBar.status = 'loading'
// Set timeout // Set timeout
clearTimeout(loadingBar._timeout); clearTimeout(loadingBar._timeout)
loadingBar._timeout = setTimeout(function() { loadingBar._timeout = setTimeout(() => {
// Move header down // Move header down
if (visible.header()) header.dom().addClass('loading'); if (visible.header()) header.dom().addClass('loading')
// Modify loading // Modify loading
loadingBar.dom() loadingBar.dom()
.removeClass('loading uploading error') .removeClass('loading uploading error')
.html('') .html('')
.addClass('loading') .addClass('loading')
.show(); .show()
}, 1000); }, 1000)
return true; return true
} }
@ -82,14 +78,14 @@ loadingBar.hide = function(force) {
if ((loadingBar.status!=='error' && loadingBar.status!==null) || force) { if ((loadingBar.status!=='error' && loadingBar.status!==null) || force) {
// Remove status // Remove status
loadingBar.status = null; loadingBar.status = null
// Move header up // Move header up
header.dom().removeClass('error loading'); header.dom().removeClass('error loading')
// Set timeout // Set timeout
clearTimeout(loadingBar._timeout); clearTimeout(loadingBar._timeout)
setTimeout(function() { loadingBar.dom().hide() }, 300); setTimeout(() => loadingBar.dom().hide(), 300)
} }