This library provides an (optional) Modernizr test for detecting the HTML5 time element, and a shim that you can use to provide browser support for the time element if it's not natively supported.
This tool is licensed under the MIT license. It is copyright 2011 Jonathan Abourbih.
This is very much a work in progress, but in the end it will support:
- determining the datetime value of the time element and properly setting the valueAsDate property, based on the rules in the specification; (this is partly done)
- optionally generating appropriately-formatted content for the time tag when none has been provided.
Currently it follows the spec's parsing rules very closely (practically step by step), and this may not be the most efficient way of handling it. I'd be interested in refactoring with regexes if this reduces code size and improves performance.
It's my aim to have the code pass JSLint with only The Good Parts. The code style will also adhere to Crockford's standard in Javascript: The Good Parts, enforced by jsbeautifier with the --space-after-anon-function --indent-size 4
options.
This tool uses Jasmine for testing. To run the tests, open the SpecRunner.html file in any browser. The Jasmine files and stuff are included in the lib directory, and the specs are in spec.
Include the timeshim.js file your HTML page. To use the Modernizr test, you'll also need to include the modernizr script before timeshim.js.
<script src="lib/modernizr-1.7.min.js" type="text/javascript"></script>
<script src="timeshim.js" type="text/javascript"></script>
<script type="text/javascript">
if (!Modernizr.timetag) {
TimeShim.apply();
}
</script>