]> source.dussan.org Git - jquery-ui.git/commitdiff
Calendar: Do not rebuild whole calendar when selecting date
authorFelix Nagel <info@felixnagel.com>
Thu, 3 Dec 2015 17:16:40 +0000 (18:16 +0100)
committerFelix Nagel <info@felixnagel.com>
Wed, 20 Jan 2016 11:16:55 +0000 (12:16 +0100)
ui/widgets/calendar.js

index e692995f4f60fa2a8351ad78041d2d55527e945d..b493cb72faefcddb7dd608fe265a144a66df33f8 100644 (file)
@@ -99,7 +99,7 @@ return $.widget( "ui.calendar", {
                        },
                        "mousedown .ui-calendar-calendar button": function( event ) {
                                this._setOption( "value", new Date( $( event.currentTarget ).data( "timestamp" ) ) );
-                               this.refresh();
+                               this._updateDayElement( "ui-state-active" );
 
                                // Allow datepicker to handle focus
                                if ( this._trigger( "select", event ) !== false ) {
@@ -180,25 +180,29 @@ return $.widget( "ui.calendar", {
 
                        // Check if the needed day is already present in our grid due
                        // to eachDay option changes (eg. other-months demo)
-                       return !this.grid.find(
-                               "#" + $.ui.escapeSelector( this._getDayId( this.date ) )
-                               ).length;
+                       return !this._getDateElement( this._getDayId( this.date ) ).length;
                }
 
                return false;
        },
 
        _setActiveDescendant: function() {
+               this.activeDescendant = this._updateDayElement( "ui-state-focus" );
+       },
+
+       _updateDayElement: function( state ) {
                var id = this._getDayId( this.date );
 
                this.grid
                        .attr( "aria-activedescendant", id )
-                       .find( ".ui-state-focus" )
-                       .removeClass( "ui-state-focus" );
+                       .find( "button." + state )
+                       .removeClass( state );
+
+               return this._getDateElement( id ).children( "button" ).addClass( state );
+       },
 
-               this.activeDescendant = this.grid.find(
-                       "#" + $.ui.escapeSelector( id ) + " > button"
-               ).addClass( "ui-state-focus" );
+       _getDateElement: function( id ) {
+               return this.grid.find( "#" + $.ui.escapeSelector( id ) );
        },
 
        _setLocale: function( locale, dateFormat ) {
@@ -518,7 +522,7 @@ return $.widget( "ui.calendar", {
        refresh: function() {
                this.labels = this.options.labels;
 
-               // Determine which day gridcell to focus after refresh
+               // Determine which day grid cell to focus after refresh
                // TODO: Prevent disabled cells from being focused
                if ( this.options.numberOfMonths === 1 ) {
                        this.element.find( ".ui-calendar-title" ).html( this._buildTitle() );