Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Nov 10, 2015
2 parents de5a532 + a8f43d6 commit 2e89c57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion angular-moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
var modelName = attr.amTimeAgo;
var currentFrom;
var isTimeElement = ('TIME' === element[0].nodeName.toUpperCase());
var setTitleTime = !element.attr('title');

function getNow() {
var now;
Expand Down Expand Up @@ -234,7 +235,7 @@
element.text(momentInstance.from(getNow(), withoutSuffix));
}

if (titleFormat && !element.attr('title')) {
if (titleFormat && setTitleTime) {
element.attr('title', momentInstance.local().format(titleFormat));
}

Expand Down
12 changes: 12 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ describe('module angularMoment', function () {
expect(element.attr('title')).toBe(testDateWithCustomFormatting);
});

it('should update the title attribute of the element if the binding model changed', function () {
amTimeAgoConfig.titleFormat = 'MMMM Do YYYY, h:mm:ss a';
$rootScope.testDate = Date.UTC(2015, 11, 10, 18, 44, 12);
var element = angular.element('<span am-time-ago="testDate"></span>');
element = $compile(element)($rootScope);
$rootScope.$digest();
$rootScope.testDate = Date.UTC(2015, 11, 10, 19, 43, 34);
$rootScope.$digest();
var testDate = moment($rootScope.testDate).format(amTimeAgoConfig.titleFormat);
expect(element.attr('title')).toBe(testDate);
});

describe('full date support', function () {
it('should display relative time if the date is recent', function () {
amTimeAgoConfig.fullDateThreshold = 7;
Expand Down

0 comments on commit 2e89c57

Please sign in to comment.