]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Support changing `eachDay` after initialization
authorTJ VanToll <tj.vantoll@gmail.com>
Tue, 19 Nov 2013 13:35:19 +0000 (08:35 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 29 Jan 2015 22:47:47 +0000 (17:47 -0500)
tests/unit/datepicker/datepicker_options.js
ui/datepicker.js

index 9218303edac6a16f125bf5fc576b5a6fae2d12f4..52ae74a746eda7df2309d401532fc09999783a77 100644 (file)
@@ -45,7 +45,43 @@ test( "dateFormat", function() {
 });
 
 test( "eachDay", function() {
-       expect( 0 );
+       expect( 5 );
+       var timestamp,
+               input = $( "#datepicker" ).datepicker(),
+               picker = input.datepicker( "widget" );
+               firstCell = picker.find( "td[id]:first" );
+
+       equal( firstCell.find( "a" ).length, 1, "days are selectable by default" );
+       timestamp = parseInt( firstCell.find( "a" ).attr( "data-timestamp" ), 10 );
+       equal( new Date( timestamp ).getDate(), 1, "first available day is the 1st by default" );
+
+       // Do not render the 1st of the month
+       input.datepicker( "option", "eachDay", function( day ) {
+               if ( day.date === 1 ) {
+                       day.render = false;
+               }
+       });
+       firstCell = picker.find( "td[id]:first" );
+       timestamp = parseInt( firstCell.find( "a" ).attr( "data-timestamp" ), 10 );
+       equal( new Date( timestamp ).getDate(), 2, "first available day is the 2nd" );
+
+       // Display the 1st of the month but make it not selectable.
+       input.datepicker( "option", "eachDay", function( day ) {
+               if ( day.date === 1 ) {
+                       day.selectable = false;
+               }
+       });
+       firstCell = picker.find( "td[id]:first" );
+       equal( firstCell.find( "a" ).length, 0, "the 1st is not selectable" );
+
+       input.datepicker( "option", "eachDay", function( day ) {
+               if ( day.date === 1 ) {
+                       day.extraClasses = "ui-custom";
+               }
+       });
+       ok( picker.find( "td[id]:first a" ).hasClass( "ui-custom" ), "extraClasses applied" );
+
+       input.datepicker( "destroy" );
 });
 
 test( "numberOfMonths", function() {
index 6839ca7e4d8c3580c142d59c67aeae96b6b8184f..3afe5afd0098eff6fec32a0bd4f5ee7c1f303bbb 100644 (file)
@@ -627,6 +627,11 @@ $.widget( "ui.datepicker", {
                        this.picker.appendTo( this._appendTo() );
                }
 
+               if ( key === "eachDay" ) {
+                       this.date.eachDay = this.options.eachDay;
+                       this.refresh();
+               }
+
                if ( key === "showWeek" ) {
                        this.refresh();
                }