Changed to use JS class pattern #7

Merged
Ray merged 1 commits from release/0.2.1.068 into master 2023-11-18 19:27:56 +00:00
3 changed files with 401 additions and 361 deletions
Showing only changes of commit 6ebb4bbe93 - Show all commits

View File

@ -29,93 +29,133 @@
<body class="py-5"> <body class="py-5">
<div class="container"> <div class="container">
<div class="row mb-3"> <div class="row mb-3 border-bottom">
<div class="col-6 border-right"> <div class="col-sm-4 border-right">
<p><b>Example. Simple Text Modal</b></p>
<p>Launch a modal with a text body.</p>
<div class="pb-3 mb-3 border-bottom"> <p><button id="buttonL1" type="button" class="btn btn-primary">Launch Modal</button></p>
<p><b>Example. Simple Text Modal</b></p>
<p>Launch an empty modal</p> <script>
<div class="alert alert-secondary text-sm"> $(document).ready(function(){
<pre>
BSDialog5.Show({ $("#buttonL1").on('click', function(){
BSDialog5.Show({
ID: "modalL1",
Title: "Modal Title",
Message: "Hello Momo!",
URL: null,
Size: "md",
Colour: "secondary"
});
});
});
</script>
</div>
<div class="col-sm-8">
<div class="alert alert-secondary text-sm">
<pre>BSDialog5.Show({
ID: "modalL1", ID: "modalL1",
Title: "Modal Title", Title: "Modal Title",
Message: "Hello Momo!", Message: "Hello Momo!",
URL: null, URL: null,
Size: "md", Size: "md",
Colour: "secondary" Colour: "secondary"
}); });</pre>
</pre>
</div>
<p><button id="buttonL1" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonL1").on('click', function(){
BSDialog5.Show({
ID: "modalL1",
Title: "Modal Title",
Message: "Hello Momo!",
URL: null,
Size: "md",
Colour: "secondary"
});
});
});
</script>
</div> </div>
</div>
</div>
<div class="pb-3 mb-3 border-bottom"> <div class="row mb-3 border-bottom">
<p><b>Example. Prompt Modal</b></p> <div class="col-sm-4 border-right">
<p>Launch a prompt modal and wait for a response</p>
<div class="alert alert-secondary text-sm">
<pre>
let response = await BSDialog5.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); <p><b>Example. Update Modal</b></p>
</pre> <p>Make changes (title, body, size or footer) to a modal.</p>
</div>
<p><button id="buttonL2" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonL2").on('click', async function(){ <p><button id="buttonR1" type="button" class="btn btn-primary">Launch Modal</button></p>
let response = await BSDialog5.Prompt({ <script>
Title: "Modal Title", $(document).ready(function(){
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); $("#buttonR1").on('click', function(){
BSDialog5.Show({
ID: "modalR1",
Title: "Modal Title",
Message: "Hello Momo!",
URL: null,
Size: "md",
Colour: "secondary"
}); });
BSDialog5.Update({
ID: "modalR1",
Title: "Modal Changed Title",
Body: "Hello momo again!",
URL: null,
Size: "lg",
Footer: null
});
}); });
</script>
});
</script>
</div>
<div class="col-sm-8">
<div class="alert alert-secondary text-sm">
<pre>BSDialog5.Update({
ID: "modalL1",
Title: "Modal Changed Title",
Body: "Hello momo again!",
URL: null,
Size: "lg",
Footer: null
});</pre>
</div> </div>
</div>
</div>
<div class="pb-3 mb-3 border-bottom"> <div class="row mb-3 border-bottom">
<p><b>Example. Multiple Modals</b></p> <div class="col-sm-4 border-right">
<p>Launch multiple modals</p>
<div class="alert alert-secondary text-sm"> <p><b>Example. Multiple Modals (Stack)</b></p>
<pre> <p>Launch multiple modals, stacked on top of each other.</p>
BSDialog5.Show({
<p><button id="buttonL3" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonL3").on('click', function(){
BSDialog5.Show({
ID: "modalL3a",
Title: "Modal A Title",
Message: "First!",
URL: null,
Size: "md",
Colour: "secondary"
});
BSDialog5.Show({
ID: "modalL3b",
Title: "Modal B Title",
Message: "Second!",
URL: null,
Size: "md",
Colour: "secondary"
});
});
});
</script>
</div>
<div class="col-sm-8">
<div class="alert alert-secondary text-sm">
<pre>BSDialog5.Show({
ID: "modalL3a", ID: "modalL3a",
Title: "Modal A Title", Title: "Modal A Title",
Message: "First!", Message: "First!",
@ -131,47 +171,86 @@ BSDialog5.Show({
URL: null, URL: null,
Size: "md", Size: "md",
Colour: "secondary" Colour: "secondary"
}); });</pre>
</pre> </div>
</div> </div>
<p><button id="buttonL3" type="button" class="btn btn-primary">Launch Modal</button></p> </div>
<script>
$(document).ready(function(){
$("#buttonL3").on('click', function(){ <div class="row mb-3 border-bottom">
BSDialog5.Show({ <div class="col-sm-4 border-right">
ID: "modalL3a",
Title: "Modal A Title",
Message: "First!",
URL: null,
Size: "md",
Colour: "secondary"
});
BSDialog5.Show({ <p><b>Example. Button Prompt (Modal)</b></p>
ID: "modalL3b", <p>Launch a modal with a prompt of several buttons. Modal waits for a response from one of the buttons.</p>
Title: "Modal B Title",
Message: "Second!", <p><button id="buttonL2" type="button" class="btn btn-primary">Launch Modal</button></p>
URL: null, <script>
Size: "md", $(document).ready(function(){
Colour: "secondary"
}); $("#buttonL2").on('click', async function(){
let response = await BSDialog5.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>
});
</script>
</div> </div>
<div class="col-6"> <div class="col-sm-8">
<div class="alert alert-secondary text-sm">
<pre>let response = await BSDialog5.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" }
]
});
<div class="pb-3 mb-3 border-bottom"> alert(response);</pre>
<p><b>Example. Prompt Modal (Textbox)</b></p> </div>
<p>Launch a prompt modal and wait for a textbox response</p> </div>
<div class="alert alert-secondary text-sm"> </div>
<pre>
let response = await BSDialog5.Prompt({ <div class="row mb-3 border-bottom">
<div class="col-sm-4 border-right">
<p><b>Example. Text Prompt (Modal)</b></p>
<p>Launch a modal with a text prompt. Modal waits for a response from the textbox.</p>
<p><button id="buttonL2a" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonL2a").on('click', async function(){
let response = await BSDialog5.Prompt({
Type: "textbox",
Title: "Modal Title",
Message: "Are you sure want to wait for a response?",
Size: "md",
Label: "",
Placeholder: ""
});
alert(response);
});
});
</script>
</div>
<div class="col-sm-8">
<div class="alert alert-secondary text-sm">
<pre>let response = await BSDialog5.Prompt({
Type: "textbox", Type: "textbox",
Title: "Modal Title", Title: "Modal Title",
Message: "Are you sure want to wait for a response?", Message: "Are you sure want to wait for a response?",
@ -180,125 +259,56 @@ let response = await BSDialog5.Prompt({
Placeholder: "" Placeholder: ""
}); });
alert(response); alert(response);</pre>
</pre>
</div>
<p><button id="buttonL2a" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonL2a").on('click', async function(){
let response = await BSDialog5.Prompt({
Type: "textbox",
Title: "Modal Title",
Message: "Are you sure want to wait for a response?",
Size: "md",
Label: "",
Placeholder: ""
});
alert(response);
});
});
</script>
</div> </div>
</div>
</div>
<div class="pb-3 mb-3 border-bottom"> <div class="row mb-3 border-bottom">
<p><b>Example. Text Modal with Updates</b></p> <div class="col-sm-4 border-right">
<p>Launch a basic modal, make updates to the title, body, size and footer.</p>
<div class="alert alert-secondary text-sm">
<pre>
BSDialog5.Show({
ID: "modalR1",
Title: "Modal Title",
Message: "Hello Momo!",
URL: null,
Size: "md",
Colour: "secondary"
});
BSDialog5.Update({ <p><b>Example. Close Modal</b></p>
ID: "modalR1", <p>Close a modal using its identifier</p>
Title: "Modal Changed Title", <p><button id="buttonR2" type="button" class="btn btn-primary">Launch Modal</button></p>
Body: "Hello momo again!", <script>
BodyURL: null, $(document).ready(function(){
Size: "lg",
Footer: null
});
</pre>
</div>
<p><button id="buttonR1" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonR1").on('click', function(){
BSDialog5.Show({
ID: "modalR1",
Title: "Modal Title",
Message: "Hello Momo!",
URL: null,
Size: "md",
Colour: "secondary"
});
BSDialog5.Update({
ID: "modalR1",
Title: "Modal Changed Title",
Body: "Hello momo again!",
BodyURL: null,
Size: "lg",
Footer: null
});
});
$("#buttonR2").on('click', function(){
BSDialog5.Close("modalR1");
}); });
</script>
});
</script>
</div>
<div class="col-sm-8">
<div class="alert alert-secondary text-sm">
<pre>BSDialog5.Close("modalR1");</pre>
</div> </div>
</div>
</div>
<div class="row mb-3 border-bottom">
<div class="col-sm-4 border-right">
<div class="pb-3 mb-3 border-bottom"> <p><b>Example. Clear Modal</b></p>
<p><b>Example. Close Modal</b></p> <p>Close all modals</p>
<p>Close a modal using its identifier</p> <p><button id="buttonR3" type="button" class="btn btn-primary">Launch Modal</button></p>
<div class="alert alert-secondary text-sm"> <script>
<pre> $(document).ready(function(){
BSDialog5.Close("modalR1");
</pre>
</div>
<p><button id="buttonR2" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonR2").on('click', function(){
BSDialog5.Close("modalR1");
});
$("#buttonR3").on('click', function(){
BSDialog5.Clear();
}); });
</script>
});
</script>
</div>
<div class="col-sm-8">
<div class="alert alert-secondary text-sm">
<pre>BSDialog5.Clear();</pre>
</div> </div>
<div class="pb-3 mb-3 border-bottom">
<p><b>Example. Clear Modal</b></p>
<p>Close all modals</p>
<div class="alert alert-secondary text-sm">
<pre>
BSDialog5.Clear();
</pre>
</div>
<p><button id="buttonR3" type="button" class="btn btn-primary">Launch Modal</button></p>
<script>
$(document).ready(function(){
$("#buttonR3").on('click', function(){
BSDialog5.Clear();
});
});
</script>
</div>
</div> </div>
</div> </div>

View File

@ -1,11 +1,16 @@
/** /**
* BSDialog5 * BSDialog5
* @version v0.2.1.005 (2023/11/14 2028) * @version v0.2.1.068 (2023/11/14 2028)
*/ */
var BSDialog5 = { class BSDialog05 {
Default: function() {
constructor() {
}
get Options() {
return { return {
ShowOptions: { ShowModal: {
ID: null, ID: null,
Title: "", Title: "",
Message: "", Message: "",
@ -15,7 +20,7 @@ var BSDialog5 = {
ShowFooter: true, ShowFooter: true,
EasyClose: true EasyClose: true
}, },
PromptOptions: { ShowPrompt: {
Type: "button", Type: "button",
Title: "", Title: "",
Message: "", Message: "",
@ -34,115 +39,130 @@ var BSDialog5 = {
BoxSize: 8 BoxSize: 8
} }
}, },
UpdateOptions: { UpdateModal: {
ID: null, ID: null,
Title: null, Title: null,
Body: null, Body: null,
BodyURL: null, URL: null,
Footer: null, Footer: null,
Size: null Size: null
} }
}; };
}, }
Show: async function (options) {
get #prefix() {
return "bsdia5_";
}
get #body() {
return document.getElementsByTagName("body")[0];
}
get #sizeList() {
return [
"modal-sm",
"modal-md",
"modal-lg",
"modal-xl",
"modal-xxl"
];
}
async Show(options) {
const a = this; const a = this;
const _options = Object.assign(a.Default().ShowOptions, options); const _options = Object.assign(a.Options.ShowModal, options);
a.id = _options.ID; a.#addModal(_options.ID, _options.Title, _options.Size, _options.ShowFooter, _options.Colour);
a.pfx = "bsdia5_";
a.addModal(_options.ID, _options.Title, _options.Size, _options.ShowFooter, _options.Colour); (new bootstrap.Modal(document.getElementById(a.#prefix + _options.ID), {
(new bootstrap.Modal(document.getElementById(a.pfx + _options.ID), {
backdrop: _options.EasyClose backdrop: _options.EasyClose
})).show(); })).show();
if (_options.URL == null) { if (a.#isURL(_options.URL)) {
await a.Update({ ID: _options.ID, Body: _options.Message }); await a.UpdateBodyRemote(_options.ID, _options.URL);
} else { } else {
if (a.isNullOrWhitespace(_options.URL)) { await a.Update({ ID: _options.ID, Body: _options.Message });
await a.Update({ ID: _options.ID, Body: URL });
} else {
if (_options.URL.startsWith("http://") || _options.URL.startsWith("https://") || _options.URL.startsWith("/")) {
await a.UpdateBodyRemote(_options.ID, _options.URL);
} else {
await a.Update({ ID: _options.ID, Body: URL });
}
}
} }
}, }
Prompt: async function (options) {
async Prompt(options) {
const a = this; const a = this;
const id = "prompt" + Math.floor(Math.random() * 10000) + 1000; const id = "prompt" + Math.floor(Math.random() * 10000) + 1000;
const _options = Object.assign(a.Default().PromptOptions, options); const _options = Object.assign(a.Options.ShowPrompt, options);
switch (_options.Type) { switch (_options.Type) {
case "textbox": case "textbox":
return await a.showTextboxPrompt(id, _options); return await a.#showTextboxPrompt(id, _options);
case "button": case "button":
default: default:
return await a.showButtonPrompt(id, _options); return await a.#showButtonPrompt(id, _options);
} }
}, }
Clear: function () {
this.GetBody().querySelectorAll(".modal").forEach(function(e) {
e.parentNode.removeChild(e);
});
this.removeBackdrop(); async Clear() {
},
Close: function (id) {
let modal = this.Find(id);
if (modal === null) {
return;
}
modal.Modal.parentNode.removeChild(modal.Modal);
modal = this.Find(id);
if (modal !== null) {
return;
}
this.removeBackdrop();
},
Update: async function (options) {
const a = this; const a = this;
let _options = Object.assign(a.Default().UpdateOptions, options);
document.querySelectorAll('.modal').forEach(function(e) {
const modal = bootstrap.Modal.getInstance(e);
if (modal) {
modal.hide();
}
});
}
async Close(id) {
const a = this;
if (id.startsWith(a.#prefix)) {
id = id.substr(a.#prefix.length);
}
const node = document.getElementById(a.#prefix + id);
const modal = bootstrap.Modal.getInstance(node);
if (modal){
modal.hide();
}
if (node) {
node.parentNode.removeChild(node);
}
}
async Update(options) {
const a = this;
let _options = Object.assign(a.Options.UpdateModal, options);
const modal = a.Find(_options.ID); const modal = a.Find(_options.ID);
if (modal === null) { if (modal === null) {
return; return;
} }
if (!this.isNullOrWhitespace(_options.Title)) modal.Title.innerHTML = _options.Title; if (!this.#isNullOrWhitespace(_options.Title)) {
modal.Title.innerHTML = _options.Title;
}
if (!this.isNullOrWhitespace(_options.Body)) a.html(modal.Body, _options.Body); if (!this.#isNullOrWhitespace(_options.Body)) {
a.#html(modal.Body, _options.Body);
if (!this.isNullOrWhitespace(_options.BodyURL)) { } else {
if (_options.BodyURL.startsWith("http://") || _options.BodyURL.startsWith("https://") || _options.BodyURL.startsWith("/")) { if (this.#isURL(_options.URL)) {
// ok await a.UpdateBodyRemote(_options.ID, _options.URL);
} else {
_options.BodyURL = null;
} }
} }
if (!this.isNullOrWhitespace(_options.BodyURL)) { if (!this.#isNullOrWhitespace(_options.Footer)) {
await a.UpdateBodyRemote(_options.ID, _options.BodyURL); a.#html(modal.Footer, _options.Footer);
} }
if (!this.isNullOrWhitespace(_options.Footer)) a.html(modal.Footer, _options.Footer); if (!this.#isNullOrWhitespace(_options.Size)) {
a.#setSize(_options.ID, "modal-" + _options.Size);
if (!this.isNullOrWhitespace(_options.Size)) {
modal.Modal.classList.remove("modal-sm");
modal.Modal.classList.remove("modal-md");
modal.Modal.classList.remove("modal-lg");
modal.Modal.classList.remove("modal-xl");
modal.Modal.classList.add("modal-" + _options.Size);
} }
}, }
UpdateBodyRemote: async function (id, url) {
async UpdateBodyRemote(id, url) {
const a = this; const a = this;
if (!a.Exists(id)) { if (!a.Exists(id)) {
@ -157,12 +177,16 @@ var BSDialog5 = {
}).catch((error) => { }).catch((error) => {
a.Update({ ID: id, Body: "Error: " + error }); a.Update({ ID: id, Body: "Error: " + error });
}); });
}, }
Exists: function (id) {
Exists(id) {
return (this.Find(id) !== null); return (this.Find(id) !== null);
}, }
Find: function (id) {
const modal = this.GetBody().querySelectorAll("#" + this.pfx + id + ".modal"); Find(id) {
const a = this;
const modal = a.#body.querySelectorAll("#" + a.#prefix + id + ".modal");
if (!modal) { if (!modal) {
return null; return null;
} }
@ -179,11 +203,10 @@ var BSDialog5 = {
Close: modal[0].querySelectorAll("[data-bs-dismiss='modal']"), Close: modal[0].querySelectorAll("[data-bs-dismiss='modal']"),
Modal: modal[0] Modal: modal[0]
}; };
}, }
GetBody: function() {
return document.getElementsByTagName("body")[0];
}, #addModal(id, title, size, showFooter, closeColour) {
addModal: function (id, title, size, showFooter, closeColour) {
const a = this; const a = this;
// don't allow duplicates // don't allow duplicates
@ -193,7 +216,7 @@ var BSDialog5 = {
} }
let html = ""; let html = "";
html += '<div class="modal modal-' + size + ' fade" id="' + a.pfx + id + '" tabindex="-1" aria-labelledby="' + a.pfx + id + '" aria-hidden="true" style="display:none;">'; html += '<div class="modal modal-' + size + ' fade" id="' + a.#prefix + id + '" tabindex="-1" aria-labelledby="' + a.#prefix + id + '" aria-hidden="true" style="display:none;">';
html += ' <div class="modal-dialog">'; html += ' <div class="modal-dialog">';
html += ' <div class="modal-content">'; html += ' <div class="modal-content">';
html += ' <div class="modal-header">'; html += ' <div class="modal-header">';
@ -222,14 +245,14 @@ var BSDialog5 = {
html += ' </div>'; html += ' </div>';
html += '</div>'; html += '</div>';
a.appendHtml(a.GetBody(), html); a.#appendHtml(a.#body, html);
modal = a.Find(id); modal = a.Find(id);
if (modal === null) { if (modal === null) {
return; return;
} }
document.getElementById(a.pfx + id).addEventListener('hidden.bs.modal', function (event) { document.getElementById(a.#prefix + id).addEventListener('hidden.bs.modal', function (event) {
a.Close(id); a.Close(id);
}); });
@ -237,13 +260,11 @@ var BSDialog5 = {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
a.toggleSize(); a.#toggleSize(id);
}); });
}, }
async #showButtonPrompt(id, options) {
showButtonPrompt: async function (id, options) {
const a = this; const a = this;
return await new Promise(async (resolve, reject) => { return await new Promise(async (resolve, reject) => {
@ -288,8 +309,9 @@ var BSDialog5 = {
}); });
}); });
}, }
showTextboxPrompt: async function (id, options) {
async #showTextboxPrompt(id, options) {
const a = this; const a = this;
return await new Promise(async (resolve, reject) => { return await new Promise(async (resolve, reject) => {
@ -308,13 +330,13 @@ var BSDialog5 = {
let body = ''; let body = '';
if (!a.isNullOrWhitespace(options.Message)) { if (!a.#isNullOrWhitespace(options.Message)) {
body += '<p>' + options.Message + '</p>'; body += '<p>' + options.Message + '</p>';
} }
body += '<div class="form-group row">'; body += '<div class="form-group row">';
if (a.isNullOrWhitespace(options.Textbox.Label) || (options.Textbox.LabelSize <= 0)) { if (a.#isNullOrWhitespace(options.Textbox.Label) || (options.Textbox.LabelSize <= 0)) {
body += '<div class="col-sm-12">'; body += '<div class="col-sm-12">';
body += '<input type="text" class="form-control" id="textbox' + id + '" placeholder="' + options.Textbox.Placeholder + '" value="' + options.Textbox.Value + '">'; body += '<input type="text" class="form-control" id="textbox' + id + '" placeholder="' + options.Textbox.Placeholder + '" value="' + options.Textbox.Value + '">';
body += '</div>'; body += '</div>';
@ -341,59 +363,58 @@ var BSDialog5 = {
const modal = a.Find(id); const modal = a.Find(id);
const buttons = modal.Footer.querySelectorAll("button"); const buttons = modal.Footer.querySelectorAll("button");
buttons[0].addEventListener("click", function(e){ buttons[0].addEventListener("click", async function(e){
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
const value = modal.Body.querySelectorAll("input")[0].value; const value = modal.Body.querySelectorAll("input")[0].value;
a.Close(id); await a.Close(id);
resolve(value); resolve(value);
}); });
buttons[1].addEventListener("click", function(e){ buttons[1].addEventListener("click", async function(e){
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
a.Close(id); await a.Close(id);
resolve(""); resolve("");
}); });
modal.Close.forEach(function(sender) { modal.Close.forEach(async function(sender) {
sender.addEventListener("click", function(e){ sender.addEventListener("click", async function(e){
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
a.Close(id); await a.Close(id);
resolve(""); resolve("");
}); });
}); });
}); });
}, }
#appendHtml(el, html) {
appendHtml: function (el, html) {
let node = document.createElement('template'); let node = document.createElement('template');
node.innerHTML = html; node.innerHTML = html;
node = node.content.firstChild; node = node.content.firstChild;
el.appendChild(node); el.appendChild(node);
}, }
html: function (el, newHtml) {
/// todo: replace with pure JS #html(el, newHtml) {
if (jQuery) { if (jQuery) {
jQuery(el).html(newHtml); jQuery(el).html(newHtml);
} else { } else {
el.innerHTML = newHtml; el.innerHTML = newHtml;
} }
}, }
isNullOrWhitespace: function(e) {
#isNullOrWhitespace(e) {
if (typeof (e) == "undefined") { if (typeof (e) == "undefined") {
return true; return true;
} }
@ -407,55 +428,64 @@ var BSDialog5 = {
} }
return (e.trim().length <= 0); return (e.trim().length <= 0);
}, }
removeBackdrop: function () {
#isURL(value) {
const a = this; const a = this;
if (a.GetBody().querySelectorAll(".modal-backdrop").length <= 0) { if (a.#isNullOrWhitespace(value)) {
return; return false;
} }
if (a.GetBody().querySelectorAll(".modal").length > 0) { if (value.startsWith("http://") || value.startsWith("https://") || value.startsWith("/")) {
return; return true;
} }
let backdrop = a.GetBody().querySelectorAll(".modal-backdrop")[0]; return false;
backdrop.parentNode.removeChild(backdrop); }
// unlock background #setSize(id, size) {
a.GetBody().classList.remove("modal-open");
a.GetBody().style.overflow = null;
},
toggleSize: function () {
const a = this; const a = this;
let modal = a.Find(a.id); const modal = a.Find(id);
if (modal === null) { if (modal === null) {
return; return;
} }
if (modal.Modal.classList.contains('modal-sm')) { for (let i=0; i<a.#sizeList.length; i++) {
modal.Modal.classList.remove("modal-sm"); modal.Modal.classList.remove(a.#sizeList[i]);
modal.Modal.classList.add("modal-md");
} else if (modal.Modal.classList.contains('modal-md')) {
modal.Modal.classList.remove("modal-md");
modal.Modal.classList.add("modal-lg");
} else if (modal.Modal.classList.contains('modal-lg')) {
modal.Modal.classList.remove("modal-lg");
modal.Modal.classList.add("modal-xl");
} else if (modal.Modal.classList.contains('modal-xl')) {
modal.Modal.classList.remove("modal-xl");
modal.Modal.classList.add("modal-xxl");
} else if (modal.Modal.classList.contains('modal-xxl')) {
modal.Modal.classList.remove("modal-xxl");
modal.Modal.classList.add("modal-sm");
} else {
modal.Modal.classList.remove("modal-sm");
modal.Modal.classList.remove("modal-md");
modal.Modal.classList.remove("modal-lg");
modal.Modal.classList.remove("modal-xl");
modal.Modal.classList.remove("modal-xxl");
modal.Modal.classList.add("modal-md");
} }
modal.Modal.classList.add(size);
} }
};
#toggleSize(id) {
const a = this;
const modal = a.Find(id);
if (modal === null) {
return;
}
let pos = 0;
for (let i=0; i<a.#sizeList.length; i++) {
if (modal.Modal.classList.contains(a.#sizeList[i])) {
modal.Modal.classList.remove(a.#sizeList[i]);
pos = i;
break;
}
}
pos++;
if (pos > (a.#sizeList.length - 1)) {
pos = 0;
}
modal.Modal.classList.add(a.#sizeList[pos]);
}
}
var BSDialog5 = new BSDialog05();

4
bsdialog5.min.js vendored

File diff suppressed because one or more lines are too long