jQuery Prettydate
The jQuery Prettydate plugin provides powerful validation capabilities for forms, making client-side form validation simpler, while offering extensive customization options to meet various application needs. This plugin comes bundled with a set of useful validation methods, including URL and email validation, and provides an API for writing custom methods. All bundled methods default to using English for error messages and are translated into 37 other languages.
The current version of the plugin is 1.1.0.
Download the jQuery Prettydate Validation (Password Validation) plugin.
Usage
To use the Prettydate plugin, you need to include ISO8601 dates in the title:
<a title="2008-01-28T20:24:17Z">January 28th, 2008</a>
<a title="2008-01-27T22:24:17Z">January 27th, 2008</a>
<a title="2008-01-26T22:24:17Z">January 26th, 2008</a>
Then apply the prettyDate method to them:
$(function() { $("a").prettyDate(); });
To localize the plugin, override the properties in $.prettyDate.messages. Here is an example for German localization:
$.prettyDate.messages = {
now: "gerade eben",
minute: "vor einer Minute",
minutes: $.prettyDate.template("vor {0} Minuten"),
hour: "vor einer Stunde",
hours: $.prettyDate.template("vor {0} Stunden"),
yesterday: "Gestern",
days: $.prettyDate.template("vor {0} Tagen"),
weeks: $.prettyDate.template("vor {0} Wochen")
}
The plugin updates each selected element every 10 seconds, so "just now" will change to "1 minute ago" and then to "x minutes ago" and then to "1 hour ago", and so on.
You can disable interval updates by specifying the interval option as "false":
$(function() { $("a").prettyDate({ interval: false }); });
Or set a different interval, for example, interval: 1000, to update each selected element every second:
$(function() { $("a").prettyDate({ interval: 1000 }); });
The value option defaults to reading the ISO8601 date string from the title attribute. Override this option to use another attribute, such as a custom "isodate" attribute:
$(function() {
$("a").prettyDate({
function() { // "this" is the DOM element
return $(this).attr("isodate");
}
});
});