release/0.1.3.017 #5

Merged
Ray merged 4 commits from release/0.1.3.017 into master 2023-09-06 22:30:46 +00:00
3 changed files with 58 additions and 37 deletions
Showing only changes of commit d7f4f60e4d - Show all commits

View File

@ -215,8 +215,13 @@ let response = await BSDialog.Prompt({
Title: "Modal Title",
Message: "Are you sure want to wait for a response?",
Size: "md",
Label: "Response Text",
Placeholder: "Response Text"
Textbox: {
Label: "Textbox Label",
LabelSize: 4,
Placeholder: "Placeholder",
Value: "Default Value",
BoxSize: 8
}
});
alert(response);
@ -232,8 +237,13 @@ alert(response);
Title: "Modal Title",
Message: "Are you sure want to wait for a response?",
Size: "md",
Label: "Response Text",
Placeholder: "Response Text"
Textbox: {
Label: "Textbox Label",
LabelSize: 4,
Placeholder: "Placeholder",
Value: "Default Value",
BoxSize: 8
}
});
alert(response);

View File

@ -15,15 +15,17 @@ var BSDialog = {
a.addModal(_options.ID, _options.Title, _options.Size, true, _options.Colour);
if (_options.URL == null) {
await a.UpdateBody(_options.ID, _options.Message);
await a.Update({ ID: _options.ID, Body: _options.Message });
} else {
if (a.isNullOrWhitespace(_options.URL)) {
await a.UpdateBody(_options.ID, _options.URL);
await a.Update({ ID: _options.ID, Body: _options.URL });
} else {
if (_options.URL.startsWith("http://") || _options.URL.startsWith("https://") || _options.URL.startsWith("/")) {
await a.UpdateBodyRemote(_options.ID, _options.URL);
let response = await a.retrieveURL(_options.URL);
await a.Update({ ID: _options.ID, Body: response });
} else {
await a.UpdateBody(_options.ID, _options.URL);
await a.Update({ ID: _options.ID, Body: _options.URL });
}
}
}
@ -96,7 +98,9 @@ var BSDialog = {
}
if (!this.isNullOrWhitespace(_options.BodyURL)) {
await a.UpdateBodyRemote(_options.ID, _options.BodyURL);
let response = await a.retrieveURL(_options.BodyURL);
await a.Update({ ID: _options.ID, Body: response });
}
if (!this.isNullOrWhitespace(_options.Footer)) {
@ -122,27 +126,13 @@ var BSDialog = {
});
}
},
UpdateBodyRemote: async function (id, url) {
var a = this;
if (!a.Exists(id)) {
return;
}
await fetch(url, {
cache: 'no-cache',
credentials: 'same-origin'
}).then(data => data.text()).then(data => {
a.UpdateBody(id, data);
}).catch((error) => {
a.UpdateBody(id, "Error: " + error);
});
},
Exists: function (id) {
return (this.Find(id) !== null);
},
Find: function (id) {
let modal = this.body.querySelectorAll("#" + this.pfx + id + ".modal");
const a = this;
const modal = a.body.querySelectorAll("#" + a.pfx + id + ".modal");
if (!modal) {
return null;
}
@ -180,8 +170,13 @@ var BSDialog = {
{ Label: "No", Value: "No", Colour: "secondary" },
{ Label: "Cancel", Value: "Cancel", Colour: "secondary" }
],
Textbox: {
Label: "",
Placeholder: ""
LabelSize: 4,
Placeholder: "",
Value: "",
BoxSize: 8
}
},
ToastOptions: {
ID: null,
@ -293,17 +288,21 @@ var BSDialog = {
const a = this;
return await new Promise(async (resolve, reject) => {
await a.Show(id, options.Title, options.Message, options.Size);
await a.Show({
ID: id,
Title: options.Title,
Message: options.Message,
Size: 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);
a.Update({ ID: id, Footer: html });
const modal = a.Find(id);
modal.Footer[0].querySelectorAll("button").forEach(function(button) {
button.addEventListener("click", function(e){
e.stopPropagation();
@ -354,14 +353,14 @@ var BSDialog = {
body += '<div class="form-group row">';
if (a.isNullOrWhitespace(options.Label)) {
if (a.isNullOrWhitespace(options.Textbox.Label) || (options.Textbox.LabelSize <= 0)) {
body += '<div class="col-sm-12">';
body += '<input type="text" class="form-control" id="textbox' + id + '" placeholder="' + options.Placeholder + '">';
body += '<input type="text" class="form-control" id="textbox' + id + '" placeholder="' + options.Textbox.Placeholder + '" value="' + options.Textbox.Value + '">';
body += '</div>';
} else {
body += '<label for="textbox' + id + '" class="col-sm-4 col-form-label">' + options.Label + '</label>';
body += '<div class="col-sm-8">';
body += '<input type="text" class="form-control" id="textbox' + id + '" placeholder="' + options.Placeholder + '">';
body += '<label for="textbox' + id + '" class="col-sm-' + options.Textbox.LabelSize + ' col-form-label">' + options.Textbox.Label + '</label>';
body += '<div class="col-sm-' + options.Textbox.BoxSize + '">';
body += '<input type="text" class="form-control" id="textbox' + id + '" placeholder="' + options.Textbox.Placeholder + '" value="' + options.Textbox.Value + '">';
body += '</div>';
}
@ -461,6 +460,18 @@ var BSDialog = {
this.body.classList.remove("modal-open");
this.body.style.overflow = null;
},
retrieveURL: async function (url) {
return await new Promise(async (resolve) => {
await fetch(url, {
cache: 'no-cache',
credentials: 'same-origin'
}).then(data => data.text()).then(data => {
resolve(data);
}).catch((error) => {
resolve("Error: " + error);
});
});
},
toggleSize: function () {
var a = this;

2
bsdialog4.min.js vendored

File diff suppressed because one or more lines are too long