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

Add observer to amTimeAgo to refresh the starting time on attribute change #285

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion angular-moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
var currentFrom;
var isTimeElement = ('TIME' === element[0].nodeName.toUpperCase());
var setTitleTime = !element.attr('title');
var truncate = !!element.attr('truncate');

function getNow() {
var now;
Expand Down Expand Up @@ -236,7 +237,13 @@
if (showFullDate) {
element.text(momentInstance.format(fullDateFormat));
} else {
element.text(momentInstance.from(getNow(), withoutSuffix));
var text = momentInstance.from(getNow(), withoutSuffix);

if (truncate && (text.indexOf('months') > -1 || text.indexOf('year') > -1)) {
text = 'more than a month ago';
}

element.text(text);
}

if (titleFormat && setTitleTime) {
Expand Down Expand Up @@ -312,6 +319,11 @@
});
}

attr.$observe('amTimeAgo', function (newValue) {
currentValue = newValue;
updateMoment();
});

attr.$observe('amFullDateThreshold', function (newValue) {
fullDateThreshold = newValue;
updateMoment();
Expand Down
2 changes: 1 addition & 1 deletion angular-moment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.