loadingBar.js 1.8 KB

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