loadingBar.js 1.9 KB

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