loadingBar.js 1.7 KB

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