Retrospring/app/javascript/retrospring/initializers/bootstrap.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-01-04 03:23:00 -08:00
import * as bootstrap from 'bootstrap';
/**
* This module sets up Bootstrap's JavaScript
*
* Inside of the exported function below, initialize Bootstrap
* modules that require explicit initilization, like tooltips
*/
export default function (): void {
document.addEventListener('turbo:load', () => {
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
2023-01-04 08:31:19 -08:00
[...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
2023-01-04 03:23:00 -08:00
const dropdownElementList = document.querySelectorAll('.dropdown-toggle');
2023-01-04 08:31:19 -08:00
[...dropdownElementList].map(dropdownToggleEl => new bootstrap.Dropdown(dropdownToggleEl));
2023-01-04 13:57:45 -08:00
// HACK/BUG?: Bootstrap disables dropdowns in navbars, here we re-enable and "kinda" fix it
// By the time Bootstrap 6 releases this probably won't be needed anymore
const navigationElementList = document.querySelectorAll('#rs-mobile-nav .nav-link[data-bs-toggle="dropdown"]');
[...navigationElementList].map(dropdownToggleEl => new bootstrap.Dropdown(dropdownToggleEl, {
popperConfig(defaultPopperConfig) {
return {
...defaultPopperConfig,
strategy: 'fixed',
modifiers: [
{
name: 'applyStyles',
enabled: true
},
{
name: 'preventOverflow',
options: {
boundary: document.querySelector('body')
}
},
]
}
}
}));
2023-01-04 03:23:00 -08:00
});
}