({ title, message, confirmText, placeholder })
| 5528 | } |
| 5529 | |
| 5530 | function showTypedConfirmModal({ title, message, confirmText, placeholder }) { |
| 5531 | return new Promise(resolve => { |
| 5532 | let modal = document.getElementById("typedConfirmModal"); |
| 5533 | if (!modal) { |
| 5534 | modal = document.createElement("div"); |
| 5535 | modal.id = "typedConfirmModal"; |
| 5536 | modal.className = "modal"; |
| 5537 | modal.style.zIndex = "4000"; |
| 5538 | modal.style.display = "none"; |
| 5539 | modal.innerHTML = ` |
| 5540 | <div class="modal-content" style="max-width:520px;"> |
| 5541 | <div id="typedConfirmTitle" style="font-weight:600; margin-bottom:6px;"></div> |
| 5542 | <div id="typedConfirmMessage" style="white-space:pre-wrap; margin-bottom:10px;"></div> |
| 5543 | <input id="typedConfirmInput" class="form-control" type="text" autocomplete="off" /> |
| 5544 | <div class="modal-actions" style="margin-top:12px;"> |
| 5545 | <button id="typedConfirmYesBtn" class="btn btn-danger" disabled>Confirm</button> |
| 5546 | <button id="typedConfirmNoBtn" class="btn btn-secondary">Cancel</button> |
| 5547 | </div> |
| 5548 | </div> |
| 5549 | `; |
| 5550 | document.body.appendChild(modal); |
| 5551 | } |
| 5552 | |
| 5553 | const titleEl = document.getElementById("typedConfirmTitle"); |
| 5554 | const msgEl = document.getElementById("typedConfirmMessage"); |
| 5555 | const input = document.getElementById("typedConfirmInput"); |
| 5556 | const yes = document.getElementById("typedConfirmYesBtn"); |
| 5557 | const no = document.getElementById("typedConfirmNoBtn"); |
| 5558 | |
| 5559 | if (!titleEl || !msgEl || !input || !yes || !no) { |
| 5560 | resolve(false); |
| 5561 | return; |
| 5562 | } |
| 5563 | |
| 5564 | titleEl.textContent = title || "Confirm"; |
| 5565 | msgEl.textContent = message || ""; |
| 5566 | input.value = ""; |
| 5567 | input.placeholder = placeholder || ""; |
| 5568 | yes.disabled = true; |
| 5569 | modal.style.display = "block"; |
| 5570 | input.focus(); |
| 5571 | |
| 5572 | const onInput = () => { |
| 5573 | yes.disabled = (input.value !== confirmText); |
| 5574 | }; |
| 5575 | const cleanup = () => { |
| 5576 | modal.style.display = "none"; |
| 5577 | input.removeEventListener("input", onInput); |
| 5578 | yes.removeEventListener("click", onYes); |
| 5579 | no.removeEventListener("click", onNo); |
| 5580 | }; |
| 5581 | const onYes = () => { cleanup(); resolve(true); }; |
| 5582 | const onNo = () => { cleanup(); resolve(false); }; |
| 5583 | |
| 5584 | input.addEventListener("input", onInput); |
| 5585 | yes.addEventListener("click", onYes); |
| 5586 | no.addEventListener("click", onNo); |
| 5587 | }); |
no outgoing calls
no test coverage detected