loadingBar.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. .addClass(status)
  26. .html('<h1>Error: <span>' + errorText + '</span></h1>')
  27. .show()
  28. .css('height', '40px');
  29. // Set timeout
  30. clearTimeout(loadingBar._timeout);
  31. loadingBar._timeout = setTimeout(function() {
  32. loadingBar.hide(true)
  33. }, 3000);
  34. return true;
  35. }
  36. if (loadingBar.status===null) {
  37. // Set status
  38. loadingBar.status = 'loading';
  39. // Set timeout
  40. clearTimeout(loadingBar._timeout);
  41. loadingBar._timeout = setTimeout(function() {
  42. // Move header down
  43. if (visible.header()) header.dom().addClass('loading');
  44. // Modify loading
  45. loadingBar.dom()
  46. .removeClass('loading uploading error')
  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. if (visible.header()) header.dom().removeClass('error loading');
  59. // Modify loading
  60. loadingBar.dom()
  61. .html('')
  62. .css('height', '3px');
  63. // Set timeout
  64. clearTimeout(loadingBar._timeout);
  65. setTimeout(function() { loadingBar.dom().hide() }, 300);
  66. }
  67. }