mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2024-12-03 12:36:49 -05:00
Merge pull request #75 from jgraichen/title
Preserve already present title attributes in time tags.
This commit is contained in:
commit
b78598f73f
2 changed files with 17 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,9 @@
|
|||
<p>Date only (default tooltip): <abbr id="defaultTooltip" class="timeago" title="2008-02-26"> </abbr>.</p>
|
||||
<p>Timestsamp (with millis): <abbr class="timeago" title="1978-12-18T17:17:00.021Z">(you shouldn't see this)</abbr>.</p>
|
||||
|
||||
<p><time id="testTimeTitle" class="timeago" datetime="2012-05-07T10:06:02+02:00" title="May 10, 2012 10:06">May 10, 2012</time></p>
|
||||
<p><time id="testTimeTitle2" class="timeago" datetime="2012-05-07T10:06:02+02:00">May 10, 2012</time></p>
|
||||
|
||||
<h2>Errors</h2>
|
||||
|
||||
<p>Bad (letters): <abbr class="bad timeago" title="bleh">(this should be displayed)</abbr>.</p>
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue