Compare commits

..

No commits in common. "f4872143c866b0dd77719094d890b0ab84277a87" and "44ab87e8676d2af7db2385f384245bb186ce0cde" have entirely different histories.

3 changed files with 99 additions and 103 deletions

View File

@ -14,7 +14,6 @@
<link href="http://cdn.hiimray.co.uk/8206c600-707c-469e-8d49-a76ae35782af/bootstrap/4.6.2/dist/css/bootstrap.min.css" rel="stylesheet" /> <link href="http://cdn.hiimray.co.uk/8206c600-707c-469e-8d49-a76ae35782af/bootstrap/4.6.2/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="bsdialog4.js"></script> <script src="bsdialog4.js"></script>
<!-- <script src="bsdialog4.min.js"></script> -->
<title></title> <title></title>
<style> <style>

View File

@ -1,18 +1,18 @@
/** /**
* BSDialog4 * BSDialog4
* @version v0.1.4.031 (2023/11/03 22:42) * @version v0.1.3.017 (2023/08/30 00:17)
*/ */
var BSDialog = { var BSDialog = {
Show: async function (options) { Show: async function (options) {
const a = this; const a = this;
const _options = Object.assign(a.Options.ShowModal, options); const _options = Object.assign(a.Default().ShowOptions, options);
a.id = _options.ID; a.id = _options.ID;
a.pfx = "bsdia4_"; a.pfx = "bsdia4_";
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.ShowFooter, _options.EasyClose, _options.Colour); a.addModal(_options.ID, _options.Title, _options.Size, true, _options.Colour);
if (_options.URL == null) { if (_options.URL == null) {
await a.Update({ ID: _options.ID, Body: _options.Message }); await a.Update({ ID: _options.ID, Body: _options.Message });
@ -34,7 +34,7 @@ var BSDialog = {
const a = this; const a = this;
let id = Math.floor(Math.random() * 10000) + 1000; let id = Math.floor(Math.random() * 10000) + 1000;
const _options = Object.assign(a.Options.ShowPrompt, options); const _options = Object.assign(a.Default().PromptOptions, options);
switch (_options.Type) { switch (_options.Type) {
case "textbox": case "textbox":
@ -57,7 +57,9 @@ var BSDialog = {
return; return;
} }
modal.Modal.parentNode.removeChild(modal.Modal); modal.Modal.forEach(function(e) {
e.parentNode.removeChild(e);
});
modal = this.Find(id); modal = this.Find(id);
if (modal !== null) { if (modal !== null) {
@ -68,7 +70,7 @@ var BSDialog = {
}, },
Update: async function (options) { Update: async function (options) {
const a = this; const a = this;
let _options = Object.assign(a.Options.UpdateModal, options); let _options = Object.assign(a.Default().UpdateOptions, options);
const modal = a.Find(_options.ID); const modal = a.Find(_options.ID);
if (modal === null) { if (modal === null) {
@ -76,11 +78,15 @@ var BSDialog = {
} }
if (!this.isNullOrWhitespace(_options.Title)) { if (!this.isNullOrWhitespace(_options.Title)) {
modal.Title.innerHTML = _options.Title; modal.Title.forEach(function(e) {
e.innerHTML = _options.Title;
});
} }
if (!this.isNullOrWhitespace(_options.Body)) { if (!this.isNullOrWhitespace(_options.Body)) {
a.html(modal.Body, _options.Body); modal.Body.forEach(function(e) {
a.html(e, _options.Body);
});
} }
if (!this.isNullOrWhitespace(_options.BodyURL)) { if (!this.isNullOrWhitespace(_options.BodyURL)) {
@ -98,11 +104,13 @@ var BSDialog = {
} }
if (!this.isNullOrWhitespace(_options.Footer)) { if (!this.isNullOrWhitespace(_options.Footer)) {
a.html(modal.Footer, _options.Footer); modal.Footer.forEach(function(e) {
a.html(e, _options.Footer);
});
} }
if (!this.isNullOrWhitespace(_options.Size)) { if (!this.isNullOrWhitespace(_options.Size)) {
modal.Modal.querySelectorAll(".modal-dialog").forEach(function(e) { modal.Modal[0].querySelectorAll(".modal-dialog").forEach(function(e) {
e.classList.forEach(function(e2) { e.classList.forEach(function(e2) {
if (e2 == "modal-dialog") { if (e2 == "modal-dialog") {
@ -134,31 +142,29 @@ var BSDialog = {
} }
return { return {
Title: modal[0].querySelectorAll(".modal-title")[0], Title: modal[0].querySelectorAll(".modal-title"),
Header: modal[0].querySelectorAll(".modal-header")[0], Body: modal[0].querySelectorAll(".modal-body"),
Body: modal[0].querySelectorAll(".modal-body")[0], Footer: modal[0].querySelectorAll(".modal-footer"),
Footer: modal[0].querySelectorAll(".modal-footer")[0],
Close: modal[0].querySelectorAll("[data-dismiss='modal']"), Close: modal[0].querySelectorAll("[data-dismiss='modal']"),
Modal: modal[0] Modal: modal
}; };
}, },
Options: { Default: function() {
ShowModal: { return {
ShowOptions: {
ID: null, ID: null,
Title: "", Title: "",
Message: "", Message: "",
URL: null, URL: null,
Size: "md", Size: "md",
Colour: "secondary", Colour: "secondary",
ShowFooter: true, ShowFooter: true
EasyClose: true
}, },
ShowPrompt: { PromptOptions: {
Type: "button", Type: "button",
Title: "", Title: "",
Message: "", Message: "",
Size: "md", Size: "md",
EasyClose: true,
Buttons: [ Buttons: [
{ Label: "Yes", Value: "Yes", Colour: "primary" }, { Label: "Yes", Value: "Yes", Colour: "primary" },
{ Label: "No", Value: "No", Colour: "secondary" }, { Label: "No", Value: "No", Colour: "secondary" },
@ -172,23 +178,24 @@ var BSDialog = {
BoxSize: 8 BoxSize: 8
} }
}, },
UpdateModal: { ToastOptions: {
ID: null,
Title: "",
Message: "",
Size: "md"
},
UpdateOptions: {
ID: null, ID: null,
Title: null, Title: null,
Body: null, Body: null,
BodyURL: null, BodyURL: null,
Footer: null, Footer: null,
Size: null Size: null
},
ShowToast: {
ID: null,
Title: "",
Message: "",
Size: "md"
} }
};
}, },
addBackdrop: function () { addBackdrop: function () {
const a = this; let a = this;
// don't allow duplicates // don't allow duplicates
if (a.body.querySelectorAll(".modal-backdrop").length > 0) { if (a.body.querySelectorAll(".modal-backdrop").length > 0) {
@ -200,9 +207,18 @@ var BSDialog = {
// lock background // lock background
a.body.classList.add("modal-open"); a.body.classList.add("modal-open");
a.body.style.overflow = "hidden"; a.body.style.overflow = "hidden";
// close
let backdrop = a.body.querySelectorAll(".modal-backdrop")[0];
backdrop.addEventListener("click", function(e){
e.stopPropagation();
e.preventDefault();
a.Clear();
});
}, },
addModal: function (id, title, size, showFooter, easyClose, closeColour) { addModal: function (id, title, size, showFooter, closeColour) {
const a = this; var a = this;
// don't allow duplicates // don't allow duplicates
let modal = a.Find(id); let modal = a.Find(id);
@ -215,8 +231,8 @@ var BSDialog = {
html += ' <div class="modal-dialog modal-' + size + '">'; html += ' <div class="modal-dialog modal-' + size + '">';
html += ' <div class="modal-content">'; html += ' <div class="modal-content">';
html += ' <div class="modal-header">'; html += ' <div class="modal-header">';
html += ' <span class="modal-title font-weight-bold" style="cursor: default; user-select: none;" aria-label="Title">' + title + '</span>'; html += ' <span class="modal-title font-weight-bold">' + title + '</span>';
html += ' <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="user-select: none;">'; html += ' <button type="button" class="close" data-dismiss="modal" aria-label="Close">';
html += ' <span aria-hidden="true">&times;</span>'; html += ' <span aria-hidden="true">&times;</span>';
html += ' </button>'; html += ' </button>';
html += ' </div>'; html += ' </div>';
@ -249,22 +265,6 @@ var BSDialog = {
return; return;
} }
// Close on backdrp
if (easyClose === true) {
modal.Modal.addEventListener("click", function(e){
e.stopPropagation();
e.preventDefault();
a.Close(id);
});
const modalContent = modal.Modal.querySelectorAll(".modal-content")[0];
modalContent.addEventListener("click", function(e){
e.stopPropagation();
e.preventDefault();
});
}
modal.Close.forEach(function(e){ modal.Close.forEach(function(e){
e.addEventListener("click", function(e){ e.addEventListener("click", function(e){
e.stopPropagation(); e.stopPropagation();
@ -272,15 +272,17 @@ var BSDialog = {
a.Close(id); a.Close(id);
}); });
});
modal.Title.addEventListener("dblclick", function(e){ e.addEventListener("auxclick", function(e){
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
if (e.button === 1) {
a.toggleSize(); a.toggleSize();
}
}); });
});
}, },
showButtonPrompt: async function (id, options) { showButtonPrompt: async function (id, options) {
const a = this; const a = this;
@ -290,8 +292,7 @@ var BSDialog = {
ID: id, ID: id,
Title: options.Title, Title: options.Title,
Message: options.Message, Message: options.Message,
Size: options.Size, Size: options.Size
EasyClose: options.EasyClose
}); });
let html = ''; let html = '';
@ -302,7 +303,7 @@ var BSDialog = {
a.Update({ ID: id, Footer: html }); a.Update({ ID: id, Footer: html });
const modal = a.Find(id); const modal = a.Find(id);
modal.Footer.querySelectorAll("button").forEach(function(button) { modal.Footer[0].querySelectorAll("button").forEach(function(button) {
button.addEventListener("click", function(e){ button.addEventListener("click", function(e){
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
@ -341,8 +342,7 @@ var BSDialog = {
ID: id, ID: id,
Title: options.Title, Title: options.Title,
Message: options.Message, Message: options.Message,
Size: options.Size, Size: options.Size
EasyClose: options.EasyClose
}); });
let body = ''; let body = '';
@ -378,13 +378,13 @@ var BSDialog = {
}); });
const modal = a.Find(id); const modal = a.Find(id);
const buttons = modal.Footer.querySelectorAll("button"); const buttons = modal.Footer[0].querySelectorAll("button");
buttons[0].addEventListener("click", function(e){ buttons[0].addEventListener("click", function(e){
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
const value = modal.Body.querySelectorAll("input")[0].value; const value = modal.Body[0].querySelectorAll("input")[0].value;
a.Close(id); a.Close(id);
@ -473,14 +473,14 @@ var BSDialog = {
}); });
}, },
toggleSize: function () { toggleSize: function () {
const a = this; var a = this;
let modal = a.Find(a.id); let modal = a.Find(a.id);
if (modal === null) { if (modal === null) {
return; return;
} }
let modalDialog = modal.Modal.querySelectorAll(".modal-dialog")[0]; let modalDialog = modal.Modal[0].querySelectorAll(".modal-dialog")[0];
if (modalDialog.classList.contains('modal-sm')) { if (modalDialog.classList.contains('modal-sm')) {
a.Update({ ID: a.id, Size: "md" }); a.Update({ ID: a.id, Size: "md" });
} else if (modalDialog.classList.contains('modal-md')) { } else if (modalDialog.classList.contains('modal-md')) {
@ -488,15 +488,12 @@ var BSDialog = {
} else if (modalDialog.classList.contains('modal-lg')) { } else if (modalDialog.classList.contains('modal-lg')) {
a.Update({ ID: a.id, Size: "xl" }); a.Update({ ID: a.id, Size: "xl" });
} else if (modalDialog.classList.contains('modal-xl')) { } else if (modalDialog.classList.contains('modal-xl')) {
a.Update({ ID: a.id, Size: "xxl" });
} else if (modalDialog.classList.contains('modal-xxl')) {
a.Update({ ID: a.id, Size: "sm" }); a.Update({ ID: a.id, Size: "sm" });
} else { } else {
a.Update({ ID: a.id, Size: "md" }); a.Update({ ID: a.id, Size: "md" });
} }
}, },
// //
//
// deprecated/legacy-support // deprecated/legacy-support
Create: async function (id, title, url, size) { Create: async function (id, title, url, size) {
await this.Show({ await this.Show({
@ -522,7 +519,7 @@ var BSDialog = {
}, },
Toast: async function (options) { Toast: async function (options) {
const a = this; const a = this;
const _options = Object.assign(a.Options.ShowToast, options); const _options = Object.assign(a.Default().ToastOptions, options);
await this.Show({ await this.Show({
ID: _options.ID, ID: _options.ID,

4
bsdialog4.min.js vendored

File diff suppressed because one or more lines are too long