From 3d962822c68c7fe4d757afb25217059d500335ce Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 17 Aug 2015 16:26:35 -0400 Subject: [PATCH] #3322 properly, @barisusakli so no need to copy pasta everywhere timeago is used --- public/src/app.js | 6 +++--- public/src/client/topic/posts.js | 4 +--- public/src/utils.js | 9 +++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 606277f467..5bcbb8201d 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -241,9 +241,9 @@ app.cacheBuster = null; app.processPage = function () { highlightNavigationLink(); - $('.timeago').timeago().each(function() { - $(this).attr('title', (new Date($(this).attr('title'))).toString()); - }); + utils.overrideTimeago(); + + $('.timeago').timeago(); utils.makeNumbersHumanReadable($('.human-readable-number')); diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 4ad5d3ad60..6532ae648c 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -255,9 +255,7 @@ define('forum/topic/posts', [ app.replaceSelfLinks(posts.find('a')); utils.addCommasToNumbers(posts.find('.formatted-number')); utils.makeNumbersHumanReadable(posts.find('.human-readable-number')); - posts.find('.timeago').timeago().each(function() { - $(this).attr('title', (new Date($(this).attr('title'))).toString()); - }); + posts.find('.timeago').timeago(); posts.find('[component="post/content"] img:not(.emoji)').each(function() { var $this = $(this); if (!$this.parent().is('a')) { diff --git a/public/src/utils.js b/public/src/utils.js index 930e03501f..66ee10f6cf 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -203,6 +203,15 @@ return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); }, + overrideTimeago: function() { + var timeagoFn = $.fn.timeago; + $.fn.timeago = function() { + timeagoFn.apply(this, arguments).each(function() { + $(this).attr('title', (new Date($(this).attr('title'))).toString()); + }); + }; + }, + toISOString: function(timestamp) { if (!timestamp || !Date.prototype.toISOString) { return '';