jquery-timeago/timeago-koext.js
bryantlikes 5b7b9f7c85 Adding a knockout binding extension
Simple knockout binding extension for knockout bindings with timeago and momentjs. Usage is <div data-bind='timeago: mytimeprop'  />
2013-11-30 17:22:33 -08:00

14 lines
611 B
JavaScript

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);
}
}