2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2020-10-14 05:08:46 -04:00
|
|
|
import { hide } from '~/tooltips';
|
2018-03-09 15:18:59 -05:00
|
|
|
|
2018-10-24 15:17:03 -04: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);
|
|
|
|
el.setAttribute('data-container', 'body');
|
|
|
|
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]
|
|
|
|
.filter(el => !el.classList.contains('dropdown'))
|
2017-09-06 06:55:23 -04:00
|
|
|
.map(el => el.querySelector('a'))
|
|
|
|
.filter(el => el);
|
2017-08-17 09:00:50 -04:00
|
|
|
const $expander = $('.js-breadcrumbs-collapsed-expander');
|
2017-08-16 08:13:34 -04:00
|
|
|
|
2017-08-17 09:00:50 -04:00
|
|
|
topLevelLinks.forEach(el => addTooltipToEl(el));
|
|
|
|
|
2018-10-24 15:17:03 -04:00
|
|
|
$expander.closest('.dropdown').on('show.bs.dropdown hide.bs.dropdown', e => {
|
2020-10-14 05:08:46 -04:00
|
|
|
const $el = $('.js-breadcrumbs-collapsed-expander', e.currentTarget);
|
|
|
|
|
|
|
|
$el.toggleClass('open');
|
|
|
|
|
|
|
|
hide($el);
|
2018-10-24 15:17:03 -04:00
|
|
|
});
|
2017-08-17 09:00:50 -04:00
|
|
|
}
|
2017-08-16 08:13:34 -04:00
|
|
|
};
|