Skip to content

Commit 74221fb

Browse files
authored
Refactor modal handling to use Bootstrap's JavaScript API instead of jQuery (#389)
1 parent b3ab2d8 commit 74221fb

File tree

7 files changed

+72
-22
lines changed

7 files changed

+72
-22
lines changed

backend/proteins/templates/proteins/_microscope_include.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{% if embeddable %}
2424
<span class='text-info' id="settings-button" data-bs-toggle="tooltip" data-bs-placement="right" title="Settings">{% icon "settings" data_bs_toggle="modal" data_bs_target="#settingsModal" %}</span>
2525
{% endif %}
26-
<span class='text-info' id="share-button" data-bs-toggle="tooltip" data-bs-placement="right" title="Share current configuration" data-bs-toggle="modal" data-bs-target="#shareModal">{% icon "share-square" %}</span>
26+
<span class='text-info' id="share-button" data-bs-toggle="tooltip" data-bs-placement="right" title="Share current configuration">{% icon "share-square" %}</span>
2727
<span class="pin-wrapper rotate-90" id="stickyPin" data-bs-toggle="tooltip" data-bs-placement="right" title="Keep spectra graph on top when scrolling">{% icon "thumbtack" %}</span>
2828
</div>
2929
<div class="btn-group btn-group-xs scale-btns" role="group">

backend/proteins/templates/proteins/protein_detail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ <h3>Transitions</h3>
222222
</div>
223223
<div class="align-self-end text-sm-end mt-1">
224224
<div class="align-self-end text-sm-end mt-1">
225-
<a href="#" class='text-info' data-bs-toggle="modal" id='show_transition_modal' data-action-url="{% url 'proteins:update_transitions' slug=protein.slug %}">
225+
<a href="#" class='text-info' id='show_transition_modal' data-action-url="{% url 'proteins:update_transitions' slug=protein.slug %}">
226226
<small class="d-none d-sm-inline">Edit state transitions</small>
227227
<button type="button" class="btn btn-info w-100 mt-3 d-block d-sm-none">{% icon "exchange" class_="me-2" %}Edit state transitions</button>
228228
</a>
@@ -232,7 +232,7 @@ <h3>Transitions</h3>
232232
{% endif %}
233233
{% if protein.states.count > 1 and protein.transitions.count == 0 %}
234234
<div class="align-self-end text-sm-end mt-1">
235-
<a href="#" class='text-info' data-bs-toggle="modal" id='show_transition_modal' data-action-url="{% url 'proteins:update_transitions' slug=protein.slug %}">
235+
<a href="#" class='text-info' id='show_transition_modal' data-action-url="{% url 'proteins:update_transitions' slug=protein.slug %}">
236236
<small class="d-none d-sm-inline">Edit state transitions</small>
237237
<button type="button" class="btn btn-info w-100 mt-3 d-block d-sm-none">{% icon "exchange" class_="me-2" %}Edit state transitions</button>
238238
</a>

frontend/src/css/_forms.scss

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,48 @@ i.arrow {
8080
}
8181
}
8282

83+
// Transition formset styling
84+
.trans_formset_div {
85+
.formset-form {
86+
display: flex;
87+
align-items: flex-end;
88+
gap: 0.5rem;
89+
margin-bottom: 0.75rem;
90+
padding-bottom: 0.75rem;
91+
border-bottom: 1px solid $gray-300;
92+
93+
&:last-of-type {
94+
border-bottom: none;
95+
}
96+
97+
.transition-col {
98+
flex: 1;
99+
}
100+
}
101+
102+
.transDelete {
103+
display: flex;
104+
align-items: center;
105+
justify-content: center;
106+
width: 2rem;
107+
height: 2rem;
108+
margin-bottom: 2.25rem; // Align with form inputs (accounting for help text)
109+
border-radius: 50%;
110+
color: $gray-500;
111+
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out;
112+
113+
&:hover {
114+
color: $danger;
115+
background-color: rgba($danger, 0.1);
116+
}
117+
118+
svg {
119+
width: 1.25rem;
120+
height: 1.25rem;
121+
}
122+
}
123+
}
124+
83125

84126

85127
#microscopeFormTabs {

frontend/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ document.addEventListener("DOMContentLoaded", () => {
229229

230230
// Show error modal if available
231231
const errorModal = document.getElementById("errorModal")
232-
if (errorModal && window.$ && window.$.fn.modal) {
233-
window.$(errorModal).modal("show")
232+
if (errorModal && window.bootstrap?.Modal) {
233+
bootstrap.Modal.getOrCreateInstance(errorModal).show()
234234
}
235235

236236
if (window.Sentry) {

frontend/src/js/project.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -767,15 +767,19 @@ $(() => {
767767
$("#transitionForm").html(data)
768768

769769
// Use Bootstrap's shown.bs.modal event to ensure modal is fully visible
770-
const $modal = $("#transitionModal")
770+
const transitionModalEl = document.getElementById("transitionModal")
771771
// Remove any previous handlers to avoid duplicates
772-
$modal.off("shown.bs.modal")
772+
$(transitionModalEl).off("shown.bs.modal")
773773
// Register formset AFTER modal is fully shown
774-
$modal.one("shown.bs.modal", () => {
775-
register_transition_form()
776-
})
774+
transitionModalEl.addEventListener(
775+
"shown.bs.modal",
776+
() => {
777+
register_transition_form()
778+
},
779+
{ once: true }
780+
)
777781
// Now show the modal (which will trigger the event above)
778-
$modal.modal()
782+
bootstrap.Modal.getOrCreateInstance(transitionModalEl).show()
779783
})
780784
.catch((error) => {
781785
console.error("Transition form fetch error:", error)
@@ -928,7 +932,7 @@ $(document).ready(() => {
928932
if (!$("#collectionSelect").length) {
929933
// only retrieve once
930934
$("#collectionSelection").prepend(data.widget)
931-
$("#collectionModal").modal()
935+
bootstrap.Modal.getOrCreateInstance(document.getElementById("collectionModal")).show()
932936
}
933937
})
934938
})
@@ -949,7 +953,7 @@ $(document).ready(() => {
949953
cache: "no-store",
950954
})
951955

952-
$("#collectionModal").modal("hide")
956+
bootstrap.Modal.getOrCreateInstance(document.getElementById("collectionModal")).hide()
953957
})
954958
})
955959

@@ -960,7 +964,7 @@ $(() => {
960964
.parent()
961965
.find(".select-add-button")
962966
.click(() => {
963-
$("#organismModal").modal()
967+
bootstrap.Modal.getOrCreateInstance(document.getElementById("organismModal")).show()
964968
})
965969

966970
$("#taxonomyModalForm").submit(function (e) {
@@ -990,7 +994,7 @@ $(() => {
990994
.then((_data) => {
991995
$(`<option value="${tax_id}">${sci_name} </option>`).appendTo("#id_parent_organism")
992996
$(`#id_parent_organism option[value="${tax_id}"]`).prop("selected", true)
993-
$("#organismModal").modal("hide")
997+
bootstrap.Modal.getOrCreateInstance(document.getElementById("organismModal")).hide()
994998
})
995999
} else {
9961000
$("#id_taxonomy_id").addClass("is-invalid")

frontend/src/microscope-form.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ $("#microscopeform").submit((e) => {
3838
})
3939
if (multidichroics.length > 0 || multiex.length > 0) {
4040
e.preventDefault()
41-
$("#sureModal")
42-
.one("hidden.bs.modal", () => {
41+
const sureModalEl = document.getElementById("sureModal")
42+
sureModalEl.addEventListener(
43+
"hidden.bs.modal",
44+
() => {
4345
if ($(document.activeElement).attr("id") === "save") {
4446
confirmError = false
4547
$("#microscopeform").submit()
4648
}
47-
})
48-
.modal()
49+
},
50+
{ once: true }
51+
)
52+
bootstrap.Modal.getOrCreateInstance(sureModalEl).show()
4953
}
5054
} else {
5155
$("#spinner").css("display", "inline")

frontend/src/microscope.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,8 @@ window.initMicroscope = () => {
851851

852852
$(".switchmodal").click((e) => {
853853
e.preventDefault()
854-
$("#settingsModal").modal("hide")
855-
$("#embedModal").modal("show")
854+
bootstrap.Modal.getOrCreateInstance(document.getElementById("settingsModal")).hide()
855+
bootstrap.Modal.getOrCreateInstance(document.getElementById("embedModal")).show()
856856
})
857857
})
858858

@@ -2021,7 +2021,7 @@ window.initMicroscope = () => {
20212021
const link = build_current_uri()
20222022
$("#shareLink").val(link)
20232023
$("#mailLink").attr("href", $("#mailLink").data("mailinfo") + encodeURIComponent(link))
2024-
$("#shareModal").modal("show")
2024+
bootstrap.Modal.getOrCreateInstance(document.getElementById("shareModal")).show()
20252025
})
20262026
})() // End of inner IIFE
20272027
}

0 commit comments

Comments
 (0)