Skip to content
Snippets Groups Projects
Commit 636c36bb authored by Tim Zallmann's avatar Tim Zallmann
Browse files

Improved Performance by delaying Tooltip setup for localtimeago

parent 227ce776
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -125,6 +125,7 @@ export const getTimeago = () => {
 
timeago.register(timeagoLanguageCode, locale);
timeago.register(`${timeagoLanguageCode}-remaining`, localeRemaining);
timeagoInstance = timeago();
}
 
Loading
Loading
@@ -142,6 +143,19 @@ export const renderTimeago = $els => {
getTimeago().render(timeagoEls, timeagoLanguageCode);
};
 
/**
* For the given elements, will add timeago tooltips
*/
export const addTimeAgoTooltip = () => {
const timeagoEls = document.querySelectorAll('.js-timeago-render');
timeagoEls.forEach(element => {
$(element).tooltip({
template:
'<div class="tooltip local-timeago" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>',
});
});
};
/**
* For the given elements, sets a tooltip with a formatted date.
* @param {jQuery}
Loading
Loading
@@ -149,18 +163,14 @@ export const renderTimeago = $els => {
*/
export const localTimeAgo = ($timeagoEls, setTimeago = true) => {
$timeagoEls.each((i, el) => {
if (setTimeago) {
// Recreate with custom template
$(el).tooltip({
template:
'<div class="tooltip local-timeago" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>',
});
}
el.classList.add('js-timeago-render');
});
 
renderTimeago($timeagoEls);
if (setTimeago) {
requestIdleCallback(addTimeAgoTooltip);
}
};
 
/**
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment