Skip to content

Commit 5f3bdff

Browse files
committed
Datepicker: Add support for multi month pickers to change months with the mouse
1 parent b46ee5d commit 5f3bdff

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

datepicker-rewrite/picker.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ $.widget( "ui.datepicker", {
5555
this._on( this.picker, {
5656
"click .ui-datepicker-prev": function( event ) {
5757
event.preventDefault();
58-
this.date.adjust( "M", -1 );
58+
this.date.adjust( "M", -this.options.numberOfMonths );
5959
this.refresh();
6060
},
6161
"click .ui-datepicker-next": function( event ) {
6262
event.preventDefault();
63-
this.date.adjust( "M", 1 );
63+
this.date.adjust( "M", this.options.numberOfMonths );
6464
this.refresh();
6565
},
6666
"click .ui-datepicker-current": function( event ) {
@@ -504,12 +504,24 @@ $.widget( "ui.datepicker", {
504504
//TODO: Prevent disabled cells from being focused
505505
this.date.refresh();
506506

507-
$( ".ui-datepicker-title", this.picker ).html( this._buildTitle() );
507+
if ( this.options.numberOfMonths === 1 ) {
508+
this.grid = $( this._buildGrid() );
509+
$( ".ui-datepicker-title", this.picker ).html( this._buildTitle() );
510+
$( ".ui-datepicker-calendar", this.picker ).replaceWith( this.grid );
511+
} else {
512+
this._refreshMultiplePicker();
513+
}
514+
},
515+
_refreshMultiplePicker: function() {
516+
var currentDate = this.date,
517+
i = 0;
508518

509-
// TODO fix me
510-
var newGrid = $( this._buildGrid() );
511-
this.grid = this.grid.replaceWith( newGrid );
512-
this.grid = newGrid;
519+
for ( ; i < this.options.numberOfMonths; i++ ) {
520+
$( ".ui-datepicker-title", this.picker ).eq( i ).html( this._buildTitle() );
521+
$( ".ui-datepicker-calendar", this.picker ).eq( i ).html( this._buildGrid() );
522+
this.date.adjust( "M", 1 );
523+
}
524+
this.date.adjust( "M", -this.options.numberOfMonths );
513525
},
514526
open: function( event ) {
515527
if ( this.inline || this.isOpen ) {

0 commit comments

Comments
 (0)