summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Zallmann <tzallmann@gitlab.com>2019-01-15 16:00:05 +0100
committerTim Zallmann <tzallmann@gitlab.com>2019-01-21 17:56:44 +0100
commit636c36bbbfa2c0691d46c7d5fb1315a9c9ae869a (patch)
tree04ac1e2edaf01cafe6eb50a31d298906929e8201
parent227ce776dcdaac35f6509d32428312ff0053de06 (diff)
downloadgitlab-ce-636c36bbbfa2c0691d46c7d5fb1315a9c9ae869a.tar.gz
Improved Performance by delaying Tooltip setup for localtimeago
-rw-r--r--app/assets/javascripts/lib/utils/datetime_utility.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/app/assets/javascripts/lib/utils/datetime_utility.js b/app/assets/javascripts/lib/utils/datetime_utility.js
index 01dbbb9dd16..5bb2efdb18d 100644
--- a/app/assets/javascripts/lib/utils/datetime_utility.js
+++ b/app/assets/javascripts/lib/utils/datetime_utility.js
@@ -125,6 +125,7 @@ export const getTimeago = () => {
timeago.register(timeagoLanguageCode, locale);
timeago.register(`${timeagoLanguageCode}-remaining`, localeRemaining);
+
timeagoInstance = timeago();
}
@@ -143,24 +144,33 @@ export const renderTimeago = $els => {
};
/**
+ * 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}
* @param {Boolean} setTimeago
*/
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);
+ }
};
/**