mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2025-03-21 01:49:50 -04:00
Adding a knockout binding extension
Simple knockout binding extension for knockout bindings with timeago and momentjs. Usage is <div data-bind='timeago: mytimeprop' />
This commit is contained in:
parent
eb71dbca5b
commit
5b7b9f7c85
1 changed files with 14 additions and 0 deletions
14
timeago-koext.js
Normal file
14
timeago-koext.js
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue