Added options argument methods for Show, Toast and Prompt
This commit is contained in:
parent
d9b41dab54
commit
36d99fdbc1
@ -88,7 +88,7 @@
|
||||
<p><b>Example Five</b></p>
|
||||
<p>Launch a prompt modal</p>
|
||||
<div class="alert alert-secondary">
|
||||
let result = await BSDialog.ShowPrompt({<br />
|
||||
let result = await BSDialog.Prompt({<br />
|
||||
Title: "Prompt",<br />
|
||||
Message: "This is a prompt",<br />
|
||||
Size: "md",<br />
|
||||
@ -138,7 +138,7 @@ $(document).ready(function(){
|
||||
});
|
||||
|
||||
$("#button5").on('click', async function(){
|
||||
let result = await BSDialog.ShowPrompt({
|
||||
let result = await BSDialog.Prompt({
|
||||
Title: "Prompt",
|
||||
Message: "This is a prompt",
|
||||
Size: "md",
|
||||
|
83
bsdialog4.js
83
bsdialog4.js
@ -4,22 +4,14 @@
|
||||
*/
|
||||
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,19 +124,54 @@ var BSDialog = {
|
||||
Modal: modal
|
||||
};
|
||||
},
|
||||
ShowToast: function (id, title, message, size) {
|
||||
Show: async function (options) {
|
||||
const a = this;
|
||||
const _options = Object.assign(a.DefaultShowOptions, options);
|
||||
|
||||
a.Create(id, title, null, size);
|
||||
a.UpdateBody(id, message);
|
||||
a.id = _options.ID;
|
||||
a.pfx = "bsdia4_";
|
||||
a.body = document.getElementsByTagName("body")[0];
|
||||
|
||||
const modal = a.Find(id);
|
||||
a.addBackdrop();
|
||||
a.addModal(_options.ID, _options.Title, _options.Size);
|
||||
|
||||
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: function (options) {
|
||||
const a = this;
|
||||
const _options = Object.assign(a.DefaultToastOptions, options);
|
||||
|
||||
a.Create(_options.ID, _options.Title, null, _options.Size);
|
||||
a.UpdateBody(_options.ID, _options.Message);
|
||||
|
||||
const modal = a.Find(_options.ID);
|
||||
|
||||
modal.Footer.forEach(function(e) {
|
||||
e.parentNode.removeChild(e);
|
||||
});
|
||||
|
||||
},
|
||||
ShowPrompt: async function (options) {
|
||||
ShowToast: function (id, title, message, size) {
|
||||
this.Toast({
|
||||
ID: id,
|
||||
Title: title,
|
||||
Message: message,
|
||||
Size: size
|
||||
});
|
||||
},
|
||||
Prompt: async function (options) {
|
||||
const a = this;
|
||||
let id = "prompt" + Math.floor(Math.random() * 10000) + 1000;
|
||||
|
||||
@ -189,6 +216,20 @@ var BSDialog = {
|
||||
|
||||
});
|
||||
},
|
||||
DefaultShowOptions: {
|
||||
ID: null,
|
||||
Title: "",
|
||||
Message: "",
|
||||
URL: null,
|
||||
Size: "md",
|
||||
Colour: "secondary"
|
||||
},
|
||||
DefaultToastOptions: {
|
||||
ID: null,
|
||||
Title: "",
|
||||
Message: "",
|
||||
Size: "md"
|
||||
},
|
||||
DefaultPromptOptions: {
|
||||
Title: "",
|
||||
Message: "",
|
||||
|
1
bsdialog4.min.js
vendored
1
bsdialog4.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user