aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2016-05-29 10:57:35 +0200
committerFelix Nagel <info@felixnagel.com>2016-10-12 01:04:26 +0200
commit9fc83a085c9bc1b8cf6f457f6d7842e2781fca4e (patch)
tree6eb5cd46d649b1e4cb3422aa99e947c0eb7270f8
parent6f9d266339b8c4950b18137af1feb393684e0c5a (diff)
downloadjquery-ui-9fc83a085c9bc1b8cf6f457f6d7842e2781fca4e.tar.gz
jquery-ui-9fc83a085c9bc1b8cf6f457f6d7842e2781fca4e.zip
Calendar: Add change event
-rw-r--r--tests/unit/calendar/common.js1
-rw-r--r--tests/unit/calendar/events.js36
-rw-r--r--tests/unit/datepicker/common.js1
-rw-r--r--tests/unit/datepicker/events.js31
-rw-r--r--ui/widgets/calendar.js7
-rw-r--r--ui/widgets/datepicker.js7
6 files changed, 82 insertions, 1 deletions
diff --git a/tests/unit/calendar/common.js b/tests/unit/calendar/common.js
index b6807ec84..ea637a9b8 100644
--- a/tests/unit/calendar/common.js
+++ b/tests/unit/calendar/common.js
@@ -35,6 +35,7 @@ common.testWidget( "calendar", {
value: null,
// callbacks
+ change: null,
create: null,
select: null
}
diff --git a/tests/unit/calendar/events.js b/tests/unit/calendar/events.js
index 37ad57a85..d69aa137f 100644
--- a/tests/unit/calendar/events.js
+++ b/tests/unit/calendar/events.js
@@ -10,6 +10,42 @@ module( "calendar: events", {
}
} );
+test( "change", function() {
+ expect( 6 );
+
+ var shouldFire, eventType;
+
+ this.element.calendar( {
+ change: function( event ) {
+ ok( shouldFire, "change event fired" );
+ equal(
+ event.type,
+ "calendarchange",
+ "change event"
+ );
+ equal(
+ event.originalEvent.type,
+ eventType,
+ "change originalEvent on calendar button " + eventType
+ );
+ }
+ } );
+
+ shouldFire = true;
+ eventType = "mousedown";
+ this.element.find( "tbody button" ).last().simulate( eventType );
+
+ shouldFire = true;
+ eventType = "keydown";
+ testHelper.focusGrid( this.element )
+ .simulate( eventType, { keyCode: $.ui.keyCode.HOME } )
+ .simulate( eventType, { keyCode: $.ui.keyCode.ENTER } );
+
+ shouldFire = false;
+ eventType = "mousedown";
+ this.element.find( "tbody button" ).first().simulate( eventType );
+} );
+
asyncTest( "select", function() {
expect( 6 );
diff --git a/tests/unit/datepicker/common.js b/tests/unit/datepicker/common.js
index 9074b78e6..527ddcbf3 100644
--- a/tests/unit/datepicker/common.js
+++ b/tests/unit/datepicker/common.js
@@ -42,6 +42,7 @@ common.testWidget( "datepicker", {
// callbacks
beforeOpen: null,
+ change: null,
close: null,
create: null,
open: null,
diff --git a/tests/unit/datepicker/events.js b/tests/unit/datepicker/events.js
index eb327f7f7..394a94d68 100644
--- a/tests/unit/datepicker/events.js
+++ b/tests/unit/datepicker/events.js
@@ -42,6 +42,35 @@ test( "beforeOpen", function() {
.datepicker( "open" );
} );
+test( "change", function() {
+ expect( 4 );
+
+ var shouldFire;
+
+ this.element.datepicker( {
+ change: function( event ) {
+ ok( shouldFire, "change event fired" );
+ equal(
+ event.type,
+ "datepickerchange",
+ "change event"
+ );
+ }
+ } );
+
+ shouldFire = true;
+ this.element.datepicker( "open" );
+ this.widget.find( "tbody button" ).eq( 1 ).simulate( "mousedown" );
+
+ shouldFire = false;
+ this.element.datepicker( "open" );
+ this.widget.find( "tbody button" ).eq( 1 ).simulate( "mousedown" );
+
+ shouldFire = true;
+ this.element.datepicker( "open" );
+ this.widget.find( "tbody button" ).eq( 2 ).simulate( "mousedown" );
+} );
+
test( "close", function() {
expect( 4 );
@@ -71,7 +100,7 @@ test( "close", function() {
shouldFire = false;
this.element.datepicker( "open" );
shouldFire = true;
- this.element.datepicker( "widget" ).find( "tbody tr:first button:first" ).simulate( "mousedown" );
+ this.widget.find( "tbody tr:first button:first" ).simulate( "mousedown" );
} );
test( "open", function() {
diff --git a/ui/widgets/calendar.js b/ui/widgets/calendar.js
index 805547f75..71f712166 100644
--- a/ui/widgets/calendar.js
+++ b/ui/widgets/calendar.js
@@ -72,6 +72,7 @@ return $.widget( "ui.calendar", {
value: null,
// callbacks
+ change: null,
select: null
},
@@ -125,6 +126,8 @@ return $.widget( "ui.calendar", {
},
_select: function( event ) {
+ var oldValue = this.options.value ? this.options.value.getTime() : "";
+
this._setOption( "value", new Date( $( event.currentTarget ).data( "timestamp" ) ) );
this._updateDayElement( "ui-state-active" );
@@ -133,6 +136,10 @@ return $.widget( "ui.calendar", {
this.activeDescendant.closest( this.grid ).focus();
event.preventDefault();
}
+
+ if ( oldValue !== this.options.value.getTime() ) {
+ this._trigger( "change", event );
+ }
},
_handleKeydown: function( event ) {
diff --git a/ui/widgets/datepicker.js b/ui/widgets/datepicker.js
index ed6449abe..e2e9037e8 100644
--- a/ui/widgets/datepicker.js
+++ b/ui/widgets/datepicker.js
@@ -51,6 +51,7 @@ var widget = $.widget( "ui.datepicker", {
// callbacks
beforeOpen: null,
+ change: null,
close: null,
open: null,
select: null
@@ -104,6 +105,9 @@ var widget = $.widget( "ui.datepicker", {
this.calendarInstance = this.calendar
.calendar( $.extend( {}, this.options, {
value: this._parse( this.element.val() ),
+ change: function( event ) {
+ that._trigger( "change", event );
+ },
select: function( event ) {
that.element.val( that.calendarInstance.value() );
that.close();
@@ -172,6 +176,9 @@ var widget = $.widget( "ui.datepicker", {
},
blur: function() {
this.suppressExpandOnFocus = false;
+ },
+ change: function( event ) {
+ this._trigger( "change", event );
}
},