]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker. Fixed #3657 showOtherMonths should allow the selection of days from other...
authorKeith Wood <kbwood.au@gmail.com>
Sun, 21 Jun 2009 07:28:51 +0000 (07:28 +0000)
committerKeith Wood <kbwood.au@gmail.com>
Sun, 21 Jun 2009 07:28:51 +0000 (07:28 +0000)
demos/datepicker/index.html
demos/datepicker/other-months.html [new file with mode: 0644]
tests/unit/datepicker/datepicker_options.js
ui/ui.datepicker.js

index c71922f2b14c8ca52401d45f9b030c4dee7f2ee7..9cce296e7d0999c11e7fe45f7e7f9606d7a77d2c 100644 (file)
@@ -17,6 +17,7 @@
                <li><a href="inline.html">Display inline</a></li>
                <li><a href="buttonbar.html">Display button bar</a></li>
                <li><a href="dropdown-month-year.html">Display month &amp; year menus</a></li>          
+               <li><a href="other-months.html">Dates in other months</a></li>          
                <li><a href="multiple-calendars.html">Display multiple months</a></li>          
                <li><a href="icon-trigger.html">Icon trigger</a></li>
                <li><a href="event-search.html">Event Search</a></li>
diff --git a/demos/datepicker/other-months.html b/demos/datepicker/other-months.html
new file mode 100644 (file)
index 0000000..f555f3f
--- /dev/null
@@ -0,0 +1,32 @@
+<!doctype html>\r
+<html lang="en">\r
+<head>\r
+       <title>jQuery UI Datepicker - Dates in other months</title>\r
+       <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />\r
+       <script type="text/javascript" src="../../jquery-1.3.2.js"></script>\r
+       <script type="text/javascript" src="../../ui/ui.core.js"></script>\r
+       <script type="text/javascript" src="../../ui/ui.datepicker.js"></script>\r
+       <link type="text/css" href="../demos.css" rel="stylesheet" />\r
+       <script type="text/javascript">\r
+       $(function() {\r
+               $("#datepicker").datepicker({showOtherMonths: true, selectOtherMonths: true});\r
+       });\r
+       </script>\r
+</head>\r
+<body>\r
+\r
+<div class="demo">\r
+\r
+<p>Date: <input type="text" id="datepicker"></p>\r
+\r
+</div><!-- End demo -->\r
+\r
+<div class="demo-description">\r
+\r
+<p>The datepicker can show dates that come from other than the main month\r
+       being displayed. These other dates can also be made selectable.</p>\r
+\r
+</div><!-- End demo-description -->\r
+\r
+</body>\r
+</html>\r
index 8bde84473266e1212261bf116a851d760c712af5..0a111a93c0ccc07bc87021d4d3f753d98d3c2c4b 100644 (file)
@@ -136,6 +136,27 @@ test('invocation', function() {
        inp.datepicker('hide').datepicker('destroy');
 });
 
+test('otherMonths', function() {
+       var inp = init('#inp');
+       var pop = $('#ui-datepicker-div');
+       inp.val('06/01/2009').datepicker('show');
+       equals(pop.find('tbody').text(), '\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0',
+               'Other months - none');
+       ok(pop.find('td:last *').length == 0, 'Other months - no content');
+       inp.datepicker('hide').datepicker('option', 'showOtherMonths', true).datepicker('show');
+       equals(pop.find('tbody').text(), '311234567891011121314151617181920212223242526272829301234',
+               'Other months - show');
+       ok(pop.find('td:last span').length == 1, 'Other months - span content');
+       inp.datepicker('hide').datepicker('option', 'selectOtherMonths', true).datepicker('show');
+       equals(pop.find('tbody').text(), '311234567891011121314151617181920212223242526272829301234',
+               'Other months - select');
+       ok(pop.find('td:last a').length == 1, 'Other months - link content');
+       inp.datepicker('hide').datepicker('option', 'showOtherMonths', false).datepicker('show');
+       equals(pop.find('tbody').text(), '\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0',
+               'Other months - none');
+       ok(pop.find('td:last *').length == 0, 'Other months - no content');
+});
+
 test('defaultDate', function() {
        var inp = init('#inp');
        var date = new Date();
index 478b756e384ba7cda1942d744cc503feca013180..f3f00acb31448dbf12801ebe6dada0d9e81b478e 100644 (file)
@@ -76,6 +76,7 @@ function Datepicker() {
                yearRange: '-10:+10', // Range of years to display in drop-down,
                        // either relative to current year (-nn:+nn) or absolute (nnnn:nnnn)
                showOtherMonths: false, // True to show dates in other months, false to leave blank
+               selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
                calculateWeek: this.iso8601Week, // How to calculate the week of the year,
                        // takes a Date and returns the number of the week for it
                shortYearCutoff: '+10', // Short year values < this are in the current century,
@@ -1340,6 +1341,7 @@ $.extend(Datepicker.prototype, {
                var monthNamesShort = this._get(inst, 'monthNamesShort');
                var beforeShowDay = this._get(inst, 'beforeShowDay');
                var showOtherMonths = this._get(inst, 'showOtherMonths');
+               var selectOtherMonths = this._get(inst, 'selectOtherMonths');
                var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
                var defaultDate = this._getDefaultDate(inst);
                var html = '';
@@ -1385,7 +1387,7 @@ $.extend(Datepicker.prototype, {
                                                var daySettings = (beforeShowDay ?
                                                        beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
                                                var otherMonth = (printDate.getMonth() != drawMonth);
-                                               var unselectable = otherMonth || !daySettings[0] ||
+                                               var unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
                                                        (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
                                                tbody += '<td class="' +
                                                        ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
@@ -1401,11 +1403,12 @@ $.extend(Datepicker.prototype, {
                                                        ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
                                                        (unselectable ? '' : ' onclick="DP_jQuery.datepicker._selectDay(\'#' +
                                                        inst.id + '\',' + drawMonth + ',' + drawYear + ', this);return false;"') + '>' + // actions
-                                                       (otherMonth ? (showOtherMonths ? printDate.getDate() : '&#xa0;') : // display for other months
+                                                       (otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
                                                        (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
                                                        (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
                                                        (printDate.getTime() == currentDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
-                                                       '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display for this month
+                                                       (otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
+                                                       '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
                                                printDate.setDate(printDate.getDate() + 1);
                                                printDate = this._daylightSavingAdjust(printDate);
                                        }