diff options
author | Phil Hughes <me@iamphill.com> | 2017-06-30 16:01:01 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-06-30 16:01:01 +0000 |
commit | a6c02ce6b90026b605049784824276bb33f9e776 (patch) | |
tree | cc2a291b283631ec362fc040698bdb5b621bec83 | |
parent | 9db15d2a72f464156abaa4157db2b87601b36df6 (diff) | |
parent | def0f6281029659503f32c4b93e90ac6cbfd6884 (diff) | |
download | gitlab-ce-a6c02ce6b90026b605049784824276bb33f9e776.tar.gz |
Merge branch 'bpj-init-timeago-timeout-less-frequently' into 'master'
Remove initTimeagoTimeout and let timeago.js update timeagos internally.
Closes #34340
See merge request !12468
-rw-r--r-- | app/assets/javascripts/lib/utils/datetime_utility.js | 24 | ||||
-rw-r--r-- | app/assets/javascripts/main.js | 2 |
2 files changed, 4 insertions, 22 deletions
diff --git a/app/assets/javascripts/lib/utils/datetime_utility.js b/app/assets/javascripts/lib/utils/datetime_utility.js index bfcc50996cc..034a1ec2054 100644 --- a/app/assets/javascripts/lib/utils/datetime_utility.js +++ b/app/assets/javascripts/lib/utils/datetime_utility.js @@ -112,29 +112,11 @@ window.dateFormat = dateFormat; return timefor; }; - w.gl.utils.cachedTimeagoElements = []; w.gl.utils.renderTimeago = function($els) { - if (!$els && !w.gl.utils.cachedTimeagoElements.length) { - w.gl.utils.cachedTimeagoElements = [].slice.call(document.querySelectorAll('.js-timeago-render')); - } else if ($els) { - w.gl.utils.cachedTimeagoElements = w.gl.utils.cachedTimeagoElements.concat($els.toArray()); - } - - w.gl.utils.cachedTimeagoElements.forEach(gl.utils.updateTimeagoText); - }; - - w.gl.utils.updateTimeagoText = function(el) { - const formattedDate = gl.utils.getTimeago().format(el.getAttribute('datetime'), lang); - - if (el.textContent !== formattedDate) { - el.textContent = formattedDate; - } - }; - - w.gl.utils.initTimeagoTimeout = function() { - gl.utils.renderTimeago(); + const timeagoEls = $els || document.querySelectorAll('.js-timeago-render'); - gl.utils.timeagoTimeout = setTimeout(gl.utils.initTimeagoTimeout, 1000); + // timeago.js sets timeouts internally for each timeago value to be updated in real time + gl.utils.getTimeago().render(timeagoEls); }; w.gl.utils.getDayDifference = function(a, b) { diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index d27b4ec78c6..de1b658f602 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -358,7 +358,7 @@ $(function () { gl.awardsHandler = new AwardsHandler(); new Aside(); - gl.utils.initTimeagoTimeout(); + gl.utils.renderTimeago(); $(document).trigger('init.scrolling-tabs'); }); |