Render recent dates as weekdays, part 1.

This commit just moves time rendering logic to its own file, and does
not make any functionality changes.

(imported from commit d111d03c6abc8d9550fcf65e4f89eab8056d1ed4)
This commit is contained in:
Reid Barton 2013-01-14 11:26:50 -05:00
parent 5d79bb6a20
commit 59dab21fcd
4 changed files with 22 additions and 2 deletions

View File

@ -225,6 +225,7 @@ PIPELINE_JS = {
'js/zephyr.js', 'js/zephyr.js',
'js/activity.js', 'js/activity.js',
'js/colorspace.js', 'js/colorspace.js',
'js/timerender.js',
), ),
'output_filename': 'min/app.js' 'output_filename': 'min/app.js'
}, },

View File

@ -54,6 +54,9 @@ var globals =
// invite.js // invite.js
+ ' invite' + ' invite'
// timerender.js
+ ' timerender'
// ui.js // ui.js
+ ' ui' + ' ui'

View File

@ -0,0 +1,17 @@
var timerender = (function () {
var exports = {};
// Given an XDate object 'time', return a DOM node that initially
// displays the human-formatted time, and is updated automatically as
// necessary (e.g. changing "Mon 11:21" to "Jan 14 11:21" after a week
// or so).
// (But for now it just returns a static node.)
exports.render_time = function(time) {
// Wrap the text in a span because (oddly) a text node has no outerHTML attribute.
return $("<span />").text(time.toString("MMM dd") + "\xa0\xa0" + time.toString("HH:mm"));
};
return exports;
}());

View File

@ -349,8 +349,7 @@ function add_display_time(message, prev) {
// NB: timestr is HTML, inserted into the document without escaping. // NB: timestr is HTML, inserted into the document without escaping.
if (include_date) { if (include_date) {
message.timestr = time.toString("MMM dd") + "&nbsp;&nbsp;" + message.timestr = (timerender.render_time(time))[0].outerHTML;
time.toString("HH:mm");
} else { } else {
message.timestr = time.toString("HH:mm"); message.timestr = time.toString("HH:mm");
} }