sajaniemi_variable_dataset_large / pool /shard008 /JavaScript /0050154_angular-smart-timeago.js
Pendigard's picture
Upload folder using huggingface_hub (part 93)
7f88cfb verified
Raw History Blame Contribute Delete
1.24 kB
var ngSmartTimeago = angular.module("ngSmartTimeago", []);
ngSmartTimeago.constant("ngSmartTimeagoConfig", {
attr: "datetime"
});
ngSmartTimeago.directive("timeago", ["ngSmartTimeagoConfig", "$timeout",
function(ngSmartTimeagoConfig, $timeout) {
var scope_option = {};
scope_option[ngSmartTimeagoConfig.attr] = "@";
return {
restrict: "E",
scope: scope_option,
link: function(scope, element, attrs) {
var options = angular.extend(
{},
ngSmartTimeagoConfig,
{selector: "timeago"}
);
element.timeago(options);
scope.$watch(ngSmartTimeagoConfig.attr, function() {
element.data("timeago").refresh();
});
// Clear timer before destroying scope
scope.$on('$destroy', function() {
element.data("timeago").stopTimer();
});
}
};
}
]);
ngSmartTimeago.filter('timeago',["smartTimeagoInstance", function(smartTimeagoInstance){
return function (input) {
return smartTimeagoInstance.timeAgoInWords(input);
};
}]);
ngSmartTimeago.factory("smartTimeagoInstance", ["$window", function($window) {
var instance = new $window.jQuery.fn.timeago.Constructor();
return instance;
}]);