loadingBar.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @description This module is used to show and hide the loading bar.
  3. * @copyright 2015 by Tobias Reich
  4. */
  5. loadingBar = {
  6. status : null,
  7. _dom : $('#loading')
  8. }
  9. loadingBar.dom = function(selector) {
  10. if (selector==null || selector==='') return loadingBar._dom
  11. return loadingBar._dom.find(selector)
  12. }
  13. loadingBar.show = function(status, errorText) {
  14. if (status==='error') {
  15. // Set status
  16. loadingBar.status = 'error'
  17. // Parse text
  18. if (errorText) errorText = errorText.replace('<br>', '')
  19. if (!errorText) errorText = 'Whoops, it looks like something went wrong. Please reload the site and try again!'
  20. // Move header down
  21. if (visible.header()) header.dom().addClass('header__error')
  22. // Modify loading
  23. loadingBar.dom()
  24. .removeClass('loading uploading error')
  25. .html(`<h1>Error: <span>${ errorText }</span></h1>`)
  26. .addClass(status)
  27. .show()
  28. // Set timeout
  29. clearTimeout(loadingBar._timeout)
  30. loadingBar._timeout = setTimeout(() => loadingBar.hide(true), 3000)
  31. return true
  32. }
  33. if (loadingBar.status===null) {
  34. // Set status
  35. loadingBar.status = 'loading'
  36. // Set timeout
  37. clearTimeout(loadingBar._timeout)
  38. loadingBar._timeout = setTimeout(() => {
  39. // Move header down
  40. if (visible.header()) header.dom().addClass('header__loading')
  41. // Modify loading
  42. loadingBar.dom()
  43. .removeClass('loading uploading error')
  44. .html('')
  45. .addClass('loading')
  46. .show()
  47. }, 1000)
  48. return true
  49. }
  50. }
  51. loadingBar.hide = function(force) {
  52. if ((loadingBar.status!=='error' && loadingBar.status!=null) || force) {
  53. // Remove status
  54. loadingBar.status = null
  55. // Move header up
  56. header.dom().removeClass('header__error header__loading')
  57. // Set timeout
  58. clearTimeout(loadingBar._timeout)
  59. setTimeout(() => loadingBar.dom().hide(), 300)
  60. }
  61. }