/** * BSDialog5 * @version v0.1.0.001 (2022/10/15 1713) */ var BSDialog5 = { Create: function (id, title, url, size) { var a = this; a.id = id; a.title = title; a.url = url; a.size = a.sanitiseSize(size); a.addBackdrop(a.id); a.addModal(a.id); if (a.isNullOrWhitespace(a.url)) { a.Update(a.id, "No URL specified"); } else { a.Update(a.id, null); fetch(a.url, { cache: 'no-cache', credentials: 'same-origin' }).then(data => data.text()).then(data => { a.Update(a.id, data); }).catch((error) => { a.Update(a.id, "Error: " + error); }).then(function(){ // do nothing }); } }, Clear: function () { var a = this; // remove all backdrop var result = document.body.querySelectorAll(".bsdia5-backdrop"); for (var i=0; i< result.length; i++) { result[i].parentNode.removeChild(result[i]); } // remove all dialog result = document.body.querySelectorAll(".bsdia5"); for (var i=0; i< result.length; i++) { result[i].parentNode.removeChild(result[i]); } // lock background document.getElementsByTagName("body")[0].style.overflow = "auto"; }, Close: function (id) { var a = this; // remove modal var modal = a.getModal(id); if (modal !== null) { modal.parentNode.removeChild(modal); } // remove backdrop var backdrop = a.getBackdrop(id); if (backdrop !== null) { backdrop.parentNode.removeChild(backdrop); } // lock background document.getElementsByTagName("body")[0].style.overflow = "auto"; }, Exists: function (id) { return (document.body.querySelectorAll("#bsdia5-dlg" + id).length > 0); }, ShowToast: function (id, title, message, size) { var a = this; a.id = id; a.title = title; a.size = a.sanitiseSize(size); a.addBackdrop(a.id); a.addModal(a.id); a.Update(a.id, message); }, ToggleSize: function (id) { var a = this; var modal = a.getModal(id); if (modal == null) { return; } if (modal.classList.contains("bsdia5-md")) { modal.classList.remove("bsdia5-md"); modal.classList.add("bsdia5-lg"); } else if (modal.classList.contains("bsdia5-lg")) { modal.classList.remove("bsdia5-lg"); modal.classList.add("bsdia5-xl"); } else if (modal.classList.contains("bsdia5-xl")) { modal.classList.remove("bsdia5-xl"); modal.classList.add("bsdia5-sm"); } else if (modal.classList.contains("bsdia5-sm")) { modal.classList.remove("bsdia5-sm"); modal.classList.add("bsdia5-md"); } }, Update: function (id, html) { var a = this; var content = a.getModalContent(id); if (content === null) { return; } if (html === null) { // $(content).html('Loading...'); $(content).html('