({
msg = "",
x = window.innerWidth / 2,
y = window.innerHeight - 100,
align = "center",
styleText = "",
duration = 3000,
} = {})
| 210 | }, 3000); |
| 211 | } |
| 212 | function notify({ |
| 213 | msg = "", |
| 214 | x = window.innerWidth / 2, |
| 215 | y = window.innerHeight - 100, |
| 216 | align = "center", |
| 217 | styleText = "", |
| 218 | duration = 3000, |
| 219 | } = {}) { |
| 220 | let id = "ufs_notify_div"; |
| 221 | let exist = document.getElementById(id); |
| 222 | if (exist) exist.remove(); |
| 223 | |
| 224 | // create notify msg in website at postion, fade out animation, auto clean up |
| 225 | let div = document.createElement("div"); |
| 226 | div.id = id; |
| 227 | div.style.cssText = ` |
| 228 | position: fixed; |
| 229 | left: ${x}px; |
| 230 | top: ${y}px; |
| 231 | padding: 10px; |
| 232 | background-color: #333; |
| 233 | color: #fff; |
| 234 | border-radius: 5px; |
| 235 | z-index: 2147483647; |
| 236 | transition: all 1s ease-out; |
| 237 | ${ |
| 238 | align === "right" |
| 239 | ? "transform: translateX(-100%);" |
| 240 | : align === "center" |
| 241 | ? "transform: translateX(-50%);" |
| 242 | : "" |
| 243 | } |
| 244 | ${styleText || ""} |
| 245 | `; |
| 246 | div.innerHTML = createTrustedHtml(msg); |
| 247 | (document.body || document.documentElement).appendChild(div); |
| 248 | |
| 249 | let timeouts = []; |
| 250 | function closeAfter(_time) { |
| 251 | timeouts.forEach((t) => clearTimeout(t)); |
| 252 | timeouts = [ |
| 253 | setTimeout(() => { |
| 254 | if (div) { |
| 255 | div.style.opacity = 0; |
| 256 | div.style.top = `${y - 50}px`; |
| 257 | } |
| 258 | }, _time - 1000), |
| 259 | setTimeout(() => { |
| 260 | div?.remove(); |
| 261 | }, _time), |
| 262 | ]; |
| 263 | } |
| 264 | |
| 265 | closeAfter(duration); |
| 266 | |
| 267 | return { |
| 268 | closeAfter: closeAfter, |
| 269 | remove() { |
nothing calls this directly
no test coverage detected