From 5fbe668d8615b86aca58d7c0e36de133b63baa29 Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Fri, 15 Nov 2013 09:17:13 -0500 Subject: [PATCH] Datepicker: Various changes for the `showWeek` option * Re-add `ui-datepicker-week-col` class name currently used. * Add test suite. * Support changing option after initialization. --- tests/unit/datepicker/datepicker_options.js | 24 ++++++++++++++++++++- ui/datepicker.js | 8 +++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/unit/datepicker/datepicker_options.js b/tests/unit/datepicker/datepicker_options.js index 72f459db0..67302345c 100644 --- a/tests/unit/datepicker/datepicker_options.js +++ b/tests/unit/datepicker/datepicker_options.js @@ -57,7 +57,29 @@ test( "position", function() { }); test( "showWeek", function() { - expect( 0 ); + expect( 7 ); + var input = $( "#datepicker" ).datepicker(), + container = input.datepicker( "widget" ); + + equal( container.find( "thead th" ).length, 7, "just 7 days, no column cell" ); + equal( container.find( ".ui-datepicker-week-col" ).length, 0, + "no week column cells present" ); + input.datepicker( "destroy" ); + + input = $( "#datepicker" ).datepicker({ showWeek: true }); + container = input.datepicker( "widget" ); + equal( container.find( "thead th" ).length, 8, "7 days + a column cell" ); + ok( container.find( "thead th:first" ).is( ".ui-datepicker-week-col" ), + "first cell should have ui-datepicker-week-col class name" ); + equal( container.find( ".ui-datepicker-week-col" ).length, + container.find( "tr" ).length, "one week cell for each week" ); + input.datepicker( "destroy" ); + + input = $( "#datepicker" ).datepicker(); + container = input.datepicker( "widget" ); + equal( container.find( "thead th" ).length, 7, "no week column" ); + input.datepicker( "option", "showWeek", true ); + equal( container.find( "thead th" ).length, 8, "supports changing option after init" ); }); /* diff --git a/ui/datepicker.js b/ui/datepicker.js index 28fd9191a..7264a556e 100644 --- a/ui/datepicker.js +++ b/ui/datepicker.js @@ -407,7 +407,7 @@ $.widget( "ui.datepicker", { labels = Globalize.localize( "datepicker" ); if ( this.options.showWeek ) { - cells += "" + labels.weekHeader + ""; + cells += "" + labels.weekHeader + ""; } for ( i; i < this.date.weekdays().length; i++ ) { cells += this._buildGridHeaderCell( this.date.weekdays()[i] ); @@ -436,7 +436,7 @@ $.widget( "ui.datepicker", { i = 0; if ( this.options.showWeek ) { - cells += "" + week.number + ""; + cells += "" + week.number + ""; } for ( i; i < week.days.length; i++ ) { cells += this._buildDayCell( week.days[i] ); @@ -625,6 +625,10 @@ $.widget( "ui.datepicker", { if ( key === "appendTo" ) { this.picker.appendTo( this._appendTo() ); } + + if ( key === "showWeek" ) { + this.refresh(); + } } }); -- 2.39.5