loadingBar.js 1.8 KB

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