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 196 additions and 174 deletions
Showing only changes of commit 46cda4fbf1 - Show all commits

View File

@ -200,11 +200,11 @@ BSDialog.UpdateFooter('abc123', '');
BSDialog.UpdateSize('abc123', 'lg');
</pre>
</div>
<p><button id="button3" type="button" class="btn btn-primary">Launch Modal</button></p>
<p><button id="buttonR3" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#button2").on('click', function(){
$("#buttonR3").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!');

View File

@ -1,132 +1,11 @@
/**
* BSDialog4
* @version v0.1.2.046 (2023/08/20 00:39)
* @version v0.1.3.017 (2023/08/30 00:17)
*/
var BSDialog = {
Create: async function (id, title, url, size) {
await this.Show({
ID: id,
Title: title,
Message: url,
URL: url,
Size: size,
Colour: "secondary"
});
},
Clear: function () {
this.body.querySelectorAll(".modal").forEach(function(e) {
e.parentNode.removeChild(e);
});
this.removeBackdrop();
},
Close: function (id) {
let modal = this.Find(id);
if (modal === null) {
return;
}
modal.Modal.forEach(function(e) {
e.parentNode.removeChild(e);
});
modal = this.Find(id);
if (modal !== null) {
return;
}
this.removeBackdrop();
},
UpdateTitle: function (id, title) {
let modal = this.Find(id);
if (modal === null) {
return;
}
modal.Title.forEach(function(e) {
e.innerHTML = title;
});
},
UpdateSize: function (id, size) {
let modal = this.Find(id);
if (modal === null) {
return;
}
modal.Modal.forEach(function(e) {
let modalDialog = e.querySelectorAll(".modal-dialog")[0];
modalDialog.classList.remove("modal-sm");
modalDialog.classList.remove("modal-md");
modalDialog.classList.remove("modal-lg");
modalDialog.classList.remove("modal-xl");
modalDialog.classList.add("modal-" + size);
});
},
UpdateBody: function (id, content) {
var a = this;
let modal = a.Find(id);
if (modal === null) {
return;
}
modal.Body.forEach(function(e) {
a.html(e, content);
});
},
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);
});
},
UpdateFooter: function (id, content) {
var a = this;
let modal = a.Find(id);
if (modal === null) {
return;
}
modal.Footer.forEach(function(e) {
a.html(e, content);
});
},
Exists: function (id) {
return (this.Find(id) !== null);
},
Find: function (id) {
let modal = this.body.querySelectorAll("#" + this.pfx + id + ".modal");
if (!modal) {
return null;
}
if (modal.length <= 0) {
return null;
}
return {
Title: modal[0].querySelectorAll(".modal-title"),
Body: modal[0].querySelectorAll(".modal-body"),
Footer: modal[0].querySelectorAll(".modal-footer"),
Close: modal[0].querySelectorAll("[data-dismiss='modal']"),
Modal: modal
};
},
Show: async function (options) {
const a = this;
const _options = Object.assign(a.DefaultShowOptions, options);
const _options = Object.assign(a.Default().ShowOptions, options);
a.id = _options.ID;
a.pfx = "bsdia4_";
@ -149,25 +28,11 @@ var BSDialog = {
}
}
},
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);
const _options = Object.assign(a.Default().PromptOptions, options);
return await new Promise((resolve, reject) => {
@ -208,7 +73,119 @@ var BSDialog = {
});
},
DefaultShowOptions: {
Clear: function () {
this.body.querySelectorAll(".modal").forEach(function(e) {
e.parentNode.removeChild(e);
});
this.removeBackdrop();
},
Close: function (id) {
let modal = this.Find(id);
if (modal === null) {
return;
}
modal.Modal.forEach(function(e) {
e.parentNode.removeChild(e);
});
modal = this.Find(id);
if (modal !== null) {
return;
}
this.removeBackdrop();
},
Update: async function (options) {
const a = this;
let _options = Object.assign(a.Default().UpdateOptions, options);
const modal = a.Find(_options.ID);
if (modal === null) {
return;
}
if (!this.isNullOrWhitespace(_options.Title)) {
modal.Title.forEach(function(e) {
e.innerHTML = _options.Title;
});
}
if (!this.isNullOrWhitespace(_options.Body)) {
modal.Body.forEach(function(e) {
a.html(e, _options.Body);
});
}
if (!this.isNullOrWhitespace(_options.BodyURL)) {
if (_options.BodyURL.startsWith("http://") || _options.BodyURL.startsWith("https://") || _options.BodyURL.startsWith("/")) {
// ok
} else {
_options.BodyURL = null;
}
}
if (!this.isNullOrWhitespace(_options.BodyURL)) {
await a.UpdateBodyRemote(_options.ID, _options.BodyURL);
}
if (!this.isNullOrWhitespace(_options.Footer)) {
modal.Footer.forEach(function(e) {
a.html(e, _options.Footer);
});
}
if (!this.isNullOrWhitespace(_options.Size)) {
modal.Modal[0].querySelectorAll(".modal-dialog").forEach(function(e) {
e.classList.remove("modal-sm");
e.classList.remove("modal-md");
e.classList.remove("modal-lg");
e.classList.remove("modal-xl");
e.classList.add("modal-" + _options.Size);
});
}
},
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");
if (!modal) {
return null;
}
if (modal.length <= 0) {
return null;
}
return {
Title: modal[0].querySelectorAll(".modal-title"),
Body: modal[0].querySelectorAll(".modal-body"),
Footer: modal[0].querySelectorAll(".modal-footer"),
Close: modal[0].querySelectorAll("[data-dismiss='modal']"),
Modal: modal
};
},
Default: function() {
return {
ShowOptions: {
ID: null,
Title: "",
Message: "",
@ -217,13 +194,7 @@ var BSDialog = {
Colour: "secondary",
ShowFooter: true
},
DefaultToastOptions: {
ID: null,
Title: "",
Message: "",
Size: "md"
},
DefaultPromptOptions: {
PromptOptions: {
Title: "",
Message: "",
Size: "md",
@ -233,13 +204,21 @@ var BSDialog = {
{ Label: "Cancel", Value: "Cancel", Colour: "secondary" }
]
},
ShowToast: function (id, title, message, size) {
this.Toast({
ID: id,
Title: title,
Message: message,
Size: size
});
ToastOptions: {
ID: null,
Title: "",
Message: "",
Size: "md"
},
UpdateOptions: {
ID: null,
Title: null,
Body: null,
BodyURL: null,
Footer: null,
Size: null
}
};
},
addBackdrop: function () {
let a = this;
@ -406,5 +385,49 @@ var BSDialog = {
modalDialog.classList.remove("modal-xl");
modalDialog.classList.add("modal-md");
}
},
//
// deprecated/legacy -support
// DefaultShowOptions: this.Default().ShowOptions,
// DefaultToastOptions: this.Default().ToastOptions,
// DefaultPromptOptions: this.Default().PromptOptions,
Create: async function (id, title, url, size) {
await this.Show({
ID: id,
Title: title,
Message: url,
URL: url,
Size: size,
Colour: "secondary"
});
},
UpdateTitle: function (id, title) {
this.Update({ ID: id, Title: title });
},
UpdateSize: function (id, size) {
this.Update({ ID: id, Size: size });
},
UpdateBody: function (id, content) {
this.Update({ ID: id, Body: content });
},
UpdateFooter: function (id, content) {
this.Update({ ID: id, Footer: content });
},
Toast: async function (options) {
const a = this;
const _options = Object.assign(a.Default().ToastOptions, options);
await this.Show({
ID: _options.ID,
Title: _options.Title,
Message: _options.Message,
URL: null,
Size: _options.Size,
Colour: "secondary",
ShowFooter: false
});
},
ShowToast: function (id, title, message, size) {
this.Toast({ ID: id, Title: title, Message: message, Size: size });
}
};

3
bsdialog4.min.js vendored

File diff suppressed because one or more lines are too long