Rework to simplify and minimise jQuery dependency #1
26
bsdialog5.js
26
bsdialog5.js
@ -26,8 +26,8 @@ var BSDialog5 = {
|
||||
this.removeBackdrop();
|
||||
},
|
||||
Close: function (id) {
|
||||
let model = this.Find(id);
|
||||
if (model === null) {
|
||||
let modal = this.Find(id);
|
||||
if (modal === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -35,30 +35,30 @@ var BSDialog5 = {
|
||||
e.parentNode.removeChild(e);
|
||||
});
|
||||
|
||||
model = this.Find(id);
|
||||
if (model !== null) {
|
||||
modal = this.Find(id);
|
||||
if (modal !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.removeBackdrop();
|
||||
},
|
||||
UpdateTitle: function (id, title) {
|
||||
let model = this.Find(id);
|
||||
if (model === null) {
|
||||
let modal = this.Find(id);
|
||||
if (modal === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
model.Title.forEach(function(e) {
|
||||
modal.Title.forEach(function(e) {
|
||||
e.innerHTML = title;
|
||||
});
|
||||
},
|
||||
UpdateSize: function (id, size) {
|
||||
let model = this.Find(id);
|
||||
if (model === null) {
|
||||
let modal = this.Find(id);
|
||||
if (modal === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
model.Modal.forEach(function(e) {
|
||||
modal.Modal.forEach(function(e) {
|
||||
e.classList.remove("modal-sm");
|
||||
e.classList.remove("modal-md");
|
||||
e.classList.remove("modal-lg");
|
||||
@ -69,12 +69,12 @@ var BSDialog5 = {
|
||||
UpdateBody: function (id, content) {
|
||||
var a = this;
|
||||
|
||||
let model = a.Find(id);
|
||||
if (model === null) {
|
||||
let modal = a.Find(id);
|
||||
if (modal === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
model.Body.forEach(function(e) {
|
||||
modal.Body.forEach(function(e) {
|
||||
a.html(e, content);
|
||||
});
|
||||
},
|
||||
|
2
bsdialog5.min.js
vendored
2
bsdialog5.min.js
vendored
@ -2,4 +2,4 @@
|
||||
* BSDialog5
|
||||
* @version v0.1.1.063 (2023/07/275 1713)
|
||||
*/
|
||||
var BSDialog5={Create:async function(e,t,l,o){var d=this;d.pfx="bsdia5_",d.body=document.getElementsByTagName("body")[0],d.addBackdrop(),d.addModal(e,t,o),d.isNullOrWhitespace(l)?d.UpdateBody(e,""):await d.UpdateBodyRemote(e,l)},Clear:function(){this.body.querySelectorAll(".modal").forEach((function(e){e.parentNode.removeChild(e)})),this.removeBackdrop()},Close:function(e){let t=this.Find(e);null!==t&&(modal.Modal.forEach((function(e){e.parentNode.removeChild(e)})),t=this.Find(e),null===t&&this.removeBackdrop())},UpdateTitle:function(e,t){let l=this.Find(e);null!==l&&l.Title.forEach((function(e){e.innerHTML=t}))},UpdateSize:function(e,t){let l=this.Find(e);null!==l&&l.Modal.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-"+t)}))},UpdateBody:function(e,t){var l=this;let o=l.Find(e);null!==o&&o.Body.forEach((function(e){l.html(e,t)}))},UpdateBodyRemote:async function(e,t){var l=this;l.Exists(e)&&await fetch(t,{cache:"no-cache",credentials:"same-origin"}).then((e=>e.text())).then((t=>{l.UpdateBody(e,t)})).catch((t=>{l.UpdateBody(e,"Error: "+t)}))},Exists:function(e){return null!==this.Find(e)},Find:function(e){let t=this.body.querySelectorAll("#"+this.pfx+e+".modal");return t?t.length<=0?null:{Title:t[0].querySelectorAll(".modal-title"),Body:t[0].querySelectorAll(".modal-body"),Footer:t[0].querySelectorAll(".modal-footer"),Close:t[0].querySelectorAll("[data-bs-dismiss='modal']"),Modal:t}:null},ShowToast:function(e,t,l,o){this.Create(e,t,null,o),this.UpdateBody(e,l)},addBackdrop:function(){let e=this;e.body.querySelectorAll(".modal-backdrop").length>0||(e.appendHtml(e.body,'<div class="modal-backdrop fade show"></div>'),e.body.classList.add("modal-open"),e.body.style.overflow="hidden",e.body.querySelectorAll(".modal-backdrop")[0].addEventListener("click",(function(t){t.stopPropagation(),t.preventDefault(),e.Clear()})))},addModal:function(e,t,l){var o=this;let d=o.Find(e);if(null!==d)return;let a="";a+='<div class="modal modal-'+l+' fade show d-block" id="'+o.pfx+e+'" tabindex="-1" aria-modal="true" role="dialog">',a+=' <div class="modal-dialog">',a+=' <div class="modal-content">',a+=' <div class="modal-header">',a+=' <span class="modal-title fs-5">'+t+"</span>",a+=' <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>',a+=" </div>",a+=' <div class="modal-body">',a+='<div class="row mt-3 pb-3">',a+=' <div class="col-12 text-center">',a+=' <div class="spinner-border">',a+='\t <span class="visually-hidden">Loading...</span>',a+=" </div>",a+=" </div>",a+="</div>",a+=" </div>",a+=' <div class="modal-footer">',a+=' <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Close</button>',a+=" </div>",a+=" </div>",a+=" </div>",a+="</div>",o.appendHtml(o.body,a),d=o.Find(e),null!==d&&d.Close.forEach((function(t){t.addEventListener("click",(function(t){t.stopPropagation(),t.preventDefault(),o.Close(e)}))}))},removeBackdrop:function(){if(this.body.querySelectorAll(".modal-backdrop").length<=0)return;let e=this.body.querySelectorAll(".modal-backdrop")[0];e.parentNode.removeChild(e),this.body.classList.remove("modal-open"),this.body.style.overflow=null},appendHtml:function(e,t){let l=document.createElement("template");l.innerHTML=t,l=l.content.firstChild,e.appendChild(l)},html:function(e,t){jQuery?jQuery(e).html(t):e.innerHTML=t},isNullOrWhitespace:function(e){return void 0===e||(null==e||(0==e||e.trim().length<=0))}};
|
||||
var BSDialog5={Create:async function(e,t,l,o){var d=this;d.pfx="bsdia5_",d.body=document.getElementsByTagName("body")[0],d.addBackdrop(),d.addModal(e,t,o),d.isNullOrWhitespace(l)?d.UpdateBody(e,""):await d.UpdateBodyRemote(e,l)},Clear:function(){this.body.querySelectorAll(".modal").forEach((function(e){e.parentNode.removeChild(e)})),this.removeBackdrop()},Close:function(e){let t=this.Find(e);null!==t&&(t.Modal.forEach((function(e){e.parentNode.removeChild(e)})),t=this.Find(e),null===t&&this.removeBackdrop())},UpdateTitle:function(e,t){let l=this.Find(e);null!==l&&l.Title.forEach((function(e){e.innerHTML=t}))},UpdateSize:function(e,t){let l=this.Find(e);null!==l&&l.Modal.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-"+t)}))},UpdateBody:function(e,t){var l=this;let o=l.Find(e);null!==o&&o.Body.forEach((function(e){l.html(e,t)}))},UpdateBodyRemote:async function(e,t){var l=this;l.Exists(e)&&await fetch(t,{cache:"no-cache",credentials:"same-origin"}).then((e=>e.text())).then((t=>{l.UpdateBody(e,t)})).catch((t=>{l.UpdateBody(e,"Error: "+t)}))},Exists:function(e){return null!==this.Find(e)},Find:function(e){let t=this.body.querySelectorAll("#"+this.pfx+e+".modal");return t?t.length<=0?null:{Title:t[0].querySelectorAll(".modal-title"),Body:t[0].querySelectorAll(".modal-body"),Footer:t[0].querySelectorAll(".modal-footer"),Close:t[0].querySelectorAll("[data-bs-dismiss='modal']"),Modal:t}:null},ShowToast:function(e,t,l,o){this.Create(e,t,null,o),this.UpdateBody(e,l)},addBackdrop:function(){let e=this;e.body.querySelectorAll(".modal-backdrop").length>0||(e.appendHtml(e.body,'<div class="modal-backdrop fade show"></div>'),e.body.classList.add("modal-open"),e.body.style.overflow="hidden",e.body.querySelectorAll(".modal-backdrop")[0].addEventListener("click",(function(t){t.stopPropagation(),t.preventDefault(),e.Clear()})))},addModal:function(e,t,l){var o=this;let d=o.Find(e);if(null!==d)return;let a="";a+='<div class="modal modal-'+l+' fade show d-block" id="'+o.pfx+e+'" tabindex="-1" aria-modal="true" role="dialog">',a+=' <div class="modal-dialog">',a+=' <div class="modal-content">',a+=' <div class="modal-header">',a+=' <span class="modal-title fs-5">'+t+"</span>",a+=' <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>',a+=" </div>",a+=' <div class="modal-body">',a+='<div class="row mt-3 pb-3">',a+=' <div class="col-12 text-center">',a+=' <div class="spinner-border">',a+='\t <span class="visually-hidden">Loading...</span>',a+=" </div>",a+=" </div>",a+="</div>",a+=" </div>",a+=' <div class="modal-footer">',a+=' <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Close</button>',a+=" </div>",a+=" </div>",a+=" </div>",a+="</div>",o.appendHtml(o.body,a),d=o.Find(e),null!==d&&d.Close.forEach((function(t){t.addEventListener("click",(function(t){t.stopPropagation(),t.preventDefault(),o.Close(e)}))}))},removeBackdrop:function(){if(this.body.querySelectorAll(".modal-backdrop").length<=0)return;let e=this.body.querySelectorAll(".modal-backdrop")[0];e.parentNode.removeChild(e),this.body.classList.remove("modal-open"),this.body.style.overflow=null},appendHtml:function(e,t){let l=document.createElement("template");l.innerHTML=t,l=l.content.firstChild,e.appendChild(l)},html:function(e,t){jQuery?jQuery(e).html(t):e.innerHTML=t},isNullOrWhitespace:function(e){return void 0===e||(null==e||(0==e||e.trim().length<=0))}};
|
Loading…
Reference in New Issue
Block a user