Corrected keystrokes for big previous/next

Moved global stayOpen into instances
Use parseInt to convert to numeric
This commit is contained in:
Keith Wood 2008-08-02 04:00:32 +00:00
parent 9c72777a43
commit 869b6f03b0

View File

@ -441,11 +441,13 @@ $.extend(Datepicker.prototype, {
break; // select the value on enter break; // select the value on enter
case 27: $.datepicker._hideDatepicker(null, $.datepicker._get(inst, 'duration')); case 27: $.datepicker._hideDatepicker(null, $.datepicker._get(inst, 'duration'));
break; // hide on escape break; // hide on escape
case 33: $.datepicker._adjustDate(e.target, (e.ctrlKey ? -1 : case 33: $.datepicker._adjustDate(e.target, (e.ctrlKey ?
-$.datepicker._get(inst, 'stepMonths')), (e.ctrlKey ? 'Y' : 'M')); -$.datepicker._get(inst, 'stepBigMonths') :
-$.datepicker._get(inst, 'stepMonths')), 'M');
break; // previous month/year on page up/+ ctrl break; // previous month/year on page up/+ ctrl
case 34: $.datepicker._adjustDate(e.target, (e.ctrlKey ? +1 : case 34: $.datepicker._adjustDate(e.target, (e.ctrlKey ?
+$.datepicker._get(inst, 'stepMonths')), (e.ctrlKey ? 'Y' : 'M')); +$.datepicker._get(inst, 'stepBigMonths') :
+$.datepicker._get(inst, 'stepMonths')), 'M');
break; // next month/year on page down/+ ctrl break; // next month/year on page down/+ ctrl
case 35: if (e.ctrlKey) $.datepicker._clearDate(e.target); case 35: if (e.ctrlKey) $.datepicker._clearDate(e.target);
handled = e.ctrlKey; handled = e.ctrlKey;
@ -607,10 +609,10 @@ $.extend(Datepicker.prototype, {
if (!inst) if (!inst)
return; return;
var rangeSelect = this._get(inst, 'rangeSelect'); var rangeSelect = this._get(inst, 'rangeSelect');
if (rangeSelect && this._stayOpen) if (rangeSelect && inst.stayOpen)
this._selectDate('#' + inst.id, this._formatDate(inst, this._selectDate('#' + inst.id, this._formatDate(inst,
inst.currentDay, inst.currentMonth, inst.currentYear)); inst.currentDay, inst.currentMonth, inst.currentYear));
this._stayOpen = false; inst.stayOpen = false;
if (this._datepickerShowing) { if (this._datepickerShowing) {
duration = (duration != null ? duration : this._get(inst, 'duration')); duration = (duration != null ? duration : this._get(inst, 'duration'));
var showAnim = this._get(inst, 'showAnim'); var showAnim = this._get(inst, 'showAnim');
@ -725,8 +727,8 @@ $.extend(Datepicker.prototype, {
var inst = $.data(target[0], PROP_NAME); var inst = $.data(target[0], PROP_NAME);
var rangeSelect = this._get(inst, 'rangeSelect'); var rangeSelect = this._get(inst, 'rangeSelect');
if (rangeSelect) { if (rangeSelect) {
this._stayOpen = !this._stayOpen; inst.stayOpen = !inst.stayOpen;
if (this._stayOpen) { if (inst.stayOpen) {
$('.ui-datepicker td').removeClass(this._currentClass); $('.ui-datepicker td').removeClass(this._currentClass);
$(td).addClass(this._currentClass); $(td).addClass(this._currentClass);
} }
@ -734,7 +736,7 @@ $.extend(Datepicker.prototype, {
inst.selectedDay = inst.currentDay = $('a', td).html(); inst.selectedDay = inst.currentDay = $('a', td).html();
inst.selectedMonth = inst.currentMonth = month; inst.selectedMonth = inst.currentMonth = month;
inst.selectedYear = inst.currentYear = year; inst.selectedYear = inst.currentYear = year;
if (this._stayOpen) { if (inst.stayOpen) {
inst.endDay = inst.endMonth = inst.endYear = null; inst.endDay = inst.endMonth = inst.endYear = null;
} }
else if (rangeSelect) { else if (rangeSelect) {
@ -744,7 +746,7 @@ $.extend(Datepicker.prototype, {
} }
this._selectDate(id, this._formatDate(inst, this._selectDate(id, this._formatDate(inst,
inst.currentDay, inst.currentMonth, inst.currentYear)); inst.currentDay, inst.currentMonth, inst.currentYear));
if (this._stayOpen) { if (inst.stayOpen) {
inst.rangeStart = new Date(inst.currentYear, inst.currentMonth, inst.currentDay); inst.rangeStart = new Date(inst.currentYear, inst.currentMonth, inst.currentDay);
this._updateDatepicker(inst); this._updateDatepicker(inst);
} }
@ -764,7 +766,7 @@ $.extend(Datepicker.prototype, {
var inst = $.data(target[0], PROP_NAME); var inst = $.data(target[0], PROP_NAME);
if (this._get(inst, 'mandatory')) if (this._get(inst, 'mandatory'))
return; return;
this._stayOpen = false; inst.stayOpen = false;
inst.endDay = inst.endMonth = inst.endYear = inst.rangeStart = null; inst.endDay = inst.endMonth = inst.endYear = inst.rangeStart = null;
this._selectDate(target, ''); this._selectDate(target, '');
}, },
@ -787,7 +789,7 @@ $.extend(Datepicker.prototype, {
inst.input.trigger('change'); // fire the change event inst.input.trigger('change'); // fire the change event
if (inst.inline) if (inst.inline)
this._updateDatepicker(inst); this._updateDatepicker(inst);
else if (!this._stayOpen) { else if (!inst.stayOpen) {
this._hideDatepicker(null, this._get(inst, 'duration')); this._hideDatepicker(null, this._get(inst, 'duration'));
this._lastInput = inst.input[0]; this._lastInput = inst.input[0];
if (typeof(inst.input[0]) != 'object') if (typeof(inst.input[0]) != 'object')
@ -892,7 +894,7 @@ $.extend(Datepicker.prototype, {
var num = 0; var num = 0;
while (size > 0 && iValue < value.length && while (size > 0 && iValue < value.length &&
value.charAt(iValue) >= '0' && value.charAt(iValue) <= '9') { value.charAt(iValue) >= '0' && value.charAt(iValue) <= '9') {
num = num * 10 + (value.charAt(iValue++) - 0); num = num * 10 + parseInt(value.charAt(iValue++));
size--; size--;
} }
if (size == origSize) if (size == origSize)
@ -1191,15 +1193,15 @@ $.extend(Datepicker.prototype, {
while (matches) { while (matches) {
switch (matches[2] || 'd') { switch (matches[2] || 'd') {
case 'd' : case 'D' : case 'd' : case 'D' :
day += (matches[1] - 0); break; day += parseInt(matches[1]); break;
case 'w' : case 'W' : case 'w' : case 'W' :
day += (matches[1] * 7); break; day += parseInt(matches[1]) * 7; break;
case 'm' : case 'M' : case 'm' : case 'M' :
month += (matches[1] - 0); month += parseInt(matches[1]);
day = Math.min(day, getDaysInMonth(year, month)); day = Math.min(day, getDaysInMonth(year, month));
break; break;
case 'y': case 'Y' : case 'y': case 'Y' :
year += (matches[1] - 0); year += parseInt(matches[1]);
day = Math.min(day, getDaysInMonth(year, month)); day = Math.min(day, getDaysInMonth(year, month));
break; break;
} }
@ -1632,9 +1634,8 @@ $.fn.datepicker = function(options){
/* Initialise the date picker. */ /* Initialise the date picker. */
if (!$.datepicker.initialized) { if (!$.datepicker.initialized) {
$(document.body) $(document.body).append($.datepicker.dpDiv).
.append($.datepicker.dpDiv) mousedown($.datepicker._checkExternalClick);
.mousedown($.datepicker._checkExternalClick);
$.datepicker.initialized = true; $.datepicker.initialized = true;
} }