Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/unit/calendar/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ common.testWidget( "calendar", {
// callbacks
change: null,
create: null,
refresh: null,
select: null
}
} );
Expand Down
32 changes: 28 additions & 4 deletions tests/unit/calendar/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ QUnit.module( "calendar: events", {
} );

QUnit.test( "change", function( assert ) {
assert.expect( 6 );
assert.expect( 8 );

var shouldFire, eventType;

this.element.calendar( {
change: function( event ) {
change: function( event, ui ) {
assert.ok( shouldFire, "change event fired" );
assert.equal(
event.type,
Expand All @@ -29,6 +29,7 @@ QUnit.test( "change", function( assert ) {
eventType,
"change originalEvent on calendar button " + eventType
);
assert.equal( $.type( ui.value ), "date", "value is a date object" );
}
} );

Expand All @@ -48,14 +49,14 @@ QUnit.test( "change", function( assert ) {
} );

QUnit.test( "select", function( assert ) {
assert.expect( 6 );
assert.expect( 8 );

var ready = assert.async(),
that = this,
message, eventType;

this.element.calendar( {
select: function( event ) {
select: function( event, ui ) {
assert.ok( true, "select event fired " + message );
assert.equal(
event.type,
Expand All @@ -67,6 +68,7 @@ QUnit.test( "select", function( assert ) {
eventType,
"select originalEvent " + message
);
assert.equal( $.type( ui.value ), "date", "value is a date object" );
}
} );

Expand Down Expand Up @@ -96,4 +98,26 @@ QUnit.test( "select", function( assert ) {
step1();
} );

QUnit.test( "refresh", function( assert ) {
assert.expect( 2 );

var shouldFire;

this.element.calendar( {
refresh: function() {
assert.ok( shouldFire, "refresh event fired" );
}
} );

shouldFire = true;
this.element.find( "button.ui-calendar-next" ).simulate( "click" );

shouldFire = false;
this.element.find( "table button:eq(1)" ).simulate( "click" );

testHelper.focusGrid( this.element ).simulate( "keydown", { keyCode: $.ui.keyCode.END } );
shouldFire = true;
testHelper.focusGrid( this.element ).simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
} );

} );
1 change: 1 addition & 0 deletions tests/unit/datepicker/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ common.testWidget( "datepicker", {
close: null,
create: null,
open: null,
refresh: null,
select: null
}
} );
Expand Down
28 changes: 24 additions & 4 deletions tests/unit/datepicker/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ QUnit.test( "beforeOpen", function( assert ) {
} );

QUnit.test( "change", function( assert ) {
assert.expect( 4 );
assert.expect( 6 );

var shouldFire;

this.element.datepicker( {
change: function( event ) {
change: function( event, ui ) {
assert.ok( shouldFire, "change event fired" );
assert.equal(
event.type,
"datepickerchange",
"change event"
);
assert.equal( $.type( ui.value ), "date", "value is a date object" );
}
} );

Expand Down Expand Up @@ -121,19 +122,20 @@ QUnit.test( "open", function( assert ) {

QUnit.test( "select", function( assert ) {
var ready = assert.async();
assert.expect( 4 );
assert.expect( 6 );

var message = "",
that = this;

this.element.datepicker( {
select: function( event ) {
select: function( event, ui ) {
assert.ok( true, "select event fired " + message );
assert.equal(
event.originalEvent.type,
"calendarselect",
"select originalEvent " + message
);
assert.equal( $.type( ui.value ), "date", "value is a date object" );
}
} );

Expand Down Expand Up @@ -178,4 +180,22 @@ QUnit.test( "select", function( assert ) {
step1();
} );

QUnit.test( "refresh", function( assert ) {
assert.expect( 1 );

var shouldFire;

this.element.calendar( {
refresh: function() {
assert.ok( shouldFire, "refresh event fired" );
}
} );

shouldFire = true;
this.element.find( "button.ui-calendar-next" ).simulate( "click" );

shouldFire = false;
this.element.find( "table button:eq(1)" ).simulate( "click" );
} );

} );
7 changes: 5 additions & 2 deletions ui/widgets/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ return $.widget( "ui.calendar", {

// callbacks
change: null,
refresh: null,
select: null
},

Expand Down Expand Up @@ -134,13 +135,13 @@ return $.widget( "ui.calendar", {
this._updateDayElement( "ui-state-active" );

// Allow datepicker to handle focus
if ( this._trigger( "select", event ) !== false ) {
if ( this._trigger( "select", event, { value: this.options.value } ) !== false ) {
this.activeDescendant.closest( this.grid ).focus();
event.preventDefault();
}

if ( oldValue !== this.options.value.getTime() ) {
this._trigger( "change", event );
this._trigger( "change", event, { value: this.options.value } );
}
},

Expand Down Expand Up @@ -595,6 +596,8 @@ return $.widget( "ui.calendar", {
this._setActiveDescendant();
this._refreshHeaderButtons();
this._createButtons();

this._trigger( "refresh" );
},

_refreshHeaderButtons: function() {
Expand Down
15 changes: 11 additions & 4 deletions ui/widgets/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ var widget = $.widget( "ui.datepicker", {
change: null,
close: null,
open: null,
refresh: null,
select: null
},

calendarOptions: [ "buttons", "classes", "disabled", "dateFormat", "eachDay",
"icons", "labels", "locale", "max", "min", "numberOfMonths", "showWeek" ],
"icons", "labels", "locale", "max", "min", "numberOfMonths", "showWeek", "refresh" ],

_create: function() {
this.suppressExpandOnFocus = false;
Expand Down Expand Up @@ -111,14 +112,18 @@ var widget = $.widget( "ui.datepicker", {
.calendar( $.extend( {}, this.options, {
value: this._parse( this.element.val() ),
change: function( event ) {
that._trigger( "change", event );
that._trigger( "change", event, {
value: that.calendarInstance.valueAsDate()
} );
},
select: function( event ) {
that.element.val( that.calendarInstance.value() );
that.close();
event.preventDefault();
that._focusTrigger();
that._trigger( "select", event );
that._trigger( "select", event, {
value: that.calendarInstance.valueAsDate()
} );

return false;
}
Expand Down Expand Up @@ -183,7 +188,9 @@ var widget = $.widget( "ui.datepicker", {
this.suppressExpandOnFocus = false;
},
change: function( event ) {
this._trigger( "change", event );
this._trigger( "change", event, {
value: this.calendarInstance.valueAsDate()
} );
}
},

Expand Down