aboutsummaryrefslogtreecommitdiffhomepage
path: root/ui/static/js/modal_handler.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/static/js/modal_handler.js')
-rw-r--r--ui/static/js/modal_handler.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/ui/static/js/modal_handler.js b/ui/static/js/modal_handler.js
new file mode 100644
index 0000000..c0e8b13
--- /dev/null
+++ b/ui/static/js/modal_handler.js
@@ -0,0 +1,31 @@
+class ModalHandler {
+ static exists() {
+ return document.getElementById("modal-container") !== null;
+ }
+
+ static open(fragment) {
+ if (ModalHandler.exists()) {
+ return;
+ }
+
+ let container = document.createElement("div");
+ container.id = "modal-container";
+ container.appendChild(document.importNode(fragment, true));
+ document.body.appendChild(container);
+
+ let closeButton = document.querySelector("a.btn-close-modal");
+ if (closeButton !== null) {
+ closeButton.onclick = (event) => {
+ event.preventDefault();
+ ModalHandler.close();
+ };
+ }
+ }
+
+ static close() {
+ let container = document.getElementById("modal-container");
+ if (container !== null) {
+ container.parentNode.removeChild(container);
+ }
+ }
+}