39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
export default class PreviewContentDialog extends HTMLDialogElement {
|
|
#headingEl;
|
|
#contentEl;
|
|
#closeBtnEl;
|
|
|
|
constructor() {
|
|
super();
|
|
this.#headingEl = this.querySelector('.modal-heading');
|
|
this.#contentEl = this.querySelector('.modal-content');
|
|
this.#closeBtnEl = this.querySelector('.modal-close');
|
|
|
|
this.setHeading = this.setHeading.bind(this);
|
|
this.setContent = this.setContent.bind(this);
|
|
|
|
this.#closeBtnEl.addEventListener('click', () => this.close());
|
|
document.addEventListener('hidePreviewContentModal', () => this.close());
|
|
document.addEventListener('showPreviewContentModal', (event) => {
|
|
this.display(event.detail);
|
|
});
|
|
}
|
|
|
|
setHeading(heading) {
|
|
this.#headingEl.innerHTML = heading;
|
|
}
|
|
|
|
setContent(content) {
|
|
this.#contentEl.innerHTML = content;
|
|
}
|
|
|
|
display({ heading, content }) {
|
|
if (this.hasAttribute('mdWidth')) {
|
|
this.style.width = this.getAttribute('mdWidth');
|
|
}
|
|
this.setHeading(heading);
|
|
this.setContent(content);
|
|
this.showModal();
|
|
}
|
|
}
|