-
-
Notifications
You must be signed in to change notification settings - Fork 322
Expand file tree
/
Copy pathdialog_link.js
More file actions
36 lines (29 loc) · 774 Bytes
/
dialog_link.js
File metadata and controls
36 lines (29 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Dialog } from "alchemy_admin/dialog"
export class DialogLink extends HTMLAnchorElement {
connectedCallback() {
this.addEventListener("click", this)
}
disconnectedCallback() {
this.removeEventListener("click", this)
}
handleEvent(evt) {
if (!this.disabled) {
this.openDialog()
}
evt.preventDefault()
}
openDialog() {
this.dialog = new Dialog(this.getAttribute("href"), this.dialogOptions)
this.dialog.open()
}
get dialogOptions() {
const options = this.dataset.dialogOptions
? JSON.parse(this.dataset.dialogOptions)
: {}
return options
}
get disabled() {
return this.classList.contains("disabled")
}
}
customElements.define("alchemy-dialog-link", DialogLink, { extends: "a" })