summaryrefslogtreecommitdiff
path: root/app/static/js
diff options
context:
space:
mode:
authorstilbruch <stilbruch@protonmail.com>2022-04-06 15:54:13 -0500
committerstilbruch <stilbruch@protonmail.com>2022-04-06 15:54:13 -0500
commit73b96155fcd54b958fe8c676db028fd4fc4fabe4 (patch)
tree463889ee607c060c36404df88a6eca88146c3204 /app/static/js
parenta15316714eed4c8051bd84917a126f104e3ed293 (diff)
downloadStrengthy-73b96155fcd54b958fe8c676db028fd4fc4fabe4.tar.xz
Strengthy-73b96155fcd54b958fe8c676db028fd4fc4fabe4.zip
Add confirmation modal for deleting a workout
Diffstat (limited to 'app/static/js')
-rw-r--r--app/static/js/bulma.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/static/js/bulma.js b/app/static/js/bulma.js
new file mode 100644
index 0000000..49b9b93
--- /dev/null
+++ b/app/static/js/bulma.js
@@ -0,0 +1,42 @@
+// Functions to open and close a modal
+function openModal($el) {
+ $el.classList.add('is-active');
+}
+
+function closeModal($el) {
+ $el.classList.remove('is-active');
+}
+
+function closeAllModals() {
+ (document.querySelectorAll('.modal') || []).forEach(($modal) => {
+ closeModal($modal);
+ });
+}
+
+// Add a click event on buttons to open a specific modal
+(document.querySelectorAll('.js-modal-trigger') || []).forEach(($trigger) => {
+ const modal = $trigger.dataset.target;
+ const $target = document.getElementById(modal);
+
+ $trigger.addEventListener('click', () => {
+ openModal($target);
+ });
+});
+
+// Add a click event on various child elements to close the parent modal
+(document.querySelectorAll('.modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button') || []).forEach(($close) => {
+ const $target = $close.closest('.modal');
+
+ $close.addEventListener('click', () => {
+ closeModal($target);
+ });
+});
+
+// Add a keyboard event to close all modals
+document.addEventListener('keydown', (event) => {
+ const e = event || window.event;
+
+ if (e.keyCode === 27) { // Escape key
+ closeAllModals();
+ }
+});