Added partial support for HTML5 <time> element - only handles 'datetime' attr.

This commit is contained in:
Mark Gibson 2009-08-19 16:32:51 +01:00 committed by Ryan McGeary
parent 8a208c8a32
commit 39a051940e

View file

@ -17,7 +17,7 @@
$.timeago = function(timestamp) { $.timeago = function(timestamp) {
if (timestamp instanceof Date) return inWords(timestamp); if (timestamp instanceof Date) return inWords(timestamp);
else if (typeof timestamp == "string") return inWords($.timeago.parse(timestamp)); else if (typeof timestamp == "string") return inWords($.timeago.parse(timestamp));
else return inWords($.timeago.parse($(timestamp).attr("title"))); else return inWords($.timeago.datetime(timestamp));
}; };
var $t = $.timeago; var $t = $.timeago;
@ -83,6 +83,10 @@
s = s.replace(/T/," ").replace(/Z/," UTC"); s = s.replace(/T/," ").replace(/Z/," UTC");
s = s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400 s = s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
return new Date(s); return new Date(s);
},
datetime: function(elem) {
var that = $(elem);
return $t.parse(that.is('time') ? that.attr('datetime') : that.attr('title'));
} }
}); });
@ -98,7 +102,7 @@
}; };
function refresh() { function refresh() {
var date = $t.parse(this.title); var date = $t.datetime(this);
if (!isNaN(date)) { if (!isNaN(date)) {
$(this).text(inWords(date)); $(this).text(inWords(date));
} }
@ -120,4 +124,5 @@
// fix for IE6 suckage // fix for IE6 suckage
document.createElement('abbr'); document.createElement('abbr');
document.createElement('time');
})(jQuery); })(jQuery);