removed relativeTime util method, utils.js better be a C now.

v1.18.x
Julian Lam 10 years ago
parent d2938ea509
commit 99dc37bd9c

@ -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);

@ -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;

@ -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,

Loading…
Cancel
Save