loadingBar.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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===undefined||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('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(function() {
  31. loadingBar.hide(true)
  32. }, 3000);
  33. return true;
  34. }
  35. if (loadingBar.status===null) {
  36. // Set status
  37. loadingBar.status = 'loading';
  38. // Set timeout
  39. clearTimeout(loadingBar._timeout);
  40. loadingBar._timeout = setTimeout(function() {
  41. // Move header down
  42. if (visible.header()) header.dom().addClass('loading');
  43. // Modify loading
  44. loadingBar.dom()
  45. .removeClass('loading uploading error')
  46. .html('')
  47. .addClass('loading')
  48. .show();
  49. }, 1000);
  50. return true;
  51. }
  52. }
  53. loadingBar.hide = function(force) {
  54. if ((loadingBar.status!=='error'&&loadingBar.status!==null)||force) {
  55. // Remove status
  56. loadingBar.status = null;
  57. // Move header up
  58. header.dom().removeClass('error loading');
  59. // Set timeout
  60. clearTimeout(loadingBar._timeout);
  61. setTimeout(function() { loadingBar.dom().hide() }, 300);
  62. }
  63. }