// window.confirm(text); // window.confirm(title, text); // window.confirm(title, text, options); // window.confirm(text, options); window.confirm = function(/* ... */) { var title = typeof(arguments[1]) === "string" ? arguments[0] : "Photochamber"; var text = typeof(arguments[1]) === "string" ? arguments[1] : arguments[0]; var optionsParams = arguments[2] || arguments[1] || {}; var options = { closeButtonValue: false, displayCloseButton: true, canCancel: true, okButtonText: "Ok", cancelButtonText: "Cancel" }; for (var i in options) if (optionsParams[i]) options[i] = optionsParams[i]; return new Promise(ok => { document.body.classList.add("overlay-visible"); var modalContainer = document.createElement("div"); modalContainer.className = "modal"; modalContainer.tabIndex = "-1"; modalContainer.role = "dialog"; var modal = document.createElement("div"); modal.className = "modal-dialog"; var modalContent = document.createElement("div"); modalContent.className = "modal-content"; var modalTitle = document.createElement("div"); modalTitle.className = "modal-header"; var modalTitleLabel = document.createElement("h5"); modalTitleLabel.textContent = title; modalTitleLabel.className = "modal-title"; modalTitle.appendChild(modalTitleLabel); if (options.displayCloseButton) { var closeBt = document.createElement("button"); closeBt.type = "button"; closeBt.class = "close"; closeBt.addEventListener("click", e => closeHandler()); modalTitle.appendChild(closeBt); var span = document.createElement("span"); span.ariaHidden = true; span.innerHTML = "×"; closeBt.appendChild(span); } var modalBody = document.createElement("div"); modalBody.className = "modal-body"; modalBody.textContent = text; var modalFooter = document.createElement("div"); modalFooter.className = "modal-footer"; var okButton = document.createElement("button"); okButton.type = "button"; okButton.className = "btn"; okButton.textContent = options.okButtonText; okButton.addEventListener("click", () => { confirmValue(true); }); modalFooter.appendChild(okButton); if (options.canCancel) { var cancelButton = document.createElement("button"); cancelButton.type = "button"; cancelButton.className = "btn btn-danger"; cancelButton.textContent = options.cancelButtonText; cancelButton.addEventListener("click", () => { confirmValue(false); }); modalFooter.appendChild(cancelButton); } modalContainer.style.display = "initial"; modalContainer.appendChild(modal); modal.appendChild(modalContent); modalContent.appendChild(modalTitle); modalContent.appendChild(modalBody); modalContent.appendChild(modalFooter); document.getElementById("pch-page").appendChild(modalContainer); let closeHandler = () => { confirmValue(options.closeButtonValue); }; function confirmValue(val) { if (options.displayCloseButton) document.removeOnClosePopinRequested(closeHandler); document.getElementById("pch-page").removeChild(modalContainer); document.body.classList.remove("overlay-visible"); ok(val); }; if (options.displayCloseButton) { document.onClosePopinRequested(closeHandler); } }); }