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

35 lines
988 B
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2021-01-03 14:25:43 +05:30
import { hide } from '~/tooltips';
2018-05-09 12:01:36 +05:30
2018-12-13 13:39:08 +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);
el.setAttribute('data-container', 'body');
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]
.filter(el => !el.classList.contains('dropdown'))
2018-03-17 18:26:18 +05:30
.map(el => el.querySelector('a'))
.filter(el => el);
const $expander = $('.js-breadcrumbs-collapsed-expander');
topLevelLinks.forEach(el => addTooltipToEl(el));
2018-12-13 13:39:08 +05:30
$expander.closest('.dropdown').on('show.bs.dropdown hide.bs.dropdown', e => {
2021-01-03 14:25:43 +05:30
const $el = $('.js-breadcrumbs-collapsed-expander', e.currentTarget);
$el.toggleClass('open');
hide($el);
2018-12-13 13:39:08 +05:30
});
2018-03-17 18:26:18 +05:30
}
};