12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- /* global $, APP */
-
- /**
- * Base class for overlay components - the components which are displayed on
- * top of the application with semi-transparent background covering the whole
- * screen.
- */
- export default class Overlay{
- /**
- * Creates new <tt>Overlay</tt> instance.
- */
- constructor() {
- /**
- *
- * @type {jQuery}
- */
- this.$overlay = null;
- }
- /**
- * Template method which should be used by subclasses to provide the overlay
- * content. The contents provided by this method are later subject to
- * the translation using {@link APP.translation.translateElement}.
- * @return {string} HTML representation of the overlay dialog contents.
- * @private
- */
- _buildOverlayContent() {
- return '';
- }
- /**
- * Constructs the HTML body of the overlay dialog.
- *
- * @param isLightOverlay indicates that this will be a light overlay look
- * and feel.
- */
- buildOverlayHtml(isLightOverlay) {
-
- let overlayContent = this._buildOverlayContent();
-
- let containerClass = isLightOverlay ? "overlay__container-light"
- : "overlay__container";
-
- this.$overlay = $(`
- <div class=${containerClass}>
- <div class='overlay__content'>
- ${overlayContent}
- </div>
- </div>`);
-
- APP.translation.translateElement(this.$overlay);
- }
- /**
- * Checks whether the page reload overlay has been displayed.
- * @return {boolean} <tt>true</tt> if the page reload overlay is currently
- * visible or <tt>false</tt> otherwise.
- */
- isVisible() {
- return this.$overlay && this.$overlay.parents('body').length > 0;
- }
- /**
- * Template method called just after the overlay is displayed for the first
- * time.
- * @private
- */
- _onShow() {
- // To be overridden by subclasses.
- }
- /**
- * Shows the overlay dialog adn attaches the underlying HTML representation
- * to the DOM.
- *
- * @param isLightOverlay indicates that this will be a light overlay look
- * and feel.
- */
- show(isLightOverlay) {
-
- !this.$overlay && this.buildOverlayHtml(isLightOverlay);
-
- if (!this.isVisible()) {
- this.$overlay.appendTo('body');
- this._onShow();
- }
- }
-
- /**
- * Hides the overlay dialog and detaches it's HTML representation from
- * the DOM.
- */
- hide() {
- this.$overlay && this.$overlay.detach();
- }
- }
|