44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
/**
|
|
* DO NOT EDIT THIS FILE.
|
|
* See the following change record for more information,
|
|
* https://www.drupal.org/node/2815083
|
|
* @preserve
|
|
**/
|
|
|
|
((Drupal, once) => {
|
|
function init(el) {
|
|
const tabs = el.querySelector('.tabs');
|
|
const expandedClass = 'is-expanded';
|
|
const activeTab = tabs.querySelector('.is-active');
|
|
|
|
function isTabsMobileLayout() {
|
|
return tabs.querySelector('.tabs__trigger').clientHeight > 0;
|
|
}
|
|
|
|
function handleTriggerClick(e) {
|
|
if (!tabs.classList.contains(expandedClass)) {
|
|
e.currentTarget.setAttribute('aria-expanded', 'true');
|
|
tabs.classList.add(expandedClass);
|
|
} else {
|
|
e.currentTarget.setAttribute('aria-expanded', 'false');
|
|
tabs.classList.remove(expandedClass);
|
|
}
|
|
}
|
|
|
|
if (isTabsMobileLayout() && !activeTab.matches('.tabs__tab:first-child')) {
|
|
const newActiveTab = activeTab.cloneNode(true);
|
|
const firstTab = tabs.querySelector('.tabs__tab:first-child');
|
|
tabs.insertBefore(newActiveTab, firstTab);
|
|
tabs.removeChild(activeTab);
|
|
}
|
|
|
|
tabs.querySelector('.tabs__trigger').addEventListener('click', handleTriggerClick);
|
|
}
|
|
|
|
Drupal.behaviors.primaryTabs = {
|
|
attach(context) {
|
|
once('olivero-tabs', '[data-drupal-nav-primary-tabs]', context).forEach(init);
|
|
}
|
|
|
|
};
|
|
})(Drupal, once); |