File: //var/www/innodrive/src/js/modules/modal-message.js
import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock';
const template = `<div class="modal-message"><div><h2></h2><p></p><div><button class="button-link">Закрыть</button></div></div></div>`;
class ModalMessage {
constructor () {
this.container = document.createElement('div');
this.container.innerHTML = template;
this.modal = this.container.querySelector('.modal-message');
this.msgContainer = this.container.querySelector('.modal-message p');
this.headingContainer = this.container.querySelector('.modal-message h2');
this.closeButton = this.container.querySelector('.modal-message button');
document.querySelector('body').appendChild(this.container);
this.hide = this.hide.bind(this);
this.closeButton.addEventListener('click', this.hide);
}
show (heading, msg) {
this.msgContainer.textContent = msg;
this.headingContainer.textContent = heading;
this.modal.classList.add('js-shown');
disableBodyScroll();
}
hide () {
this.msgContainer.textContent = '';
this.headingContainer.textContent = '';
this.modal.classList.remove('js-shown');
enableBodyScroll();
}
}
export default ModalMessage;