Skip to content

Node.js based forum software built for the modern web

partial revert of a9984bb, adding in a layer to translate ISO timestamp to datetime attribute and save localised string into title attribute.

Julian Lam75ff60e4d547
diff --git a/public/src/overrides.js b/public/src/overrides.js
index a2d213f45c..af8d80f659 100644
--- a/public/src/overrides.js
+++ b/public/src/overrides.js
@@ -152,13 +152,18 @@ if ('undefined' !== typeof window) {
var timeagoFn = $.fn.timeago;
$.timeago.settings.cutoff = 1000 * 60 * 60 * 24 * 30;
$.fn.timeago = function () {
- var els = timeagoFn.apply(this, arguments);
+ var els = $(this);
+
+ // Convert "old" format to new format (#5108)
+ var options = { year: 'numeric', month: 'long', day: 'numeric' };
+ var iso;
+ els.each(function() {
+ iso = this.getAttribute('title');
+ this.setAttribute('datetime', iso);
+ this.setAttribute('title', new Date(iso).toLocaleString(config.userLang.replace('_', '-'), options));
+ });
- if (els) {
- els.each(function () {
- $(this).attr('title', (new Date($(this).attr('title'))).toString());
- });
- }
+ timeagoFn.apply(this, arguments);
};
};
diff --git a/public/vendor/jquery/timeago/jquery.timeago.js b/public/vendor/jquery/timeago/jquery.timeago.js
index 8727fa7adb..c85ebcc5b0 100644
--- a/public/vendor/jquery/timeago/jquery.timeago.js
+++ b/public/vendor/jquery/timeago/jquery.timeago.js
@@ -194,41 +194,7 @@
$(this).text(inWords(data.datetime));
} else {
if ($(this).attr('title').length > 0) {
- //$(this).text($(this).attr('title'));
- var languageCode = void 0;
- switch (config.userLang) {
- case 'en_GB':
- case 'en_US':
- languageCode = 'en';
- break;
-
- case 'fa_IR':
- languageCode = 'fa';
- break;
-
- case 'pt_BR':
- languageCode = 'pt-br';
- break;
-
- case 'nb':
- languageCode = 'no';
- break;
-
- case 'zh_TW':
- languageCode = 'zh-TW';
- break;
-
- case 'zh_CN':
- languageCode = 'zh-CN';
- break;
-
- default:
- languageCode = config.userLang;
- break;
- }
-
- var options = { year: 'numeric', month: 'long', day: 'numeric' };
- $(this).text(new Date($(this).attr('title')).toLocaleString(languageCode, options));
+ $(this).text($(this).attr('title'));
}
}
}