Navbar menu input
- Define the
initialize
method.
initialize: function(el) {
// Construct the jQuery selector for the container element by its ID
let menuId = '#' + $(el).attr('id');
// Find the currently active tab within the container
let activeTab = $(`${menuId} .nav-link.active`);
// If at least one active tab is found
if (activeTab.length > 0) {
// Get the associated tab content's ID from the 'data-value' attribute
let tabId = $(activeTab).attr('data-value');
// Activate the tab using Bootstrap's tab API
// Remove the .active from other tabs
$(activeTab).tab('show');
// Make sure the corresponding tab content is also visible
$(`#${tabId}`).addClass('show active');
} else {
// If no active tab is found, activate the first tab in the menu
$(`${menuId} .nav-link`)
.first()
.tab('show');
}
}