|
14 | 14 | console.log(`SimpleToast(v${localToast.versionString}): Publicized`); |
15 | 15 | } |
16 | 16 | })(this, () => { |
17 | | - const version = buildVersion(2, 0, 1); |
| 17 | + const version = buildVersion(2, 0, 2); |
18 | 18 | const style = { |
19 | 19 | root: { |
20 | 20 | display: 'flex', |
|
76 | 76 | return old; |
77 | 77 | } |
78 | 78 |
|
| 79 | + function getClassName(clazz) { |
| 80 | + if (Array.isArray(clazz)) { |
| 81 | + return clazz.join(' '); |
| 82 | + } |
| 83 | + if (typeof clazz === 'string') { |
| 84 | + return clazz; |
| 85 | + } |
| 86 | + return undefined; |
| 87 | + } |
| 88 | + |
79 | 89 | const toasts = new Map(); |
80 | 90 | let root = (() => { |
81 | 91 | function create() { |
|
146 | 156 | const body = el.appendChild(document.createElement('span')); |
147 | 157 | const fel = el.appendChild(document.createElement('span')); |
148 | 158 | if (className) { |
149 | | - const clazz = className.toast || className; |
150 | | - el.className = Array.isArray(clazz) ? clazz.join(' ') : (typeof clazz === 'string' ? clazz : undefined); |
| 159 | + el.className = getClassName(className.toast || className); |
151 | 160 | } |
152 | 161 | applyCSS(el, style.toast); |
153 | 162 | applyCSS(el, css.toast || css); |
|
172 | 181 | body.innerHTML = newText; |
173 | 182 | }, |
174 | 183 | exists: () => toasts.has(id), |
175 | | - close: (closeType) => { |
| 184 | + close: (closeType = 'unknown') => { |
176 | 185 | if (!toast.exists()) return; |
177 | 186 | root.removeChild(el); |
178 | 187 | toasts.delete(id); |
179 | 188 | if (typeof onClose === 'function') { |
180 | | - onClose.call(safeToast, closeType || 'unknown', safeToast); |
| 189 | + onClose.call(safeToast, closeType, safeToast); |
181 | 190 | } |
182 | 191 | }, |
183 | 192 | }; |
|
192 | 201 | buttons.forEach((button) => { |
193 | 202 | if (!button.text) return; |
194 | 203 | const elb = document.createElement('button'); |
195 | | - if (button.className || className && className.button) { |
196 | | - const clazz = button.className || className.button; |
197 | | - elb.className = Array.isArray(clazz) ? clazz.join(' ') : clazz; |
| 204 | + if (button.className || className?.button) { |
| 205 | + elb.className = getClassName(button.className || className.button); |
198 | 206 | } |
199 | 207 | elb.innerHTML = button.text; |
200 | 208 | applyCSS(elb, style.button); |
201 | 209 | applyCSS(elb, css.button); |
202 | 210 | applyCSS(elb, button.css); |
203 | 211 | if (typeof button.onclick === 'function') { |
204 | | - elb.onclick = button.onclick; |
| 212 | + elb.onclick = (e) => button.onclick.call(safeToast, e, safeToast); |
205 | 213 | } |
206 | 214 | let prev = {}; |
207 | 215 | elb.onmouseover = () => { |
208 | 216 | const hoverStyle = Object.assign( |
209 | 217 | {}, |
210 | 218 | style.button.mouseOver, |
211 | | - css.button && css.button.mouseOver, |
212 | | - button.css && button.css.mouseOver |
| 219 | + css.button?.mouseOver, |
| 220 | + button.css?.mouseOver |
213 | 221 | ); |
214 | 222 | prev = applyCSS(hoverStyle); |
215 | 223 | }; |
|
0 commit comments