Skip to content

Commit 75087d9

Browse files
committed
Factor out class names for day hover and week hover
Call _optionDatepicker from _changeDatepicker Don't recalculate default date and cell over
1 parent 931aec7 commit 75087d9

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

ui/ui.datepicker.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function Datepicker() {
3838
this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
3939
this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
4040
this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
41+
this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
42+
this._weekOverClass = 'ui-datepicker-week-over'; // The name of the week hover marker class
4143
this.regional = []; // Available regional settings, indexed by language code
4244
this.regional[''] = { // Default regional settings
4345
clearText: 'Clear', // Display text for clear link
@@ -432,7 +434,9 @@ $.extend(Datepicker.prototype, {
432434
},
433435

434436
// change method deprecated
435-
_changeDatepicker: this._optionDatepicker,
437+
_changeDatepicker: function(target, name, value) {
438+
this._optionDatepicker(target, name, value);
439+
},
436440

437441
/* Redraw the date picker attached to an input field or division.
438442
@param target element - the target input field or division or span */
@@ -476,12 +480,12 @@ $.extend(Datepicker.prototype, {
476480
switch (e.keyCode) {
477481
case 9: $.datepicker._hideDatepicker(null, '');
478482
break; // hide on tab out
479-
case 13: if ($('td.ui-datepicker-days-cell-over, td.ui-datepicker-current-day', inst.dpDiv)[0]) {
480-
$.datepicker._selectDay(e.target, inst.selectedMonth, inst.selectedYear,
481-
$('td.ui-datepicker-days-cell-over, td.ui-datepicker-current-day', inst.dpDiv)[0]);
482-
} else {
483+
case 13: var sel = $('td.' + $.datepicker._dayOverClass +
484+
', td.' + $.datepicker._currentClass, inst.dpDiv);
485+
if (sel[0])
486+
$.datepicker._selectDay(e.target, inst.selectedMonth, inst.selectedYear, sel[0]);
487+
else
483488
$.datepicker._hideDatepicker(null, $.datepicker._get(inst, 'duration'));
484-
}
485489
return false; // don't submit the form
486490
break; // select the value on enter
487491
case 27: $.datepicker._hideDatepicker(null, $.datepicker._get(inst, 'duration'));
@@ -1417,6 +1421,7 @@ $.extend(Datepicker.prototype, {
14171421
var status = (showStatus ? this._get(inst, 'dayStatus') || initStatus : '');
14181422
var dateStatus = this._get(inst, 'statusForDate') || this.dateStatus;
14191423
var endDate = inst.endDay ? new Date(inst.endYear, inst.endMonth, inst.endDay) : currentDate;
1424+
var defaultDate = this._getDefaultDate(inst);
14201425
for (var row = 0; row < numMonths[0]; row++)
14211426
for (var col = 0; col < numMonths[1]; col++) {
14221427
var selectedDate = new Date(drawYear, drawMonth, inst.selectedDay);
@@ -1461,24 +1466,24 @@ $.extend(Datepicker.prototype, {
14611466
((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end-cell' : '') + // highlight weekends
14621467
(otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
14631468
((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) // user pressed key
1464-
|| (this._getDefaultDate(inst).getTime() == printDate.getTime() && this._getDefaultDate(inst).getTime() == selectedDate.getTime()) ?
1469+
|| (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
14651470
// or defaultDate is current printedDate and defaultDate is selectedDate
1466-
' ui-datepicker-days-cell-over' : '') + // highlight selected day
1471+
' ' + $.datepicker._dayOverClass : '') + // highlight selected day
14671472
(unselectable ? ' ' + this._unselectableClass : '') + // highlight unselectable days
14681473
(otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
14691474
(printDate.getTime() >= currentDate.getTime() && printDate.getTime() <= endDate.getTime() ? // in current range
14701475
' ' + this._currentClass : '') + // highlight selected day
14711476
(printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
14721477
((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
1473-
(unselectable ? (highlightWeek ? ' onmouseover="jQuery(this).parent().addClass(\'ui-datepicker-week-over\');"' + // highlight selection week
1474-
' onmouseout="jQuery(this).parent().removeClass(\'ui-datepicker-week-over\');"' : '') : // unhighlight selection week
1475-
' onmouseover="jQuery(this).addClass(\'ui-datepicker-days-cell-over\')' + // highlight selection
1476-
(highlightWeek ? '.parent().addClass(\'ui-datepicker-week-over\')' : '') + ';' + // highlight selection week
1478+
(unselectable ? (highlightWeek ? ' onmouseover="jQuery(this).parent().addClass(\'' + this._weekOverClass + '\');"' + // highlight selection week
1479+
' onmouseout="jQuery(this).parent().removeClass(\'' + this._weekOverClass + '\');"' : '') : // unhighlight selection week
1480+
' onmouseover="jQuery(this).addClass(\'' + this._dayOverClass + '\')' + // highlight selection
1481+
(highlightWeek ? '.parent().addClass(\'' + this._weekOverClass + '\')' : '') + ';' + // highlight selection week
14771482
(!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#ui-datepicker-status-' +
14781483
inst.id + '\').html(\'' + (dateStatus.apply((inst.input ? inst.input[0] : null),
14791484
[printDate, inst]) || initStatus) +'\');') + '"' +
1480-
' onmouseout="jQuery(this).removeClass(\'ui-datepicker-days-cell-over\')' + // unhighlight selection
1481-
(highlightWeek ? '.parent().removeClass(\'ui-datepicker-week-over\')' : '') + ';' + // unhighlight selection week
1485+
' onmouseout="jQuery(this).removeClass(\'' + this._dayOverClass + '\')' + // unhighlight selection
1486+
(highlightWeek ? '.parent().removeClass(\'' + this._weekOverClass + '\')' : '') + ';' + // unhighlight selection week
14821487
(!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#ui-datepicker-status-' +
14831488
inst.id + '\').html(\'' + initStatus + '\');') + '" onclick="jQuery.datepicker._selectDay(\'#' +
14841489
inst.id + '\',' + drawMonth + ',' + drawYear + ', this);"') + '>' + // actions

0 commit comments

Comments
 (0)