diff --git a/jquery.timeago.js b/jquery.timeago.js index b4c93f4..b137ea6 100644 --- a/jquery.timeago.js +++ b/jquery.timeago.js @@ -96,10 +96,12 @@ return new Date(s); }, datetime: function(elem) { - // jQuery's `is()` doesn't play well with HTML5 in IE - var isTime = $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time"); - var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title"); + var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title"); return $t.parse(iso8601); + }, + isTime: function(elem) { + // jQuery's `is()` doesn't play well with HTML5 in IE + return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time"); } }); @@ -127,7 +129,7 @@ if (!element.data("timeago")) { element.data("timeago", { datetime: $t.datetime(element) }); var text = $.trim(element.text()); - if (text.length > 0) { + if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) { element.attr("title", text); } } diff --git a/test/index.html b/test/index.html index 3bf4f95..a215d1c 100644 --- a/test/index.html +++ b/test/index.html @@ -73,6 +73,9 @@

Date only (default tooltip): .

Timestsamp (with millis): (you shouldn't see this).

+

+

+

Errors

Bad (letters): (this should be displayed).

@@ -302,6 +305,14 @@ ok($("#defaultTooltip").attr("title") == "2008-02-26", "correctly set"); }); + test("should preserve title in time tags", function () { + ok(($("#testTimeTitle").attr('title') === "May 10, 2012 10:06"), "title preserved") + }); + + test("should set title in time tags without a title", function () { + ok(($("#testTimeTitle2").attr('title') === "May 10, 2012"), "title set") + }); + module("Parsing"); // Note, different browsers behave slightly different