Node.js based forum software built for the modern web
removed relativeTime util method, utils.js better be a C now.
Julian Lam99dc37bd9c5c
diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.jsindex 46e6833806..319d88041f 100644--- a/public/src/modules/notifications.js+++ b/public/src/modules/notifications.js@@ -25,11 +25,14 @@ define('notifications', ['sounds'], function(sound) {image = '';}- return '<li class="' + (notification.readClass || '') + '"><a href="' + (notification.path || '#') + '">' + image + '<span class="pull-right relTime">' + utils.relativeTime(notification.datetime, true) + '</span><span class="text">' + notification.bodyShort + '</span></a></li>';+ return '<li class="' + (notification.readClass || '') + '"><a href="' + (notification.path || '#') + '">' + image + '<span class="pull-right relTime">' + $.timeago(new Date(parseInt(notification.datetime, 10))) + '</span><span class="text">' + notification.bodyShort + '</span></a></li>';}var x, html = '';+ // Switch to shorthand+ translator.toggleTimeagoShorthand();+if (!err && (data.read.length + data.unread.length) > 0) {var image = '';for (x = 0; x < data.unread.length; x++) {@@ -43,6 +46,9 @@ define('notifications', ['sounds'], function(sound) {html += '<li class="no-notifs"><a>[[notifications:no_notifs]]</a></li>';}+ // Switch back to original timeago strings+ translator.toggleTimeagoShorthand();+html += '<li class="pagelink"><a href="' + config.relative_path + '/notifications">[[notifications:see_all]]</a></li>';notifList.translateHtml(html);diff --git a/public/src/translator.js b/public/src/translator.jsindex 07794f360c..5b052af216 100644--- a/public/src/translator.js+++ b/public/src/translator.js@@ -85,6 +85,34 @@}};+ translator.toggleTimeagoShorthand = function() {+ if (!translator.timeagoStrings) {+ translator.timeagoStrings = $.extend({}, jQuery.timeago.settings.strings);+ jQuery.timeago.settings.strings = {+ prefixAgo: null,+ prefixFromNow: null,+ suffixAgo: "",+ suffixFromNow: "",+ seconds: "1m",+ minute: "1m",+ minutes: "%dm",+ hour: "1h",+ hours: "%dh",+ day: "1d",+ days: "%dd",+ month: "1mo",+ months: "%dmo",+ year: "1yr",+ years: "%dyr",+ wordSeparator: " ",+ numbers: []+ };+ } else {+ jQuery.timeago.settings.strings = $.extend({}, translator.timeagoStrings);+ delete translator.timeagoStrings;+ }+ };+translator.translate = function (text, language, callback) {if (typeof language === 'function') {callback = language;diff --git a/public/src/utils.js b/public/src/utils.jsindex bdb8bf1a81..b9658593cc 100644--- a/public/src/utils.js+++ b/public/src/utils.js@@ -63,44 +63,6 @@});},- relativeTime: function(timestamp, min) {- var now = +new Date(),- difference = now - Math.floor(parseFloat(timestamp));-- if(difference < 0) {- difference = 0;- }-- difference = Math.floor(difference / 1000);-- if (difference < 60) {- return difference + (min ? 's' : ' second') + (difference !== 1 && !min ? 's' : '');- }-- difference = Math.floor(difference / 60);- if (difference < 60) {- return difference + (min ? 'm' : ' minute') + (difference !== 1 && !min ? 's' : '');- }-- difference = Math.floor(difference / 60);- if (difference < 24) {- return difference + (min ? 'h' : ' hour') + (difference !== 1 && !min ? 's' : '');- }-- difference = Math.floor(difference / 24);- if (difference < 30) {- return difference + (min ? 'd' : ' day') + (difference !== 1 && !min ? 's' : '');- }-- difference = Math.floor(difference / 30);- if (difference < 12) {- return difference + (min ? 'mon' : ' month') + (difference !== 1 && !min ? 's' : '');- }-- difference = Math.floor(difference / 12);- return difference + (min ? 'y' : ' year') + (difference !== 1 && !min ? 's' : '');- },-invalidUnicodeChars: XRegExp('[^\\p{L}\\s\\d\\-_]', 'g'),invalidLatinChars: /[^\w\s\d\-_]/g,trimRegex: /^\s+|\s+$/g,