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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* global $, APP */
  2. /**
  3. * Base class for overlay components - the components which are displayed on
  4. * top of the application with semi-transparent background covering the whole
  5. * screen.
  6. */
  7. export default class Overlay{
  8. /**
  9. * Creates new <tt>Overlay</tt> instance.
  10. */
  11. constructor() {
  12. /**
  13. *
  14. * @type {jQuery}
  15. */
  16. this.$overlay = null;
  17. /**
  18. * Indicates if this overlay should use the light look & feel or the
  19. * standard one.
  20. * @type {boolean}
  21. */
  22. this.isLightOverlay = false;
  23. }
  24. /**
  25. * Template method which should be used by subclasses to provide the overlay
  26. * content. The contents provided by this method are later subject to
  27. * the translation using {@link APP.translation.translateElement}.
  28. * @return {string} HTML representation of the overlay dialog contents.
  29. * @protected
  30. */
  31. _buildOverlayContent() {
  32. return '';
  33. }
  34. /**
  35. * Constructs the HTML body of the overlay dialog.
  36. *
  37. * @private
  38. */
  39. _buildOverlayHtml() {
  40. let overlayContent = this._buildOverlayContent();
  41. let containerClass = this.isLightOverlay ? "overlay__container-light"
  42. : "overlay__container";
  43. this.$overlay = $(`
  44. <div class=${containerClass}>
  45. <div class='overlay__content'>
  46. ${overlayContent}
  47. </div>
  48. </div>`);
  49. APP.translation.translateElement(this.$overlay);
  50. }
  51. /**
  52. * Checks whether the page reload overlay has been displayed.
  53. * @return {boolean} <tt>true</tt> if the page reload overlay is currently
  54. * visible or <tt>false</tt> otherwise.
  55. */
  56. isVisible() {
  57. return this.$overlay && this.$overlay.parents('body').length > 0;
  58. }
  59. /**
  60. * Template method called just after the overlay is displayed for the first
  61. * time.
  62. * @protected
  63. */
  64. _onShow() {
  65. // To be overridden by subclasses.
  66. }
  67. /**
  68. * Shows the overlay dialog and attaches the underlying HTML representation
  69. * to the DOM.
  70. */
  71. show() {
  72. !this.$overlay && this._buildOverlayHtml();
  73. if (!this.isVisible()) {
  74. this.$overlay.appendTo('body');
  75. this._onShow();
  76. }
  77. }
  78. /**
  79. * Hides the overlay dialog and detaches it's HTML representation from
  80. * the DOM.
  81. */
  82. hide() {
  83. this.$overlay && this.$overlay.detach();
  84. }
  85. }