Merge pull request #151 from bryantlikes/patch-1

Adding a knockout binding extension
This commit is contained in:
Ryan McGeary 2013-12-01 16:14:05 -08:00
commit 36f4640018

14
timeago-koext.js Normal file
View file

@ -0,0 +1,14 @@
ko.bindingHandlers.timeago = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var value = valueAccessor();
var valueUnwrapped = ko.unwrap(value);
element.title = moment(valueUnwrapped).toISOString();
$(element).timeago();
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var value = valueAccessor();
var valueUnwrapped = ko.unwrap(value);
element.title = moment(valueUnwrapped).toISOString();
$(element).timeago('update', element.title);
}
}