debian-mirror-gitlab/app/assets/javascripts/breadcrumb.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2021-03-08 18:12:59 +05:30
export const addTooltipToEl = (el) => {
2018-03-17 18:26:18 +05:30
const textEl = el.querySelector('.js-breadcrumb-item-text');
if (textEl && textEl.scrollWidth > textEl.offsetWidth) {
el.setAttribute('title', el.textContent);
2022-07-23 23:45:48 +05:30
el.dataset.container = 'body';
2018-03-17 18:26:18 +05:30
el.classList.add('has-tooltip');
}
};
export default () => {
const breadcrumbs = document.querySelector('.js-breadcrumbs-list');
if (breadcrumbs) {
2018-12-13 13:39:08 +05:30
const topLevelLinks = [...breadcrumbs.children]
2021-03-08 18:12:59 +05:30
.filter((el) => !el.classList.contains('dropdown'))
.map((el) => el.querySelector('a'))
.filter((el) => el);
2021-12-11 22:18:48 +05:30
const $expanderBtn = $('.js-breadcrumbs-collapsed-expander');
2018-03-17 18:26:18 +05:30
2021-03-08 18:12:59 +05:30
topLevelLinks.forEach((el) => addTooltipToEl(el));
2018-03-17 18:26:18 +05:30
2021-12-11 22:18:48 +05:30
$expanderBtn.on('click', () => {
const detailItems = $('.breadcrumbs-detail-item');
const hiddenClass = 'gl-display-none!';
2021-01-03 14:25:43 +05:30
2021-12-11 22:18:48 +05:30
$.each(detailItems, (_key, item) => {
$(item).toggleClass(hiddenClass);
});
2021-01-03 14:25:43 +05:30
2021-12-11 22:18:48 +05:30
// remove the ellipsis
$('li.expander').remove();
// set focus on first breadcrumb item
$('.breadcrumb-item-text').first().focus();
2018-12-13 13:39:08 +05:30
});
2018-03-17 18:26:18 +05:30
}
};