From d9b41dab542a6a58d5896d7ae87dd2c79c2aaac3 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 21 Aug 2023 01:52:54 +0100 Subject: [PATCH] Changed toast to remove footer --- bs4-test.html | 26 +++++++++++++++++++++----- bsdialog4.js | 14 +++++++++++--- bsdialog4.min.js | 1 - 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/bs4-test.html b/bs4-test.html index e12af9e..b30b4d9 100644 --- a/bs4-test.html +++ b/bs4-test.html @@ -47,7 +47,7 @@

Example Three

Launch an empty modal then update its title, body, footer and size.

- BSDialog.ShowToast('abc123', 'My Modal Box 123', null, 'sm');
+ BSDialog.Create('abc123', 'My Modal Box 123', null, 'sm');
BSDialog.UpdateTitle('abc123', 'My Modal Box 567');
BSDialog.UpdateBody('abc123', 'Help, I\'m toast!');
BSDialog.UpdateFooter('abc123', '');
@@ -63,13 +63,25 @@

Example Four

Launch a multiple modals

- BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');
- BSDialog.ShowToast('abc123456', 'My Modal Box 123.567', 'Help! I\'m a second toast.', 'md');
+ BSDialog.Create('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');
+ BSDialog.Create('abc123456', 'My Modal Box 123.567', 'Help! I\'m a second toast.', 'md');

+
+
+ +

Example Six

+

Show a toast-style modal

+
+ BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');
+
+

+ +
+
@@ -109,7 +121,7 @@ $(document).ready(function(){ }); $("#button3").on('click', function(){ - BSDialog.ShowToast('abc123', 'My Modal Box 123', null, 'sm'); + BSDialog.Create('abc123', 'My Modal Box 123', null, 'sm'); BSDialog.UpdateTitle('abc123', 'My Modal Box 567'); BSDialog.UpdateBody('abc123', 'Help, I\'m toast!'); BSDialog.UpdateFooter('abc123', ''); @@ -117,8 +129,12 @@ $(document).ready(function(){ }); $("#button4").on('click', function(){ + BSDialog.Create('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm'); + BSDialog.Create('abc123456', 'My Modal Box 123.567', 'Help! I\'m a second toast.', 'md'); + }); + + $("#button6").on('click', function(){ BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm'); - BSDialog.ShowToast('abc123456', 'My Modal Box 123.567', 'Help! I\'m a second toast.', 'md'); }); $("#button5").on('click', async function(){ diff --git a/bsdialog4.js b/bsdialog4.js index a9ac23f..f699c6a 100644 --- a/bsdialog4.js +++ b/bsdialog4.js @@ -133,11 +133,19 @@ var BSDialog = { }; }, ShowToast: function (id, title, message, size) { - this.Create(id, title, null, size); - this.UpdateBody(id, message); + const a = this; + + a.Create(id, title, null, size); + a.UpdateBody(id, message); + + const modal = a.Find(id); + + modal.Footer.forEach(function(e) { + e.parentNode.removeChild(e); + }); }, ShowPrompt: async function (options) { - let a = this; + const a = this; let id = "prompt" + Math.floor(Math.random() * 10000) + 1000; const _options = Object.assign(a.DefaultPromptOptions, options); diff --git a/bsdialog4.min.js b/bsdialog4.min.js index 51ac911..eddb451 100644 --- a/bsdialog4.min.js +++ b/bsdialog4.min.js @@ -2,4 +2,3 @@ * BSDialog4 * @version v0.1.2.043 (2023/08/20 00:39) */ -var BSDialog={Create:async function(t,e,o,l){var a=this;a.id=t,a.pfx="bsdia4_",a.body=document.getElementsByTagName("body")[0],a.addBackdrop(),a.addModal(t,e,l),a.isNullOrWhitespace(o)?a.UpdateBody(t,""):o.startsWith("http://")||o.startsWith("https://")||o.startsWith("/")?a.UpdateBodyRemote(t,o):await a.UpdateBody(t,o)},Clear:function(){this.body.querySelectorAll(".modal").forEach((function(t){t.parentNode.removeChild(t)})),this.removeBackdrop()},Close:function(t){let e=this.Find(t);null!==e&&(e.Modal.forEach((function(t){t.parentNode.removeChild(t)})),e=this.Find(t),null===e&&this.removeBackdrop())},UpdateTitle:function(t,e){let o=this.Find(t);null!==o&&o.Title.forEach((function(t){t.innerHTML=e}))},UpdateSize:function(t,e){let o=this.Find(t);null!==o&&o.Modal.forEach((function(t){let o=t.querySelectorAll(".modal-dialog")[0];o.classList.remove("modal-sm"),o.classList.remove("modal-md"),o.classList.remove("modal-lg"),o.classList.remove("modal-xl"),o.classList.add("modal-"+e)}))},UpdateBody:function(t,e){var o=this;let l=o.Find(t);null!==l&&l.Body.forEach((function(t){o.html(t,e)}))},UpdateBodyRemote:async function(t,e){var o=this;o.Exists(t)&&await fetch(e,{cache:"no-cache",credentials:"same-origin"}).then((t=>t.text())).then((e=>{o.UpdateBody(t,e)})).catch((e=>{o.UpdateBody(t,"Error: "+e)}))},UpdateFooter:function(t,e){var o=this;let l=o.Find(t);null!==l&&l.Footer.forEach((function(t){o.html(t,e)}))},Exists:function(t){return null!==this.Find(t)},Find:function(t){let e=this.body.querySelectorAll("#"+this.pfx+t+".modal");return e?e.length<=0?null:{Title:e[0].querySelectorAll(".modal-title"),Body:e[0].querySelectorAll(".modal-body"),Footer:e[0].querySelectorAll(".modal-footer"),Close:e[0].querySelectorAll("[data-dismiss='modal']"),Modal:e}:null},ShowToast:function(t,e,o,l){this.Create(t,e,null,l),this.UpdateBody(t,o)},ShowPrompt:async function(t){let e=this,o="prompt"+Math.floor(1e4*Math.random())+1e3;const l=Object.assign(e.DefaultPromptOptions,t);return await new Promise(((t,a)=>{e.Create(o,l.Title,l.Message,l.Size);let s="";l.Buttons.forEach((function(t){s+='"})),e.UpdateFooter(o,s);const d=e.Find(o);d.Footer[0].querySelectorAll("button").forEach((function(l){l.addEventListener("click",(function(a){a.stopPropagation(),a.preventDefault();const s=l.getAttribute("data-prompt-value");e.Close(o),t(s)}))})),d.Close.forEach((function(l){l.addEventListener("click",(function(l){l.stopPropagation(),l.preventDefault(),e.Close(o),t("")}))}))}))},DefaultPromptOptions:{Title:"",Message:"",Size:"md",Buttons:[{Label:"Yes",Value:"Yes",Colour:"primary"},{Label:"No",Value:"No",Colour:"secondary"},{Label:"Cancel",Value:"Cancel",Colour:"secondary"}]},addBackdrop:function(){let t=this;t.body.querySelectorAll(".modal-backdrop").length>0||(t.appendHtml(t.body,''),t.body.classList.add("modal-open"),t.body.style.overflow="hidden",t.body.querySelectorAll(".modal-backdrop")[0].addEventListener("click",(function(e){e.stopPropagation(),e.preventDefault(),t.Clear()})))},addModal:function(t,e,o){var l=this;let a=l.Find(t);if(null!==a)return;let s="";s+='",l.appendHtml(l.body,s),a=l.Find(t),null!==a&&a.Close.forEach((function(e){e.addEventListener("click",(function(e){e.stopPropagation(),e.preventDefault(),l.Close(t)})),e.addEventListener("auxclick",(function(t){t.stopPropagation(),t.preventDefault(),1===t.button&&l.toggleSize()}))}))},appendHtml:function(t,e){let o=document.createElement("template");o.innerHTML=e,o=o.content.firstChild,t.appendChild(o)},html:function(t,e){jQuery?jQuery(t).html(e):t.innerHTML=e},isNullOrWhitespace:function(t){return void 0===t||(null==t||(0==t||t.trim().length<=0))},removeBackdrop:function(){if(this.body.querySelectorAll(".modal-backdrop").length<=0)return;if(this.body.querySelectorAll(".modal").length>0)return;let t=this.body.querySelectorAll(".modal-backdrop")[0];t.parentNode.removeChild(t),this.body.classList.remove("modal-open"),this.body.style.overflow=null},toggleSize:function(){let t=this.Find(this.id);if(null===t)return;let e=t.Modal[0].querySelectorAll(".modal-dialog")[0];e.classList.contains("modal-sm")?(e.classList.remove("modal-sm"),e.classList.add("modal-md")):e.classList.contains("modal-md")?(e.classList.remove("modal-md"),e.classList.add("modal-lg")):e.classList.contains("modal-lg")?(e.classList.remove("modal-lg"),e.classList.add("modal-xl")):e.classList.contains("modal-xl")?(e.classList.remove("modal-xl"),e.classList.add("modal-sm")):(e.classList.remove("modal-sm"),e.classList.remove("modal-md"),e.classList.remove("modal-lg"),e.classList.remove("modal-xl"),e.classList.add("modal-md"))}}; \ No newline at end of file