Deprecated toast

Added Show and Prompt methods
Added modern options arguments for methods
This commit is contained in:
Ray 2023-08-21 18:51:13 +01:00
parent 4b85077735
commit a5335beab9
3 changed files with 234 additions and 139 deletions

View File

@ -16,141 +16,231 @@
<script src="bsdialog4.js"></script> <script src="bsdialog4.js"></script>
<title></title> <title></title>
<style>
.text-sm {
font-size: 0.8em;
}
</style>
</head> </head>
<body class="py-5"> <body class="py-5">
<div class="container"> <div class="container">
<div class="row mb-3 border-bottom"> <div class="row mb-3">
<div class="col-12"> <div class="col-6 border-right">
<p><b>Example One</b></p> <div class="pb-3 mb-3 border-bottom">
<p>Launch an empty modal</p> <p><b>Example. Simple Text Modal</b></p>
<div class="alert alert-secondary">BSDialog.Create('abc123', 'My Modal Box 123', null, 'xl');</div> <p>Launch an empty modal</p>
<p><button id="button1" type="button" class="btn btn-primary">Launch Modal</button></p> <div class="alert alert-secondary text-sm">
<pre>
BSDialog.Show({
ID: "modalL1",
Title: "Modal Title",
Message: "Hello Momo!",
URL: null,
Size: "md",
Colour: "secondary"
});
</pre>
</div>
<p><button id="buttonL1" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
</div> $("#buttonL1").on('click', function(){
</div> BSDialog.Show({
<div class="row mb-3 border-bottom"> ID: "modalL1",
<div class="col-12"> Title: "Modal Title",
Message: "Hello Momo!",
URL: null,
Size: "md",
Colour: "secondary"
});
});
<p><b>Example Two</b></p> });
<p>Launch a modal with text</p> </script>
<div class="alert alert-secondary">BSDialog.Create('abc123', 'My Modal Box 123', 'Hello momo!', 'lg');</div>
<p><button id="button2" type="button" class="btn btn-primary">Launch Modal</button></p>
</div>
</div>
<div class="row mb-3 border-bottom">
<div class="col-12">
<p><b>Example Three</b></p>
<p>Launch an empty modal then update its title, body, footer and size.</p>
<div class="alert alert-secondary">
BSDialog.Create('abc123', 'My Modal Box 123', null, 'sm');<br />
BSDialog.UpdateTitle('abc123', 'My Modal Box 567');<br />
BSDialog.UpdateBody('abc123', 'Help, I\'m toast!');<br />
BSDialog.UpdateFooter('abc123', '');<br />
BSDialog.UpdateSize('abc123', 'lg');<br />
</div> </div>
<p><button id="button3" type="button" class="btn btn-primary">Launch Modal</button></p>
<div class="pb-3 mb-3 border-bottom">
<p><b>Example. Prompt Modal</b></p>
<p>Launch a prompt modal and wait for a response</p>
<div class="alert alert-secondary text-sm">
<pre>
let response = await BSDialog.Prompt({
Title: "Modal Title",
Message: "Are you sure want to wait for a response?",
Size: "md",
Buttons: [
{ Label: "Yes", Value: "Yes", Colour: "primary" },
{ Label: "No", Value: "No", Colour: "secondary" },
{ Label: "Cancel", Value: "Cancel", Colour: "secondary" }
]
});
alert(response);
</pre>
</div>
<p><button id="buttonL2" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonL2").on('click', async function(){
let response = await BSDialog.Prompt({
Title: "Modal Title",
Message: "Are you sure want to wait for a response?",
Size: "md",
Buttons: [
{ Label: "Yes", Value: "Yes", Colour: "primary" },
{ Label: "No", Value: "No", Colour: "secondary" },
{ Label: "Cancel", Value: "Cancel", Colour: "secondary" }
]
});
alert(response);
});
});
</script>
</div>
<div class="pb-3 mb-3 border-bottom">
<p><b>Example. Multiple Modals</b></p>
<p>Launch multiple modals</p>
<div class="alert alert-secondary text-sm">
<pre>
BSDialog.Show({
ID: "modalL3a",
Title: "Modal A Title",
Message: "First!",
URL: null,
Size: "md",
Colour: "secondary"
});
BSDialog.Show({
ID: "modalL3b",
Title: "Modal B Title",
Message: "Second!",
URL: null,
Size: "md",
Colour: "secondary"
});
</pre>
</div>
<p><button id="buttonL3" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonL3").on('click', function(){
BSDialog.Show({
ID: "modalL3a",
Title: "Modal A Title",
Message: "First!",
URL: null,
Size: "md",
Colour: "secondary"
});
BSDialog.Show({
ID: "modalL3b",
Title: "Modal B Title",
Message: "Second!",
URL: null,
Size: "md",
Colour: "secondary"
});
});
});
</script>
</div>
</div> </div>
</div> <div class="col-6">
<div class="row mb-3 border-bottom">
<div class="col-12">
<p><b>Example Four</b></p> <div class="pb-3 mb-3 border-bottom">
<p>Launch a multiple modals</p> <p><b>Example. Simple Text Modal</b> <span class="badge badge-warning">Deprecated</span></p>
<div class="alert alert-secondary"> <p>Launch an empty modal</p>
BSDialog.Create('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');<br /> <div class="alert alert-secondary text-sm">
BSDialog.Create('abc123456', 'My Modal Box 123.567', 'Help! I\'m a second toast.', 'md');<br /> <pre>
BSDialog.Create('abc123', 'My Modal Box 123', 'Hello momo!', 'xl');
</pre>
</div>
<p><button id="button1" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#button1").on('click', function(){
BSDialog.Create('abc123', 'My Modal Box 123', 'Hello momo!', 'xl');
});
});
</script>
</div> </div>
<p><button id="button4" type="button" class="btn btn-primary">Launch Modal</button></p>
</div> <div class="pb-3 mb-3 border-bottom">
</div> <p><b>Example. Empty Modal and Updates.</b> <span class="badge badge-warning">Deprecated</span></p>
<div class="row mb-3 border-bottom"> <p>Launch an empty modal then update its title, body, footer and size.</p>
<div class="col-12"> <div class="alert alert-secondary text-sm">
<pre>
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', '');
BSDialog.UpdateSize('abc123', 'lg');
</pre>
</div>
<p><button id="button3" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
<p><b>Example Six</b></p> $("#button2").on('click', function(){
<p>Show a toast-style modal</p> BSDialog.Create('abc123', 'My Modal Box 123', null, 'sm');
<div class="alert alert-secondary"> BSDialog.UpdateTitle('abc123', 'My Modal Box 567');
BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');<br /> BSDialog.UpdateBody('abc123', 'Help, I\'m toast!');
BSDialog.UpdateFooter('abc123', '');
BSDialog.UpdateSize('abc123', 'lg');
});
});
</script>
</div> </div>
<p><button id="button6" type="button" class="btn btn-primary">Launch Modal</button></p>
</div>
</div>
<div class="row mb-3 border-bottom">
<div class="col-12">
<p><b>Example Five</b></p> <div class="pb-3 mb-3 border-bottom">
<p>Launch a prompt modal</p> <p><b>Example. Toast Modal.</b> <span class="badge badge-warning">Deprecated</span></p>
<div class="alert alert-secondary"> <p>Show a toast-style modal</p>
let result = await BSDialog.Prompt({<br /> <div class="alert alert-secondary text-sm">
&nbsp;&nbsp;&nbsp;&nbsp;Title: "Prompt",<br /> <pre>
&nbsp;&nbsp;&nbsp;&nbsp;Message: "This is a prompt",<br /> BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');
&nbsp;&nbsp;&nbsp;&nbsp;Size: "md",<br /> </pre>
&nbsp;&nbsp;&nbsp;&nbsp;Buttons: [<br /> </div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ Label: "Yes", Value: "Yes", Colour: "primary" },<br /> <p><button id="button6" type="button" class="btn btn-primary">Launch Modal</button></p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ Label: "No", Value: "No", Colour: "secondary" },<br /> <script>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ Label: "Cancel", Value: "Cancel", Colour: "secondary" }<br /> $(document).ready(function(){
&nbsp;&nbsp;&nbsp;&nbsp;]<br />
});<br /> $("#button6").on('click', function(){
<br /> BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');
alert(result);<br /> });
});
</script>
</div> </div>
<p><button id="button5" type="button" class="btn btn-primary">Launch Modal</button></p>
</div> </div>
</div> </div>
</div> </div>
<script>
$(document).ready(function(){
$("#button1").on('click', function(){
BSDialog.Create('abc123', 'My Modal Box 123', null, 'xl');
});
$("#button2").on('click', function(){
BSDialog.Create('abc123', 'My Modal Box 123', 'Hello momo!', 'lg');
});
$("#button3").on('click', function(){
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', '');
BSDialog.UpdateSize('abc123', 'lg');
});
$("#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');
});
$("#button5").on('click', async function(){
let result = await BSDialog.Prompt({
Title: "Prompt",
Message: "This is a prompt",
Size: "md",
PromptType: "YesNoCancel"
});
alert(result);
});
});
</script>
</body> </body>
</html> </html>

View File

@ -1,6 +1,6 @@
/** /**
* BSDialog4 * BSDialog4
* @version v0.1.2.043 (2023/08/20 00:39) * @version v0.1.2.046 (2023/08/20 00:39)
*/ */
var BSDialog = { var BSDialog = {
Create: async function (id, title, url, size) { Create: async function (id, title, url, size) {
@ -133,7 +133,7 @@ var BSDialog = {
a.body = document.getElementsByTagName("body")[0]; a.body = document.getElementsByTagName("body")[0];
a.addBackdrop(); a.addBackdrop();
a.addModal(_options.ID, _options.Title, _options.Size, _options.Colour); a.addModal(_options.ID, _options.Title, _options.Size, true, _options.Colour);
if (_options.URL == null) { if (_options.URL == null) {
await a.UpdateBody(_options.ID, _options.Message); await a.UpdateBody(_options.ID, _options.Message);
@ -149,26 +149,18 @@ var BSDialog = {
} }
} }
}, },
Toast: function (options) { Toast: async function (options) {
const a = this; const a = this;
const _options = Object.assign(a.DefaultToastOptions, options); const _options = Object.assign(a.DefaultToastOptions, options);
a.Create(_options.ID, _options.Title, null, _options.Size); await this.Show({
a.UpdateBody(_options.ID, _options.Message); ID: _options.ID,
Title: _options.Title,
const modal = a.Find(_options.ID); Message: _options.Message,
URL: null,
modal.Footer.forEach(function(e) { Size: _options.Size,
e.parentNode.removeChild(e); Colour: "secondary",
}); ShowFooter: false
},
ShowToast: function (id, title, message, size) {
this.Toast({
ID: id,
Title: title,
Message: message,
Size: size
}); });
}, },
Prompt: async function (options) { Prompt: async function (options) {
@ -222,7 +214,8 @@ var BSDialog = {
Message: "", Message: "",
URL: null, URL: null,
Size: "md", Size: "md",
Colour: "secondary" Colour: "secondary",
ShowFooter: true
}, },
DefaultToastOptions: { DefaultToastOptions: {
ID: null, ID: null,
@ -240,6 +233,14 @@ var BSDialog = {
{ Label: "Cancel", Value: "Cancel", Colour: "secondary" } { Label: "Cancel", Value: "Cancel", Colour: "secondary" }
] ]
}, },
ShowToast: function (id, title, message, size) {
this.Toast({
ID: id,
Title: title,
Message: message,
Size: size
});
},
addBackdrop: function () { addBackdrop: function () {
let a = this; let a = this;
@ -263,7 +264,7 @@ var BSDialog = {
a.Clear(); a.Clear();
}); });
}, },
addModal: function (id, title, size, closeColour) { addModal: function (id, title, size, showFooter, closeColour) {
var a = this; var a = this;
// don't allow duplicates // don't allow duplicates
@ -293,9 +294,13 @@ var BSDialog = {
html += '</div>'; html += '</div>';
html += ' </div>'; html += ' </div>';
html += ' <div class="modal-footer">';
html += ' <button type="button" class="btn btn-' + closeColour + '" data-dismiss="modal">Close</button>'; if (showFooter === true) {
html += ' </div>'; html += ' <div class="modal-footer">';
html += ' <button type="button" class="btn btn-' + closeColour + '" data-dismiss="modal">Close</button>';
html += ' </div>';
}
html += ' </div>'; html += ' </div>';
html += ' </div>'; html += ' </div>';
html += '</div>'; html += '</div>';

4
bsdialog4.min.js vendored

File diff suppressed because one or more lines are too long