Created
October 9, 2013 16:26
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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