Commit 18524fccf4dfb71af2ebb049d12b40ba308d6e1b
Periodically update relative time strings
Charles Lehner committed on 7/10/2016, 7:01:49 AMParent: 4630b7c094e31cc4912bdb17371ca4e67d974f37
Files changed
modules/timestamp.js | changed |
modules/timestamp.js | ||
---|---|---|
@@ -1,6 +1,19 @@ | ||
1 | 1 | var h = require('hyperscript') |
2 | 2 | var moment = require('moment') |
3 | 3 | |
4 | +function updateTimestampEl(el) { | |
5 | + el.firstChild.nodeValue = moment(el.timestamp).fromNow() | |
6 | + return el | |
7 | +} | |
8 | + | |
9 | +setInterval(function () { | |
10 | + var els = [].slice.call(document.querySelectorAll('.timestamp')) | |
11 | + els.forEach(updateTimestampEl) | |
12 | +}, 60e3) | |
13 | + | |
4 | 14 | exports.message_meta = function (msg) { |
5 | - return h('a.enter', {href: '#'+msg.key}, moment(msg.value.timestamp).fromNow()) | |
15 | + return updateTimestampEl(h('a.enter.timestamp', { | |
16 | + href: '#'+msg.key, | |
17 | + timestamp: msg.value.timestamp | |
18 | + }, '')) | |
6 | 19 | } |
Built with git-ssb-web