loadingBar.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. loadingBar.status = "error";
  12. if (!errorText) errorText = "Whoops, it looks like something went wrong. Please reload the site and try again!";
  13. lychee.loadingBar
  14. .removeClass("loading uploading error")
  15. .addClass(status)
  16. .html("<h1>Error: <span>" + errorText + "</span></h1>")
  17. .show()
  18. .css("height", "40px");
  19. if (visible.controls()) lychee.header.addClass("error");
  20. clearTimeout(lychee.loadingBar.data("timeout"));
  21. lychee.loadingBar.data("timeout", setTimeout(function() { loadingBar.hide(true) }, 3000));
  22. } else if (loadingBar.status===null) {
  23. loadingBar.status = "loading";
  24. clearTimeout(lychee.loadingBar.data("timeout"));
  25. lychee.loadingBar.data("timeout", setTimeout(function() {
  26. lychee.loadingBar
  27. .show()
  28. .removeClass("loading uploading error")
  29. .addClass("loading");
  30. if (visible.controls()) lychee.header.addClass("loading");
  31. }, 1000));
  32. }
  33. },
  34. hide: function(force_hide) {
  35. if ((loadingBar.status!=="error"&&loadingBar.status!==null)||force_hide) {
  36. loadingBar.status = null;
  37. clearTimeout(lychee.loadingBar.data("timeout"));
  38. lychee.loadingBar.html("").css("height", "3px");
  39. if (visible.controls()) lychee.header.removeClass("error loading");
  40. setTimeout(function() { lychee.loadingBar.hide() }, 300);
  41. }
  42. }
  43. };