You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and dots ('.'), can be up to 35 characters long. Letters must be lowercase.
34 lines
901 B
34 lines
901 B
export class Modal { |
|
constructor(name, template_engine, tag = "#block-content") { |
|
this.name = name; |
|
this.template_engine = template_engine; |
|
this.tag = tag; |
|
this.modal_class = ""; |
|
} |
|
|
|
render(template) { |
|
this.template_engine.get_template((reponse) => { |
|
$(this.tag).prepend(` |
|
<dialog id="${this.name}" class="${this.modal_class} modal-disable"> |
|
${reponse} |
|
</dialog> |
|
`); |
|
}, template); |
|
} |
|
|
|
on_close(callback) { |
|
document.querySelector(`#${this.name}`).addEventListener("close", callback); |
|
} |
|
|
|
add_class(modal_class) { |
|
this.modal_class = `${this.modal_class} ${modal_class}`; |
|
} |
|
|
|
show() { |
|
document.querySelector(`#${this.name}`).showModal(); |
|
} |
|
|
|
close() { |
|
document.querySelector(`#${this.name}`).close(); |
|
} |
|
} |