您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Overlay.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /**
  19. * Template method which should be used by subclasses to provide the overlay
  20. * content. The contents provided by this method are later subject to
  21. * the translation using {@link APP.translation.translateElement}.
  22. * @return {string} HTML representation of the overlay dialog contents.
  23. * @private
  24. */
  25. _buildOverlayContent() {
  26. return '';
  27. }
  28. /**
  29. * Constructs the HTML body of the overlay dialog.
  30. *
  31. * @param isLightOverlay indicates that this will be a light overlay look
  32. * and feel.
  33. */
  34. buildOverlayHtml(isLightOverlay) {
  35. let overlayContent = this._buildOverlayContent();
  36. let containerClass = isLightOverlay ? "overlay__container-light"
  37. : "overlay__container";
  38. this.$overlay = $(`
  39. <div class=${containerClass}>
  40. <div class='overlay__content'>
  41. ${overlayContent}
  42. </div>
  43. </div>`);
  44. APP.translation.translateElement(this.$overlay);
  45. }
  46. /**
  47. * Checks whether the page reload overlay has been displayed.
  48. * @return {boolean} <tt>true</tt> if the page reload overlay is currently
  49. * visible or <tt>false</tt> otherwise.
  50. */
  51. isVisible() {
  52. return this.$overlay && this.$overlay.parents('body').length > 0;
  53. }
  54. /**
  55. * Template method called just after the overlay is displayed for the first
  56. * time.
  57. * @private
  58. */
  59. _onShow() {
  60. // To be overridden by subclasses.
  61. }
  62. /**
  63. * Shows the overlay dialog adn attaches the underlying HTML representation
  64. * to the DOM.
  65. *
  66. * @param isLightOverlay indicates that this will be a light overlay look
  67. * and feel.
  68. */
  69. show(isLightOverlay) {
  70. !this.$overlay && this.buildOverlayHtml(isLightOverlay);
  71. if (!this.isVisible()) {
  72. this.$overlay.appendTo('body');
  73. this._onShow();
  74. }
  75. }
  76. /**
  77. * Hides the overlay dialog and detaches it's HTML representation from
  78. * the DOM.
  79. */
  80. hide() {
  81. this.$overlay && this.$overlay.detach();
  82. }
  83. }