From 5b7b9f7c85d67ceb55552027a360b71ec40e20ed Mon Sep 17 00:00:00 2001 From: bryantlikes Date: Sat, 30 Nov 2013 17:22:33 -0800 Subject: [PATCH] Adding a knockout binding extension Simple knockout binding extension for knockout bindings with timeago and momentjs. Usage is
--- timeago-koext.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 timeago-koext.js diff --git a/timeago-koext.js b/timeago-koext.js new file mode 100644 index 0000000..bec4d13 --- /dev/null +++ b/timeago-koext.js @@ -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); + } +}