fix <time> semantics and add title attribute, closes #104

The browser shows a human-readable, absolute timestamp when hovering the
"time ago" element
This commit is contained in:
Martin Zimmermann 2014-08-10 11:33:45 +02:00
parent 0f1b95a125
commit 881788a049
3 changed files with 14 additions and 3 deletions

View File

@ -101,7 +101,7 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
// update datetime every 60 seconds
var refresh = function() {
$(".permalink > date", el).textContent = utils.ago(
$(".permalink > time", el).textContent = utils.ago(
globals.offset.localTime(), new Date(parseInt(comment.created, 10) * 1000));
setTimeout(refresh, 60*1000);
};

View File

@ -21,6 +21,13 @@ define(["libjs-jade-runtime", "app/utils", "jade!app/text/postbox", "jade!app/te
load("comment-loader", tt_comment_loader);
set("bool", function(arg) { return arg ? true : false; });
set("humanize", function(date) {
if (typeof date !== "object") {
date = new Date(parseInt(date, 10) * 1000);
}
return date.toString();
});
set("datetime", function(date) {
if (typeof date !== "object") {
date = new Date(parseInt(date, 10) * 1000);
@ -30,7 +37,11 @@ define(["libjs-jade-runtime", "app/utils", "jade!app/text/postbox", "jade!app/te
date.getUTCFullYear(),
utils.pad(date.getUTCMonth(), 2),
utils.pad(date.getUTCDay(), 2)
].join("-");
].join("-") + "T" + [
utils.pad(date.getUTCHours(), 2),
utils.pad(date.getUTCMinutes(), 2),
utils.pad(date.getUTCSeconds(), 2)
].join(":") + "Z";
});
return {

View File

@ -12,7 +12,7 @@ div(class='isso-comment' id='isso-#{comment.id}')
= bool(comment.author) ? comment.author : i18n('comment-anonymous')
span(class="spacer") •
a(class='permalink' href='#isso-#{comment.id}')
date(datetime='#{datetime(comment.created)}')
time(title='#{humanize(comment.created)}' datetime='#{datetime(comment.created)}')
span(class='note')
= comment.mode == 2 ? i18n('comment-queued') : comment.mode == 4 ? i18n('comment-deleted') : ''