mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2024-11-27 01:35:40 -05:00
Merge pull request #151 from bryantlikes/patch-1
Adding a knockout binding extension
This commit is contained in:
commit
36f4640018
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