pragmaticly/smart-time-ago — pull request #9 by fent (2012-09-15 13:52:15+00:00)
Title: smarter and improved

I've added several new options to this library. All of them include tests and there is documentation in the readme for them.

```js
$.fn.timeago.defaults = {
// The default attribute to put the ISO8601 absolute time to parse.
attr: 'datetime',

// An extra space character will be added between the time and the unit.
// '1 minute' will look like '1minute' with spacing set to `false`.
spacing: true,

// Will enable displaying text approximation words
// such as 'about 1 hour' and 'almost 2 years'.
approximate: true,

// The text generated by Smart Time Ago will look like '3 hours ago'.
// If you want the text looks like '3 hours from now',
// you might need change the 'suffix' to ' from now'.
suffix: ' ago',

// Will show how many seconds. Instead of 'less than a minute ago' you'll see '24 seconds ago'.
showSeconds: false,

// You can specify how many seconds, below 59, to show a 'just now' message
// instead of '1 second ago'.
showNow: false,

// After a date's relative time is too big,
// you might want to display its absolute version.
// For example, if after one month you don't want to display '2 years ago',
// you can make `maxRelative` equal `2592000` which is a month in seconds.
// Then specify an absolute displaying date function.
maxRelative: false,
absoluteDate: function(date, datetime) { return datetime; }
};
```

If you notice, I also removed the `dir` and `selector` options, because those are not needed. jQuery already has a selector engine, and it's already possible to call timeago on dynamically added elements. It makes much more sense for the user to be able to select what elements to use with time ago like this

```js
$('.timeago').timeago();
```

instead of

```js
$('body').timeago();
```

Also, this way, each of the elements get their own TimeAgo instance, and therefore their own timeout. I didn't really understand why the `dir` option was needed, it would mean that every single date for that instance would be updated even unnecessarily, which I think goes in the wrong direction if we want this to be smart.

Also, I made this much smarter. The timeouts are now set to go off exactly when the relative date will change, and not before or much much after. Being more accurate with timeouts is smarter. :)