Skip to content
Snippets Groups Projects
Commit 074c7fbb authored by Teal Bauer's avatar Teal Bauer
Browse files

fix: Ensure JS event listeners use turbo:load

Replaces DOMContentLoaded with turbo:load in several views
to ensure JavaScript behaviors (like toggles, modals, and tabs)
are correctly initialized after Turbo Drive navigations.

This addresses issues where UI elements would not function
correctly after a Turbo navigation until a full page reload.

Affected files:
- app/views/devise/registrations/edit.html.erb
- app/views/admin/conferences/import_history.html.erb
- app/views/shared/_admin_nav.html.erb
- app/views/layouts/application.html.erb
- app/views/admin/conferences/import_progress.html.erb
- app/views/assignments/by_user.html.erb

Cleaned up redundant listeners in application.html.erb and
_admin_nav.html.erb.
parent 37bfd82d
Branches
No related tags found
No related merge requests found
......@@ -116,7 +116,7 @@
</template>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('turbo:load', function() {
document.querySelectorAll('[data-action="view-error"]').forEach(function(button) {
button.addEventListener('click', function() {
const errorContent = this.getAttribute('data-error');
......
......@@ -62,6 +62,6 @@
});
}
document.addEventListener('DOMContentLoaded', checkImportStatus);
document.addEventListener('turbo:load', checkImportStatus);
</script>
</div>
......@@ -94,7 +94,7 @@
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('turbo:load', function() {
const tabButtons = document.querySelectorAll('[data-tabs-target]');
const tabContents = document.querySelectorAll('[role="tabpanel"]');
......
......@@ -110,7 +110,7 @@
<script>
// Toggle password fields
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('turbo:load', function() {
const togglePasswordBtn = document.getElementById('togglePasswordFields');
const passwordFields = document.getElementById('passwordFields');
......
......@@ -245,21 +245,11 @@
// Set user signed in state for JS
window.userSignedIn = <%= user_signed_in? %>;
// Initialize on DOMContentLoaded
document.addEventListener('DOMContentLoaded', () => {
initializeThemeToggle();
initializeNavMenus();
});
// Re-initialize on Turbo navigation
document.addEventListener('turbo:load', () => {
initializeThemeToggle();
initializeNavMenus();
});
document.addEventListener('turbo:render', () => {
initializeThemeToggle();
initializeNavMenus();
});
</script>
<main>
......
......@@ -84,11 +84,7 @@
}
}
// Initialize on DOMContentLoaded
document.addEventListener('DOMContentLoaded', initializeAdminNavMenu);
// Re-initialize on Turbo navigation
// Initialize on Turbo page load
document.addEventListener('turbo:load', initializeAdminNavMenu);
document.addEventListener('turbo:render', initializeAdminNavMenu);
</script>
</header>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment