8000 Added partial support for HTML5 <time> element - only handles 'dateti… · rmm5t/jquery-timeago@39a0519 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39a0519

Browse files
jollytoadrmm5t
authored andcommitted
Added partial support for HTML5 <time> element - only handles 'datetime' attr.
1 parent 8a208c8 commit 39a0519

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

jquery.timeago.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$.timeago = function(timestamp) {
1818
if (timestamp instanceof Date) return inWords(timestamp);
1919
else if (typeof timestamp == "string") return inWords($.timeago.parse(timestamp));
20-
else return inWords($.timeago.parse($(timestamp).attr("title")));
20+
else return inWords($.timeago.datetime(timestamp));
2121
};
2222
var $t = $.timeago;
2323

@@ -83,6 +83,10 @@
8383
s = s.replace(/T/," ").replace(/Z/," UTC");
8484
s = s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
8585
return new Date(s);
86+
},
87+
datetime: function(elem) {
88+
var that = $(elem);
89+
return $t.parse(that.is('time') ? that.attr('datetime') : that.attr('title'));
8690
}
8791
});
8892

@@ -98,7 +102,7 @@
98102
};
99103

100104
function refresh() {
101-
var date = $t.parse(this.title);
105+
var date = $t.datetime(this);
102106
if (!isNaN(date)) {
103107
$(this).text(inWords(date));
104108
}
@@ -120,4 +124,5 @@
120124

121125
// fix for IE6 suckage
122126
document.createElement('abbr');
127+
document.createElement('time');
123128
})(jQuery);

0 commit comments

Comments
 (0)
0