Issue #3079738 by lauriii, saschaeggi, webchick, xjm, andrewmacpherson, shimpy, effulgentsia, Wim Leers, DyanneNova, svettes, rainbreaw, fhaeberle, ckrina, AaronMcHale, justafish, catch, charlieweb82, AntoineH, lot007, pzajacz, kostyashupenko, jasonbarrie, antonellasevero, finnsky, worldlinemine, bnjmnm, RobLoach, Dennis Cohn, huzooka, Archita Arora, joachim, jrockowitz, benjifisher, shaal, Gábor Hojtsy, quiron, L2G2, ccasals, hampercm, if-jds, abhisekmazumdar, Kami Amiga, pivica, zrpnr, BrightBold, imalabya, jhedstrom, Neslee Canil Pinto, maliknaik, junaidmasoodi, Maithri Shetty, pranav73, mandclu, modulist, nod_, philosurfer, phenaproxima, mherchel, mlncn, rafuel92, leymannx, kiboman, Swapnil_Kotwal, anevins, evankay, rfmarcelino, thamas, brianperry, idebr, joelpittet, boulaffasae, alexpott, volkerk, DuneBL, Eli-T, Mahenkvyas22: Add Claro administration theme to core
2019-10-13 20:42:58 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Responsive navigation tabs.
|
|
|
|
*
|
|
|
|
* This also supports collapsible navigable is the 'is-collapsible' class is
|
|
|
|
* added to the main element, and a target element is included.
|
|
|
|
*/
|
|
|
|
(($, Drupal) => {
|
2021-08-10 10:05:02 +00:00
|
|
|
function init(tab) {
|
Issue #3079738 by lauriii, saschaeggi, webchick, xjm, andrewmacpherson, shimpy, effulgentsia, Wim Leers, DyanneNova, svettes, rainbreaw, fhaeberle, ckrina, AaronMcHale, justafish, catch, charlieweb82, AntoineH, lot007, pzajacz, kostyashupenko, jasonbarrie, antonellasevero, finnsky, worldlinemine, bnjmnm, RobLoach, Dennis Cohn, huzooka, Archita Arora, joachim, jrockowitz, benjifisher, shaal, Gábor Hojtsy, quiron, L2G2, ccasals, hampercm, if-jds, abhisekmazumdar, Kami Amiga, pivica, zrpnr, BrightBold, imalabya, jhedstrom, Neslee Canil Pinto, maliknaik, junaidmasoodi, Maithri Shetty, pranav73, mandclu, modulist, nod_, philosurfer, phenaproxima, mherchel, mlncn, rafuel92, leymannx, kiboman, Swapnil_Kotwal, anevins, evankay, rfmarcelino, thamas, brianperry, idebr, joelpittet, boulaffasae, alexpott, volkerk, DuneBL, Eli-T, Mahenkvyas22: Add Claro administration theme to core
2019-10-13 20:42:58 +00:00
|
|
|
const $tab = $(tab);
|
|
|
|
const $target = $tab.find('[data-drupal-nav-tabs-target]');
|
|
|
|
const $active = $target.find('.js-active-tab');
|
|
|
|
|
|
|
|
const openMenu = () => {
|
|
|
|
$target.toggleClass('is-open');
|
|
|
|
};
|
|
|
|
|
2020-10-21 10:41:33 +00:00
|
|
|
const toggleOrder = (reset) => {
|
Issue #3079738 by lauriii, saschaeggi, webchick, xjm, andrewmacpherson, shimpy, effulgentsia, Wim Leers, DyanneNova, svettes, rainbreaw, fhaeberle, ckrina, AaronMcHale, justafish, catch, charlieweb82, AntoineH, lot007, pzajacz, kostyashupenko, jasonbarrie, antonellasevero, finnsky, worldlinemine, bnjmnm, RobLoach, Dennis Cohn, huzooka, Archita Arora, joachim, jrockowitz, benjifisher, shaal, Gábor Hojtsy, quiron, L2G2, ccasals, hampercm, if-jds, abhisekmazumdar, Kami Amiga, pivica, zrpnr, BrightBold, imalabya, jhedstrom, Neslee Canil Pinto, maliknaik, junaidmasoodi, Maithri Shetty, pranav73, mandclu, modulist, nod_, philosurfer, phenaproxima, mherchel, mlncn, rafuel92, leymannx, kiboman, Swapnil_Kotwal, anevins, evankay, rfmarcelino, thamas, brianperry, idebr, joelpittet, boulaffasae, alexpott, volkerk, DuneBL, Eli-T, Mahenkvyas22: Add Claro administration theme to core
2019-10-13 20:42:58 +00:00
|
|
|
const current = $active.index();
|
|
|
|
const original = $active.data('original-order');
|
|
|
|
|
|
|
|
// Do not change order if already first or if already reset.
|
|
|
|
if (original === 0 || reset === (current === original)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const siblings = {
|
|
|
|
first: '[data-original-order="0"]',
|
|
|
|
previous: `[data-original-order="${original - 1}"]`,
|
|
|
|
};
|
|
|
|
|
|
|
|
const $first = $target.find(siblings.first);
|
|
|
|
const $previous = $target.find(siblings.previous);
|
|
|
|
|
|
|
|
if (reset && current !== original) {
|
|
|
|
$active.insertAfter($previous);
|
|
|
|
} else if (!reset && current === original) {
|
|
|
|
$active.insertBefore($first);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const toggleCollapsed = () => {
|
|
|
|
if (window.matchMedia('(min-width: 48em)').matches) {
|
|
|
|
if ($tab.hasClass('is-horizontal') && !$tab.attr('data-width')) {
|
|
|
|
let width = 0;
|
|
|
|
|
|
|
|
$target.find('.js-tabs-link').each((index, value) => {
|
|
|
|
width += $(value).outerWidth();
|
|
|
|
});
|
|
|
|
$tab.attr('data-width', width);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collapse the tabs if the combined width of the tabs is greater than
|
|
|
|
// the width of the parent container.
|
|
|
|
const isHorizontal = $tab.attr('data-width') <= $tab.outerWidth();
|
|
|
|
$tab.toggleClass('is-horizontal', isHorizontal);
|
|
|
|
toggleOrder(isHorizontal);
|
|
|
|
} else {
|
|
|
|
toggleOrder(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$tab.addClass('position-container is-horizontal-enabled');
|
|
|
|
|
|
|
|
$target.find('.js-tab').each((index, element) => {
|
|
|
|
const $item = $(element);
|
|
|
|
$item.attr('data-original-order', $item.index());
|
|
|
|
});
|
|
|
|
|
|
|
|
$tab.on('click.tabs', '[data-drupal-nav-tabs-trigger]', openMenu);
|
|
|
|
$(window)
|
2021-08-10 10:05:02 +00:00
|
|
|
// @todo use a media query event listener https://www.drupal.org/project/drupal/issues/3225621
|
Issue #3079738 by lauriii, saschaeggi, webchick, xjm, andrewmacpherson, shimpy, effulgentsia, Wim Leers, DyanneNova, svettes, rainbreaw, fhaeberle, ckrina, AaronMcHale, justafish, catch, charlieweb82, AntoineH, lot007, pzajacz, kostyashupenko, jasonbarrie, antonellasevero, finnsky, worldlinemine, bnjmnm, RobLoach, Dennis Cohn, huzooka, Archita Arora, joachim, jrockowitz, benjifisher, shaal, Gábor Hojtsy, quiron, L2G2, ccasals, hampercm, if-jds, abhisekmazumdar, Kami Amiga, pivica, zrpnr, BrightBold, imalabya, jhedstrom, Neslee Canil Pinto, maliknaik, junaidmasoodi, Maithri Shetty, pranav73, mandclu, modulist, nod_, philosurfer, phenaproxima, mherchel, mlncn, rafuel92, leymannx, kiboman, Swapnil_Kotwal, anevins, evankay, rfmarcelino, thamas, brianperry, idebr, joelpittet, boulaffasae, alexpott, volkerk, DuneBL, Eli-T, Mahenkvyas22: Add Claro administration theme to core
2019-10-13 20:42:58 +00:00
|
|
|
.on('resize.tabs', Drupal.debounce(toggleCollapsed, 150))
|
|
|
|
.trigger('resize.tabs');
|
|
|
|
}
|
|
|
|
/**
|
2020-05-29 11:25:47 +00:00
|
|
|
* Initialize the tabs JS.
|
Issue #3079738 by lauriii, saschaeggi, webchick, xjm, andrewmacpherson, shimpy, effulgentsia, Wim Leers, DyanneNova, svettes, rainbreaw, fhaeberle, ckrina, AaronMcHale, justafish, catch, charlieweb82, AntoineH, lot007, pzajacz, kostyashupenko, jasonbarrie, antonellasevero, finnsky, worldlinemine, bnjmnm, RobLoach, Dennis Cohn, huzooka, Archita Arora, joachim, jrockowitz, benjifisher, shaal, Gábor Hojtsy, quiron, L2G2, ccasals, hampercm, if-jds, abhisekmazumdar, Kami Amiga, pivica, zrpnr, BrightBold, imalabya, jhedstrom, Neslee Canil Pinto, maliknaik, junaidmasoodi, Maithri Shetty, pranav73, mandclu, modulist, nod_, philosurfer, phenaproxima, mherchel, mlncn, rafuel92, leymannx, kiboman, Swapnil_Kotwal, anevins, evankay, rfmarcelino, thamas, brianperry, idebr, joelpittet, boulaffasae, alexpott, volkerk, DuneBL, Eli-T, Mahenkvyas22: Add Claro administration theme to core
2019-10-13 20:42:58 +00:00
|
|
|
*/
|
|
|
|
Drupal.behaviors.navTabs = {
|
|
|
|
attach(context) {
|
2021-08-10 10:05:02 +00:00
|
|
|
once(
|
|
|
|
'nav-tabs',
|
|
|
|
'[data-drupal-nav-tabs].is-collapsible',
|
|
|
|
context,
|
|
|
|
).forEach(init);
|
Issue #3079738 by lauriii, saschaeggi, webchick, xjm, andrewmacpherson, shimpy, effulgentsia, Wim Leers, DyanneNova, svettes, rainbreaw, fhaeberle, ckrina, AaronMcHale, justafish, catch, charlieweb82, AntoineH, lot007, pzajacz, kostyashupenko, jasonbarrie, antonellasevero, finnsky, worldlinemine, bnjmnm, RobLoach, Dennis Cohn, huzooka, Archita Arora, joachim, jrockowitz, benjifisher, shaal, Gábor Hojtsy, quiron, L2G2, ccasals, hampercm, if-jds, abhisekmazumdar, Kami Amiga, pivica, zrpnr, BrightBold, imalabya, jhedstrom, Neslee Canil Pinto, maliknaik, junaidmasoodi, Maithri Shetty, pranav73, mandclu, modulist, nod_, philosurfer, phenaproxima, mherchel, mlncn, rafuel92, leymannx, kiboman, Swapnil_Kotwal, anevins, evankay, rfmarcelino, thamas, brianperry, idebr, joelpittet, boulaffasae, alexpott, volkerk, DuneBL, Eli-T, Mahenkvyas22: Add Claro administration theme to core
2019-10-13 20:42:58 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
})(jQuery, Drupal);
|