|
13 | 13 |
|
14 | 14 | get dismiss() { return this.getAttribute('dismiss'); } |
15 | 15 |
|
| 16 | + get autodismiss() { return this.getAttribute('auto-dismiss'); } |
| 17 | + |
16 | 18 | get acknowledge() { return this.getAttribute('acknowledge'); } |
17 | 19 |
|
18 | 20 | get href() { return this.getAttribute('href'); } |
|
35 | 37 | this.appendCloseButton(); |
36 | 38 | } |
37 | 39 |
|
| 40 | + if (this.hasAttribute('auto-dismiss')) { |
| 41 | + this.autoDismiss(); |
| 42 | + } |
| 43 | + |
38 | 44 | this.dispatchCustomEvent('joomla.alert.show'); |
39 | 45 | } |
40 | 46 |
|
|
70 | 76 | this.removeCloseButton(); |
71 | 77 | } |
72 | 78 | break; |
| 79 | + case 'auto-dismiss': |
| 80 | + this.autoDismiss(); |
| 81 | + break; |
73 | 82 | case 'href': |
74 | 83 | if (!newValue || newValue === '') { |
75 | 84 | this.removeCloseButton(); |
|
83 | 92 | } |
84 | 93 |
|
85 | 94 | /* Method to close the alert */ |
86 | | - close() { |
| 95 | + close(element = null) { |
87 | 96 | this.dispatchCustomEvent('joomla.alert.close'); |
88 | 97 | this.addEventListener('transitionend', () => { |
89 | 98 | this.dispatchCustomEvent('joomla.alert.closed'); |
90 | | - this.parentNode.removeChild(this); |
| 99 | + if (element) { |
| 100 | + element.remove(); |
| 101 | + } else { |
| 102 | + this.remove(); |
| 103 | + } |
91 | 104 | }, false); |
92 | 105 | this.classList.remove('joomla-alert--show'); |
93 | 106 | } |
|
148 | 161 | }); |
149 | 162 | } |
150 | 163 | } |
| 164 | + } |
151 | 165 |
|
152 | | - if (this.hasAttribute('auto-dismiss')) { |
153 | | - setTimeout(() => { |
154 | | - self.dispatchCustomEvent('joomla.alert.buttonClicked'); |
155 | | - if (self.hasAttribute('data-callback')) { |
156 | | - window[self.getAttribute('data-callback')](); |
157 | | - } else { |
158 | | - self.close(); |
159 | | - } |
160 | | - }, self.getAttribute('auto-dismiss') ? parseInt(self.getAttribute('auto-dismiss'), 10) : 3000); |
161 | | - } |
| 166 | + /* Method to auto-dismiss */ |
| 167 | + autoDismiss() { |
| 168 | + const self = this; |
| 169 | + setTimeout(() => { |
| 170 | + self.dispatchCustomEvent('joomla.alert.buttonClicked'); |
| 171 | + if (self.hasAttribute('data-callback')) { |
| 172 | + window[self.getAttribute('data-callback')](); |
| 173 | + } else { |
| 174 | + self.close(self); |
| 175 | + } |
| 176 | + }, parseInt(self.getAttribute('auto-dismiss'), 10) ? self.getAttribute('auto-dismiss') : 3000); |
162 | 177 | } |
163 | 178 |
|
164 | 179 | /* Method to remove the close button */ |
165 | 180 | removeCloseButton() { |
166 | 181 | const button = this.querySelector('button'); |
167 | 182 | if (button) { |
168 | 183 | button.removeEventListener('click', this); |
169 | | - button.parentNode.removeChild(button); |
| 184 | + button.remove(); |
170 | 185 | } |
171 | 186 | } |
172 | 187 |
|
|
0 commit comments