-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
sePromptDialog.js
93 lines (86 loc) · 1.84 KB
/
sePromptDialog.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import SePlainAlertDialog from './SePlainAlertDialog.js'
/**
* @class SePromptDialog
*/
export class SePromptDialog extends HTMLElement {
/**
* @function constructor
*/
constructor () {
super()
// create the shadowDom and insert the template
this._shadowRoot = this.attachShadow({ mode: 'open' })
this.dialog = new SePlainAlertDialog()
}
/**
* @function observedAttributes
* @returns {any} observed
*/
static get observedAttributes () {
return ['title', 'close']
}
/**
* @function attributeChangedCallback
* @param {string} name
* @param {string} oldValue
* @param {string} newValue
* @returns {void}
*/
attributeChangedCallback (name, oldValue, newValue) {
switch (name) {
case 'title':
if (this.dialog.opened) {
this.dialog.close()
}
this.dialog.textContent = newValue
this.dialog.choices = ['Cancel']
this.dialog.open()
break
case 'close':
if (this.dialog.opened) {
this.dialog.close()
} else {
this.dialog.open()
}
break
default:
console.error('unknown attr for:', name, 'newValue =', newValue)
break
}
}
/**
* @function get
* @returns {any}
*/
get title () {
return this.getAttribute('title')
}
/**
* @function set
* @returns {void}
*/
set title (value) {
this.setAttribute('title', value)
}
/**
* @function get
* @returns {any}
*/
get close () {
return this.getAttribute('close')
}
/**
* @function set
* @returns {void}
*/
set close (value) {
// boolean value => existence = true
if (value) {
this.setAttribute('close', 'true')
} else {
this.removeAttribute('close')
}
}
}
// Register
customElements.define('se-prompt-dialog', SePromptDialog)