Skip to content

Instantly share code, notes, and snippets.

@kohenkatz
Created October 9, 2013 16:26
Show Gist options
  • Save kohenkatz/6903994 to your computer and use it in GitHub Desktop.
Save kohenkatz/6903994 to your computer and use it in GitHub Desktop.
How to use jQuery Timeago (http://timeago.yarp.com/) plugin in Durandal. I put this code in my `main.js` file (after the plugin initialization), but there's probably a better place (a plugin file, or similar).
composition.addBindingHandler('timeago',{
init: function(element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
var $this = $(element);
$this.attr($.timeago.isTime($this) ? 'datetime' : 'title', value);
$this.timeago();
},
update: function(element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
var $this = $(element);
$this.attr($.timeago.isTime($this) ? 'datetime' : 'title', value);
$this.timeago('updateFromDOM');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment