From 0d3df0244989f5a9426d0bec899f0852817bc875 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 30 Aug 2023 01:02:45 +0100 Subject: [PATCH] Refactor resizing --- bsdialog4.js | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/bsdialog4.js b/bsdialog4.js index adac63e..c7385ee 100644 --- a/bsdialog4.js +++ b/bsdialog4.js @@ -35,7 +35,6 @@ var BSDialog = { const _options = Object.assign(a.Default().PromptOptions, options); return await new Promise((resolve, reject) => { - a.Create(id, _options.Title, _options.Message, _options.Size); let html = ''; @@ -138,10 +137,17 @@ var BSDialog = { if (!this.isNullOrWhitespace(_options.Size)) { modal.Modal[0].querySelectorAll(".modal-dialog").forEach(function(e) { - e.classList.remove("modal-sm"); - e.classList.remove("modal-md"); - e.classList.remove("modal-lg"); - e.classList.remove("modal-xl"); + + e.classList.forEach(function(e2) { + if (e2 == "modal-dialog") { + return; + } + + if (e2.startsWith("modal-")) { + e.classList.remove(e2); + } + }); + e.classList.add("modal-" + _options.Size); }); } @@ -367,30 +373,19 @@ var BSDialog = { let modalDialog = modal.Modal[0].querySelectorAll(".modal-dialog")[0]; if (modalDialog.classList.contains('modal-sm')) { - modalDialog.classList.remove("modal-sm"); - modalDialog.classList.add("modal-md"); + a.Update({ ID: a.id, Size: "md" }); } else if (modalDialog.classList.contains('modal-md')) { - modalDialog.classList.remove("modal-md"); - modalDialog.classList.add("modal-lg"); + a.Update({ ID: a.id, Size: "lg" }); } else if (modalDialog.classList.contains('modal-lg')) { - modalDialog.classList.remove("modal-lg"); - modalDialog.classList.add("modal-xl"); + a.Update({ ID: a.id, Size: "xl" }); } else if (modalDialog.classList.contains('modal-xl')) { - modalDialog.classList.remove("modal-xl"); - modalDialog.classList.add("modal-sm"); + a.Update({ ID: a.id, Size: "sm" }); } else { - modalDialog.classList.remove("modal-sm"); - modalDialog.classList.remove("modal-md"); - modalDialog.classList.remove("modal-lg"); - modalDialog.classList.remove("modal-xl"); - modalDialog.classList.add("modal-md"); + a.Update({ ID: a.id, Size: "md" }); } }, // - // deprecated/legacy -support - // DefaultShowOptions: this.Default().ShowOptions, - // DefaultToastOptions: this.Default().ToastOptions, - // DefaultPromptOptions: this.Default().PromptOptions, + // deprecated/legacy-support Create: async function (id, title, url, size) { await this.Show({ ID: id,