Initialize Bootstrap in TypeScript

This commit is contained in:
Andreas Nedbal 2023-01-04 12:23:00 +01:00 committed by Andreas Nedbal
parent 5612f8d2bd
commit a00936f17e
2 changed files with 18 additions and 15 deletions

View File

@ -1,15 +0,0 @@
import 'bootstrap';
import $ from 'jquery';
/**
* 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).ready(() => {
$('[data-toggle="tooltip"]').tooltip();
$('.dropdown-toggle').dropdown();
});
}

View File

@ -0,0 +1,18 @@
import * as Popper from '@popperjs/core';
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"]');
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
const dropdownElementList = document.querySelectorAll('.dropdown-toggle');
const dropdownList = [...dropdownElementList].map(dropdownToggleEl => new bootstrap.Dropdown(dropdownToggleEl));
});
}