Fix title attributes on post info
This commit is contained in:
parent
a0031f2a0d
commit
6b58713fa6
4 changed files with 26 additions and 6 deletions
app/assets/javascripts/discourse
test/javascripts/components
|
@ -43,13 +43,17 @@ Discourse.Formatter = (function(){
|
||||||
var append = "";
|
var append = "";
|
||||||
|
|
||||||
if(format === 'medium') {
|
if(format === 'medium') {
|
||||||
append = " date' title='" + longDate(date);
|
append = " date";
|
||||||
if(options.leaveAgo) {
|
if(options.leaveAgo) {
|
||||||
format = 'medium-with-ago';
|
format = 'medium-with-ago';
|
||||||
}
|
}
|
||||||
options.wrapInSpan = false;
|
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>";
|
return "<span class='relative-date" + append + "' data-time='" + date.getTime() + "' data-format='" + format + "'>" + relativeAge(date, options) + "</span>";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -203,6 +203,17 @@ Handlebars.registerHelper('unboundAge', function(property, options) {
|
||||||
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(dt));
|
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
|
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) {
|
Handlebars.registerHelper('editDate', function(property, options) {
|
||||||
// autoupdating this is going to be painful
|
// autoupdating this is going to be painful
|
||||||
var date = new Date(Ember.Handlebars.get(this, property, options));
|
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);
|
var val = Ember.Handlebars.get(this, property, options);
|
||||||
if (val) {
|
if (val) {
|
||||||
var date = new Date(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}));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,14 +39,14 @@
|
||||||
<div class='topic-meta-data-inside'>
|
<div class='topic-meta-data-inside'>
|
||||||
{{#if hasHistory}}
|
{{#if hasHistory}}
|
||||||
<div class='post-info edits'>
|
<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}}
|
{{editCount}}
|
||||||
<i class='icon-pencil'></i>
|
<i class='icon-pencil'></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div class='post-info'>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
|
@ -86,8 +86,12 @@ test("autoUpdatingRelativeAge", function() {
|
||||||
var $elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d));
|
var $elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d));
|
||||||
equal($elem.data('format'), "tiny");
|
equal($elem.data('format'), "tiny");
|
||||||
equal($elem.data('time'), d.getTime());
|
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('format'), "medium-with-ago");
|
||||||
equal($elem.data('time'), d.getTime());
|
equal($elem.data('time'), d.getTime());
|
||||||
equal($elem.attr('title'), moment(d).longDate());
|
equal($elem.attr('title'), moment(d).longDate());
|
||||||
|
@ -96,6 +100,7 @@ test("autoUpdatingRelativeAge", function() {
|
||||||
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d,{format: 'medium'}));
|
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d,{format: 'medium'}));
|
||||||
equal($elem.data('format'), "medium");
|
equal($elem.data('format'), "medium");
|
||||||
equal($elem.data('time'), d.getTime());
|
equal($elem.data('time'), d.getTime());
|
||||||
|
equal($elem.attr('title'), undefined);
|
||||||
equal($elem.html(), '1 day');
|
equal($elem.html(), '1 day');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in a new issue