2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
export const addTooltipToEl = (el) => {
|
2017-09-06 06:55:23 -04:00
|
|
|
const textEl = el.querySelector('.js-breadcrumb-item-text');
|
|
|
|
|
|
|
|
if (textEl && textEl.scrollWidth > textEl.offsetWidth) {
|
2017-08-16 08:13:34 -04:00
|
|
|
el.setAttribute('title', el.textContent);
|
2022-06-17 11:08:29 -04:00
|
|
|
el.dataset.container = 'body';
|
2017-08-16 08:13:34 -04:00
|
|
|
el.classList.add('has-tooltip');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default () => {
|
2017-09-06 06:55:23 -04:00
|
|
|
const breadcrumbs = document.querySelector('.js-breadcrumbs-list');
|
2017-08-16 08:13:34 -04:00
|
|
|
|
2017-08-17 09:00:50 -04:00
|
|
|
if (breadcrumbs) {
|
2018-10-24 15:17:03 -04:00
|
|
|
const topLevelLinks = [...breadcrumbs.children]
|
2020-12-23 16:10:24 -05:00
|
|
|
.filter((el) => !el.classList.contains('dropdown'))
|
|
|
|
.map((el) => el.querySelector('a'))
|
|
|
|
.filter((el) => el);
|
2021-11-02 08:12:25 -04:00
|
|
|
const $expanderBtn = $('.js-breadcrumbs-collapsed-expander');
|
2017-08-16 08:13:34 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
topLevelLinks.forEach((el) => addTooltipToEl(el));
|
2017-08-17 09:00:50 -04:00
|
|
|
|
2021-11-02 08:12:25 -04:00
|
|
|
$expanderBtn.on('click', () => {
|
|
|
|
const detailItems = $('.breadcrumbs-detail-item');
|
|
|
|
const hiddenClass = 'gl-display-none!';
|
2020-10-14 05:08:46 -04:00
|
|
|
|
2021-11-02 08:12:25 -04:00
|
|
|
$.each(detailItems, (_key, item) => {
|
|
|
|
$(item).toggleClass(hiddenClass);
|
|
|
|
});
|
2020-10-14 05:08:46 -04:00
|
|
|
|
2021-11-02 08:12:25 -04:00
|
|
|
// remove the ellipsis
|
|
|
|
$('li.expander').remove();
|
|
|
|
|
|
|
|
// set focus on first breadcrumb item
|
|
|
|
$('.breadcrumb-item-text').first().focus();
|
2018-10-24 15:17:03 -04:00
|
|
|
});
|
2017-08-17 09:00:50 -04:00
|
|
|
}
|
2017-08-16 08:13:34 -04:00
|
|
|
};
|