Compare commits
6 Commits
4d39ae903c
...
03f0ce6045
Author | SHA1 | Date | |
---|---|---|---|
03f0ce6045 | |||
|
a5335beab9 | ||
|
4b85077735 | ||
|
36d99fdbc1 | ||
|
d9b41dab54 | ||
|
102a3d1c01 |
268
bs4-test.html
268
bs4-test.html
@ -16,89 +16,231 @@
|
||||
<script src="bsdialog4.js"></script>
|
||||
<title></title>
|
||||
|
||||
<style>
|
||||
|
||||
.text-sm {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
</head>
|
||||
<body class="py-5">
|
||||
|
||||
<div class="container">
|
||||
<div class="row mb-3 border-bottom">
|
||||
<div class="col-12">
|
||||
|
||||
<p><b>Example One</b></p>
|
||||
<div class="row mb-3">
|
||||
<div class="col-6 border-right">
|
||||
|
||||
<div class="pb-3 mb-3 border-bottom">
|
||||
<p><b>Example. Simple Text Modal</b></p>
|
||||
<p>Launch an empty modal</p>
|
||||
<div class="alert alert-secondary">BSDialog.Create('abc123', 'My Modal Box 123', null, 'xl');</div>
|
||||
<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(){
|
||||
|
||||
$("#buttonL1").on('click', function(){
|
||||
BSDialog.Show({
|
||||
ID: "modalL1",
|
||||
Title: "Modal Title",
|
||||
Message: "Hello Momo!",
|
||||
URL: null,
|
||||
Size: "md",
|
||||
Colour: "secondary"
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
<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 class="col-6">
|
||||
|
||||
<div class="pb-3 mb-3 border-bottom">
|
||||
<p><b>Example. Simple Text Modal</b> <span class="badge badge-warning">Deprecated</span></p>
|
||||
<p>Launch an empty modal</p>
|
||||
<div class="alert alert-secondary text-sm">
|
||||
<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>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3 border-bottom">
|
||||
<div class="col-12">
|
||||
|
||||
<p><b>Example Two</b></p>
|
||||
<p>Launch a modal with text</p>
|
||||
<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.ShowToast('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>
|
||||
<p><button id="button3" 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 Four</b></p>
|
||||
<p>Launch a multiple modals</p>
|
||||
<div class="alert alert-secondary">
|
||||
BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');<br />
|
||||
BSDialog.ShowToast('abc123456', 'My Modal Box 123.567', 'Help! I\'m a second toast.', 'md');<br />
|
||||
</div>
|
||||
<p><button id="button4" type="button" class="btn btn-primary">Launch Modal</button></p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
$("#button1").on('click', function(){
|
||||
BSDialog.Create('abc123', 'My Modal Box 123', null, 'xl');
|
||||
BSDialog.Create('abc123', 'My Modal Box 123', 'Hello momo!', 'xl');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div class="pb-3 mb-3 border-bottom">
|
||||
<p><b>Example. Empty Modal and Updates.</b> <span class="badge badge-warning">Deprecated</span></p>
|
||||
<p>Launch an empty modal then update its title, body, footer and size.</p>
|
||||
<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(){
|
||||
|
||||
$("#button2").on('click', function(){
|
||||
BSDialog.Create('abc123', 'My Modal Box 123', 'Hello momo!', 'lg');
|
||||
});
|
||||
|
||||
$("#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', '');
|
||||
BSDialog.UpdateSize('abc123', 'lg');
|
||||
});
|
||||
|
||||
$("#button4").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');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="pb-3 mb-3 border-bottom">
|
||||
<p><b>Example. Toast Modal.</b> <span class="badge badge-warning">Deprecated</span></p>
|
||||
<p>Show a toast-style modal</p>
|
||||
<div class="alert alert-secondary text-sm">
|
||||
<pre>
|
||||
BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');
|
||||
</pre>
|
||||
</div>
|
||||
<p><button id="button6" type="button" class="btn btn-primary">Launch Modal</button></p>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
$("#button6").on('click', function(){
|
||||
BSDialog.ShowToast('abc123', 'My Modal Box 123', 'Help! I\'m toast.', 'sm');
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
151
bsdialog4.js
151
bsdialog4.js
@ -1,25 +1,17 @@
|
||||
/**
|
||||
* BSDialog4
|
||||
* @version v0.1.1.026 (2023/08/19 12:58)
|
||||
* @version v0.1.2.046 (2023/08/20 00:39)
|
||||
*/
|
||||
var BSDialog = {
|
||||
Create: async function (id, title, url, size) {
|
||||
var a = this;
|
||||
|
||||
a.id = id;
|
||||
a.pfx = "bsdia4_";
|
||||
a.body = document.getElementsByTagName("body")[0];
|
||||
|
||||
a.addBackdrop();
|
||||
a.addModal(id, title, size);
|
||||
|
||||
if (a.isNullOrWhitespace(url)) {
|
||||
a.UpdateBody(id, "");
|
||||
} else if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/")) {
|
||||
a.UpdateBodyRemote(id, url);
|
||||
} else {
|
||||
await a.UpdateBody(id, url);
|
||||
}
|
||||
await this.Show({
|
||||
ID: id,
|
||||
Title: title,
|
||||
Message: url,
|
||||
URL: url,
|
||||
Size: size,
|
||||
Colour: "secondary"
|
||||
});
|
||||
},
|
||||
Clear: function () {
|
||||
this.body.querySelectorAll(".modal").forEach(function(e) {
|
||||
@ -132,9 +124,122 @@ var BSDialog = {
|
||||
Modal: modal
|
||||
};
|
||||
},
|
||||
Show: async function (options) {
|
||||
const a = this;
|
||||
const _options = Object.assign(a.DefaultShowOptions, options);
|
||||
|
||||
a.id = _options.ID;
|
||||
a.pfx = "bsdia4_";
|
||||
a.body = document.getElementsByTagName("body")[0];
|
||||
|
||||
a.addBackdrop();
|
||||
a.addModal(_options.ID, _options.Title, _options.Size, true, _options.Colour);
|
||||
|
||||
if (_options.URL == null) {
|
||||
await a.UpdateBody(_options.ID, _options.Message);
|
||||
} else {
|
||||
if (a.isNullOrWhitespace(_options.URL)) {
|
||||
await a.UpdateBody(_options.ID, _options.URL);
|
||||
} else {
|
||||
if (_options.URL.startsWith("http://") || _options.URL.startsWith("https://") || _options.URL.startsWith("/")) {
|
||||
await a.UpdateBodyRemote(_options.ID, _options.URL);
|
||||
} else {
|
||||
await a.UpdateBody(_options.ID, _options.URL);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Toast: async function (options) {
|
||||
const a = this;
|
||||
const _options = Object.assign(a.DefaultToastOptions, options);
|
||||
|
||||
await this.Show({
|
||||
ID: _options.ID,
|
||||
Title: _options.Title,
|
||||
Message: _options.Message,
|
||||
URL: null,
|
||||
Size: _options.Size,
|
||||
Colour: "secondary",
|
||||
ShowFooter: false
|
||||
});
|
||||
},
|
||||
Prompt: async function (options) {
|
||||
const a = this;
|
||||
let id = "prompt" + Math.floor(Math.random() * 10000) + 1000;
|
||||
|
||||
const _options = Object.assign(a.DefaultPromptOptions, options);
|
||||
|
||||
return await new Promise((resolve, reject) => {
|
||||
|
||||
a.Create(id, _options.Title, _options.Message, _options.Size);
|
||||
|
||||
let html = '';
|
||||
_options.Buttons.forEach(function(e) {
|
||||
html += '<button type="button" class="btn btn-' + e.Colour + '" data-prompt-value="' + e.Value + '">' + e.Label + '</button>';
|
||||
});
|
||||
|
||||
a.UpdateFooter(id, html);
|
||||
|
||||
const modal = a.Find(id);
|
||||
|
||||
modal.Footer[0].querySelectorAll("button").forEach(function(button) {
|
||||
button.addEventListener("click", function(e){
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
const value = button.getAttribute("data-prompt-value");
|
||||
|
||||
a.Close(id);
|
||||
|
||||
resolve(value);
|
||||
});
|
||||
});
|
||||
|
||||
modal.Close.forEach(function(sender) {
|
||||
sender.addEventListener("click", function(e){
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
a.Close(id);
|
||||
|
||||
resolve("");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
DefaultShowOptions: {
|
||||
ID: null,
|
||||
Title: "",
|
||||
Message: "",
|
||||
URL: null,
|
||||
Size: "md",
|
||||
Colour: "secondary",
|
||||
ShowFooter: true
|
||||
},
|
||||
DefaultToastOptions: {
|
||||
ID: null,
|
||||
Title: "",
|
||||
Message: "",
|
||||
Size: "md"
|
||||
},
|
||||
DefaultPromptOptions: {
|
||||
Title: "",
|
||||
Message: "",
|
||||
Size: "md",
|
||||
Buttons: [
|
||||
{ Label: "Yes", Value: "Yes", Colour: "primary" },
|
||||
{ Label: "No", Value: "No", Colour: "secondary" },
|
||||
{ Label: "Cancel", Value: "Cancel", Colour: "secondary" }
|
||||
]
|
||||
},
|
||||
ShowToast: function (id, title, message, size) {
|
||||
this.Create(id, title, null, size);
|
||||
this.UpdateBody(id, message);
|
||||
this.Toast({
|
||||
ID: id,
|
||||
Title: title,
|
||||
Message: message,
|
||||
Size: size
|
||||
});
|
||||
},
|
||||
addBackdrop: function () {
|
||||
let a = this;
|
||||
@ -159,7 +264,7 @@ var BSDialog = {
|
||||
a.Clear();
|
||||
});
|
||||
},
|
||||
addModal: function (id, title, size) {
|
||||
addModal: function (id, title, size, showFooter, closeColour) {
|
||||
var a = this;
|
||||
|
||||
// don't allow duplicates
|
||||
@ -189,9 +294,13 @@ var BSDialog = {
|
||||
html += '</div>';
|
||||
|
||||
html += ' </div>';
|
||||
|
||||
if (showFooter === true) {
|
||||
html += ' <div class="modal-footer">';
|
||||
html += ' <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>';
|
||||
html += ' <button type="button" class="btn btn-' + closeColour + '" data-dismiss="modal">Close</button>';
|
||||
html += ' </div>';
|
||||
}
|
||||
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
|
4
bsdialog4.min.js
vendored
4
bsdialog4.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user