gitlab-org--gitlab-foss/app/assets/javascripts/breadcrumb.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
export const addTooltipToEl = (el) => {
const textEl = el.querySelector('.js-breadcrumb-item-text');
if (textEl && textEl.scrollWidth > textEl.offsetWidth) {
el.setAttribute('title', el.textContent);
el.setAttribute('data-container', 'body');
el.classList.add('has-tooltip');
}
};
export default () => {
const breadcrumbs = document.querySelector('.js-breadcrumbs-list');
2017-08-17 09:00:50 -04:00
if (breadcrumbs) {
2018-10-24 15:17:03 -04:00
const topLevelLinks = [...breadcrumbs.children]
.filter((el) => !el.classList.contains('dropdown'))
.map((el) => el.querySelector('a'))
.filter((el) => el);
const $expanderBtn = $('.js-breadcrumbs-collapsed-expander');
topLevelLinks.forEach((el) => addTooltipToEl(el));
2017-08-17 09:00:50 -04:00
$expanderBtn.on('click', () => {
const detailItems = $('.breadcrumbs-detail-item');
const hiddenClass = 'gl-display-none!';
$.each(detailItems, (_key, item) => {
$(item).toggleClass(hiddenClass);
});
// 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
}
};