/** * Provides functionality for tabbed interfaces. * * @since 2.2.5 * * @author ConvertKit */ /* eslint-disable no-unused-vars */ /** * Initializes tabbed interfaces. * * @since 2.2.5 */ function convertKitTabsInit() { // eslint-disable-line no-unused-vars // Safely call this function by destroying any previously initialized instances. convertKitTabsDestroy(); // Iterate through all JS tab instances, initializing each one. document .querySelectorAll('.convertkit-js-tabs') .forEach(function (navTabContainer) { const navTabPanelsContainer = navTabContainer.dataset.panelsContainer; const navTabPanel = navTabContainer.dataset.panel; const navTabActive = navTabContainer.dataset.active; // Call update. const activeTabElement = navTabContainer.querySelector( 'a.' + navTabActive ); convertKitTabsUpdate( navTabContainer, navTabPanelsContainer, navTabPanel, navTabActive, activeTabElement ? activeTabElement.getAttribute('href') : null ); // Register a listener when a tab is clicked. navTabContainer.addEventListener('click', function (e) { if (e.target.tagName === 'A') { e.preventDefault(); // Update the UI to show the active tab and content associated with it. convertKitTabsUpdate( navTabContainer, navTabPanelsContainer, navTabPanel, navTabActive, e.target.getAttribute('href') ); } }); }); } /* eslint-enable no-unused-vars */ /** * For the given active tab: * - Hides all other content in the group * - Shows content associated with the active tab * * @since 1.0.0 * * @param {Object} navTabContainer