]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - js/bs-modal.js
2fea1da7a44c1c43416149a70ad85fe42c8535c2
2 * Generate a bootstrap modal
4 * @param {string} title - The modal title
5 * @param {string} body - HTML for the body
6 * @param {string} footer - HTML for the footer
9 * @param {string|null} size - the bootstrap size category for modals (sm, lg, xl). Default is null.
10 * @param {boolean} static - whether or not to make the backdrop static, forcing the user to respond to the dialog. Default is false
11 * @param {boolean} show - whether or not to automatically show the modal. Default is false.
12 * @param {boolean} closebutton - display and allow the close button. Default is true.
13 * @returns {string} returns the ID
16 function bsModal(title
, body
, footer
, size
= null, static = false, show
= false, closebutton
= true)
18 /* generate a random number between 1000 and 90000 to use as an id */
21 id
= Date
.now().toString(36); // base36 unique id
24 ourSize
+= "modal-" + size
;
26 const m1
= document
.createElement("div");
27 const m2
= m1
.cloneNode();
28 const m3
= m1
.cloneNode();
29 const mHeader
= m1
.cloneNode();
30 const mBody
= m1
.cloneNode();
31 const mFooter
= m1
.cloneNode();
33 m1
.classList
.add("modal", "fade");
36 m1
.ariaHidden
= "true";
38 m2
.classList
.add("modal-dialog", "modal-dialog-centered");
40 m2
.classList
.add(ourSize
);
45 m3
.classList
.add("modal-content");
48 mHeader
.classList
.add("modal-header");
49 mHeader
.id
= id
+ "-header";
50 mHeader
.innerHTML
=`<h5 class="modal-title" id="` + id
+ `"-title">` + title
+ `</h5>`;
53 mHeader
.innerHTML
+= `<button type="button" class="close" data-dismiss="modal" aria-label="Close">
54 <span aria-hidden="true">×</span></button>`;
56 mBody
.classList
.add("modal-body");
57 mBody
.id
= id
+ "-body";
58 mBody
.innerHTML
= body
;
60 mFooter
.classList
.add("modal-footer");
61 mFooter
.id
= id
+ "-footer";
62 mFooter
.innerHTML
= footer
;
66 m3
.appendChild(mHeader
);
67 m3
.appendChild(mBody
);
68 m3
.appendChild(mFooter
);
70 document
.body
.append(m1
);
73 $('#' + m1
.id
).modal({ backdrop: "static" });
76 $('#' + m1
.id
).modal('show');