You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PageReloadOverlay.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* global $, APP, AJS */
  2. let $overlay;
  3. /**
  4. * Conference reload counter in seconds.
  5. * @type {number}
  6. */
  7. let timeLeft;
  8. /**
  9. * Conference reload timeout in seconds.
  10. * @type {number}
  11. */
  12. let timeout;
  13. /**
  14. * Internal function that constructs overlay with the warning message and count
  15. * down towards the conference reload.
  16. */
  17. function buildReloadOverlayHtml() {
  18. $overlay = $(`
  19. <div class='overlay_container'>
  20. <div class='overlay_content'>
  21. <span data-i18n='dialog.serviceUnavailable'
  22. class='overlay_text_small'></span>
  23. <span data-i18n='dialog.conferenceReloadMsg'
  24. class='overlay_text_small'></span>
  25. <div>
  26. <div id='reloadProgressBar' class="aui-progress-indicator">
  27. <span class="aui-progress-indicator-value"></span>
  28. </div>
  29. <span id='reloadSecRemaining' class='overlay_text_small'>
  30. </span>
  31. </div>
  32. </div>
  33. </div>`);
  34. APP.translation.translateElement($overlay);
  35. }
  36. /**
  37. * Updates the progress indicator position and the label with the time left.
  38. */
  39. function updateDisplay() {
  40. const timeLeftTxt
  41. = APP.translation.translateString(
  42. "dialog.conferenceReloadTimeLeft",
  43. { seconds: timeLeft });
  44. $("#reloadSecRemaining").text(timeLeftTxt);
  45. const ratio = (timeout-timeLeft)/timeout;
  46. AJS.progressBars.update("#reloadProgressBar", ratio);
  47. }
  48. /**
  49. * Starts the reload countdown with the animation.
  50. * @param {number} timeoutSeconds how many seconds before the conference
  51. * reload will happen.
  52. */
  53. function start(timeoutSeconds) {
  54. timeLeft = timeout = timeoutSeconds;
  55. // Initialize displays
  56. updateDisplay();
  57. var intervalId = window.setInterval(function() {
  58. if (timeLeft >= 1) {
  59. timeLeft -= 1;
  60. console.info("Reloading in " + timeLeft + " seconds...");
  61. }
  62. updateDisplay();
  63. if (timeLeft === 0) {
  64. window.clearInterval(intervalId);
  65. APP.ConferenceUrl.reload();
  66. }
  67. }, 1000);
  68. }
  69. export default {
  70. /**
  71. * Checks whether the page reload overlay has been displayed.
  72. * @return {boolean} <tt>true</tt> if the page reload overlay is currently
  73. * visible or <tt>false</tt> otherwise.
  74. */
  75. isVisible() {
  76. return $overlay && $overlay.parents('body').length > 0;
  77. },
  78. /**
  79. * Shows the page reload overlay which will do the conference reload after
  80. * the given amount of time.
  81. *
  82. * @param {number} timeoutSeconds how many seconds before the conference
  83. * reload will happen.
  84. */
  85. show(timeoutSeconds) {
  86. !$overlay && buildReloadOverlayHtml();
  87. if (!this.isVisible()) {
  88. $overlay.appendTo('body');
  89. start(timeoutSeconds);
  90. }
  91. }
  92. };