mirror of
https://github.com/locomotivemtl/locomotive-boilerplate.git
synced 2026-01-15 00:55:08 +08:00
37 lines
735 B
JavaScript
37 lines
735 B
JavaScript
import { module } from 'modujs';
|
|
|
|
export default class extends module {
|
|
constructor(m) {
|
|
super(m);
|
|
|
|
this.$closeBtn = this.$('close')[0]
|
|
}
|
|
|
|
init() {
|
|
// Prevent ESC to close dialog
|
|
this.onKeyDown = this.onKeyDown.bind(this)
|
|
}
|
|
|
|
onKeyDown(e) {
|
|
if(e.key === 'Escape') {
|
|
console.log('ESCAPE');
|
|
e.preventDefault()
|
|
this.$closeBtn.click();
|
|
}
|
|
}
|
|
|
|
populate(container) {
|
|
this.el.appendChild(container)
|
|
}
|
|
|
|
show() {
|
|
this.el.showModal();
|
|
window.addEventListener('keydown', this.onKeyDown);
|
|
}
|
|
|
|
close() {
|
|
window.removeEventListener('keydown', this.onKeyDown);
|
|
this.el.close();
|
|
}
|
|
}
|