Fix title attributes on post info

This commit is contained in:
Neil Lalonde 2013-06-26 16:27:08 -04:00
parent a0031f2a0d
commit 6b58713fa6
4 changed files with 26 additions and 6 deletions

View File

@ -43,13 +43,17 @@ Discourse.Formatter = (function(){
var append = "";
if(format === 'medium') {
append = " date' title='" + longDate(date);
append = " date";
if(options.leaveAgo) {
format = 'medium-with-ago';
}
options.wrapInSpan = false;
}
if (options.title) {
append += "' title='" + longDate(date);
}
return "<span class='relative-date" + append + "' data-time='" + date.getTime() + "' data-format='" + format + "'>" + relativeAge(date, options) + "</span>";
};

View File

@ -203,6 +203,17 @@ Handlebars.registerHelper('unboundAge', function(property, options) {
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(dt));
});
/**
Live refreshing age helper, with a tooltip showing the date and time
@method unboundAgeWithTooltip
@for Handlebars
**/
Handlebars.registerHelper('unboundAgeWithTooltip', function(property, options) {
var dt = new Date(Ember.Handlebars.get(this, property, options));
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(dt, {title: true}));
});
/**
Display a date related to an edit of a post
@ -212,7 +223,7 @@ Handlebars.registerHelper('unboundAge', function(property, options) {
Handlebars.registerHelper('editDate', function(property, options) {
// autoupdating this is going to be painful
var date = new Date(Ember.Handlebars.get(this, property, options));
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', leaveAgo: true, wrapInSpan: false}));
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', title: true, leaveAgo: true, wrapInSpan: false}));
});
/**
@ -284,7 +295,7 @@ Handlebars.registerHelper('date', function(property, options) {
var val = Ember.Handlebars.get(this, property, options);
if (val) {
var date = new Date(val);
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', leaveAgo: leaveAgo}));
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', title: true, leaveAgo: leaveAgo}));
}
});

View File

@ -39,14 +39,14 @@
<div class='topic-meta-data-inside'>
{{#if hasHistory}}
<div class='post-info edits'>
<a href='#' class="{{unbound historyHeat}}" {{action showHistory this}} title="{{editDate updated_at}}">
<a href='#' class="{{unbound historyHeat}}" {{action showHistory this}} title="{{unboundDate updated_at}}">
{{editCount}}
<i class='icon-pencil'></i>
</a>
</div>
{{/if}}
<div class='post-info'>
<a href='#' class='post-date' {{bindAttr data-share-url="shareUrl"}}>{{unboundAge created_at}}</a>
<a href='#' class='post-date' {{bindAttr data-share-url="shareUrl"}}>{{unboundAgeWithTooltip created_at}}</a>
</div>
</div>
{{/unless}}

View File

@ -86,8 +86,12 @@ test("autoUpdatingRelativeAge", function() {
var $elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d));
equal($elem.data('format'), "tiny");
equal($elem.data('time'), d.getTime());
equal($elem.attr('title'), undefined);
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d,{format: 'medium', leaveAgo: true}));
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d, {title: true}));
equal($elem.attr('title'), moment(d).longDate());
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d,{format: 'medium', title: true, leaveAgo: true}));
equal($elem.data('format'), "medium-with-ago");
equal($elem.data('time'), d.getTime());
equal($elem.attr('title'), moment(d).longDate());
@ -96,6 +100,7 @@ test("autoUpdatingRelativeAge", function() {
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d,{format: 'medium'}));
equal($elem.data('format'), "medium");
equal($elem.data('time'), d.getTime());
equal($elem.attr('title'), undefined);
equal($elem.html(), '1 day');
});