I've refactored jQuery UI Datepicker to use the Widget framework that the other components use. Along with this refactoring I've introduced several other changes:
* Use of a templating mechanism to generate the datepicker layout. * Use of commands to provide keystroke and UI elements for interacting with the datepicker. * Use of the position plugin. * Common date routines for general use. * An extension module for less common usage requirements. * Adobe AIR support (no inline event handlers).
For documentation on the templating see http://keith-wood.name/calendarsPickerRef.html#renderers, as the same mechanism is used. The templating is home grown at the moment, but should be moved to the official jQuery model once that has been established. The templating allows for the insertion or otherwise of command links and/or buttons. There are standard templates for the default layout and for one with a button pane.
For documentation on the commands see http://keith-wood.name/calendarsPickerRef.html#commandsobj, as the same mechanism is used. The use of commands makes it easy to extend the datepicker (as often requested) with custom buttons. It also associates keystrokes with the commands for keyboard-driven entry.
The common date routines are basically there to support the datepicker functionality but could be extracted into a separate module for more general use. They are: newDate, normaliseDate, daysInMonth, iso8601Week, dayOfYear, add, formatDate, parseDate, determineDate.
The extension module includes less common functionality: weekOfYearRenderer, noWeekends (onDate), changeFirstDay (onShow), hoverCallback (onShow), highlightWeek (onShow), showStatus (onShow).
Please comment on any and all of the features as we want to pin down what is eventually included in the next release.
In my application, I need to parse and format dates in places that do not have a datepicker associated with them. I was just trying to figure out if I could use the included datepicker functions to handle solve my requirements, but currently it looks like the parse and format functions can only be used in the datepicker itself.
I'm now looking at having to include additional code like DateJS to do this, even though I'm using DatePicker in my app, so the code to do it is already imported. I'd really like to lighten my JS footprint, so would completely welcome the extraction of common functions into a general purpose module.
Is there currently any way pass a date to formatDate() and get a formatted string back? If it is possible, I could really use it!
Thanks for pointing this out. I had ended up figuring that out after posting on here. I had looked at the docs previously, but it wasn't obvious from the documentation what kind of value was returned.
Unfortunately, it turns out that I need to parse and format strings with both date and time, so these functions won't work for me after all.
I'm not sure how it would be done, but if date format/parse was external to datepicker, then it would be possible to select what parsing/formatting library to use. It would be nice if datepicker could be configurable to use the JQuery UI parse/format library or a different one, such as DateJS. That way redundant code doesn't need to be imported.