diff --git a/README.md b/README.md index a2c29aba..246a25ae 100644 --- a/README.md +++ b/README.md @@ -119,10 +119,6 @@ var picker = new Pikaday({ field: document.getElementById('datepicker') }); Returns the selected date in a string format. If [Moment.js](http://momentjs.com/) exists (recommended) then Pikaday can return any format that Moment understands, otherwise you're stuck with JavaScript's default. -`picker.getMoment()` - -Returns a [Moment.js](http://momentjs.com/) object for the selected date (Moment must be loaded before Pikaday). - `picker.getDate()` Returns a basic JavaScript `Date` object of the selected day, or `null` if no selection. @@ -131,6 +127,14 @@ Returns a basic JavaScript `Date` object of the selected day, or `null` if no se Set the current selection. This will be restricted within the bounds of `minDate` and `maxDate` options if they're specified. +`picker.getMoment()` + +Returns a [Moment.js](http://momentjs.com/) object for the selected date (Moment must be loaded before Pikaday). + +`picker.setMoment(moment('14th Feburary 2013', 'DDo MMMM YYYY'))` + +Set the current selection with a [Moment.js](http://momentjs.com/) object (passed on to `setDate`). + ### Change current view `picker.gotoDate(new Date(2012, 1))` diff --git a/pikaday.js b/pikaday.js index 39622d82..79e029f2 100644 --- a/pikaday.js +++ b/pikaday.js @@ -539,6 +539,16 @@ return hasMoment ? window.moment(this._d) : null; }, + /** + * set the current selection from a Moment.js object (if available) + */ + setMoment: function(date) + { + if (hasMoment && window.moment.isMoment(date)) { + this.setDate(date.toDate()); + } + }, + /** * return a Date object of the current selection */ diff --git a/plugins/pikaday.jquery.js b/plugins/pikaday.jquery.js index c94f70fc..e460d5fd 100644 --- a/plugins/pikaday.jquery.js +++ b/plugins/pikaday.jquery.js @@ -217,7 +217,8 @@ // callback function onSelect: null, onOpen: null, - onClose: null + onClose: null, + onDraw: null }, @@ -575,6 +576,16 @@ return hasMoment ? window.moment(this._d) : null; }, + /** + * set the current selection from a Moment.js object (if available) + */ + setMoment: function(date) + { + if (hasMoment && window.moment.isMoment(date)) { + this.setDate(date.toDate()); + } + }, + /** * return a Date object of the current selection */ @@ -721,6 +732,13 @@ opts.field.focus(); }, 1); } + + if (typeof this._o.onDraw === 'function') { + var self = this; + sto(function() { + self._o.onDraw.call(self); + }, 0); + } }, /**