diff options
-rw-r--r-- | tests/datepicker.js | 196 | ||||
-rw-r--r-- | ui/ui.datepicker.js | 101 |
2 files changed, 23 insertions, 274 deletions
diff --git a/tests/datepicker.js b/tests/datepicker.js index 2fb76aa75..71bbaa950 100644 --- a/tests/datepicker.js +++ b/tests/datepicker.js @@ -869,38 +869,6 @@ test('setDate', function() { equalsDate(inp.datepicker('getDate'), date1, 'Set date - two dates'); inp.datepicker('setDate'); ok(inp.datepicker('getDate') == null, 'Set date - null'); - // Ranges - date1 = new Date(2008, 6 - 1, 4); - date2 = new Date(2009, 7 - 1, 5); - inp.datepicker('option', {rangeSelect: true}); - inp.datepicker('setDate', date1, date2); - equalsDateArray(inp.datepicker('getDate'), [date1, date2], - 'Set date range - 2008-06-04 - 2009-07-05'); - inp.datepicker('setDate', date1); - equalsDateArray(inp.datepicker('getDate'), [date1, date1], - 'Set date range - 2008-06-04'); - date1 = new Date(); - date1.setDate(date1.getDate() - 10); - date2 = new Date(); - date2.setDate(date2.getDate() + 10); - inp.datepicker('setDate', -10, +10); - equalsDateArray(inp.datepicker('getDate'), [date1, date2], - 'Set date range - -10 - +10'); - inp.datepicker('setDate', -10); - equalsDateArray(inp.datepicker('getDate'), [date1, date1], - 'Set date range - -10'); - date1 = new Date(); - date1.setDate(date1.getDate() - 14); - date2 = new Date(); - date2.setFullYear(date2.getFullYear() + 1); - inp.datepicker('setDate', '-2w', '+1Y'); - equalsDateArray(inp.datepicker('getDate'), [date1, date2], - 'Set date range - -2w - +1Y'); - inp.datepicker('setDate', '-2w'); - equalsDateArray(inp.datepicker('getDate'), [date1, date1], - 'Set date range - -2w'); - inp.datepicker('setDate'); - isObj(inp.datepicker('getDate'), [null, null], 'Set date range - null'); // Inline var inl = init('#inl'); date1 = new Date(2008, 6 - 1, 4); @@ -923,129 +891,11 @@ test('setDate', function() { var alt = $('#alt'); inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'}); date1 = new Date(2008, 6 - 1, 4); - date2 = new Date(2009, 7 - 1, 5); - inp.datepicker('setDate', date1, date2); - equals(inp.val(), '06/04/2008 - 07/05/2009', - 'Set date alternate - 06/04/2008 - 07/05/2009'); - equals(alt.val(), '2008-06-04 - 2009-07-05', - 'Set date alternate - 2008-06-04 - 2009-07-05'); - inp.datepicker('option', {rangeSelect: false}).datepicker('setDate', date1); + inp.datepicker('setDate', date1); equals(inp.val(), '06/04/2008', 'Set date alternate - 06/04/2008'); equals(alt.val(), '2008-06-04', 'Set date alternate - 2008-06-04'); }); -test('ranges', function() { - var inp = init('#inp', {rangeSelect: true}); - var date1 = new Date(); - var date2 = new Date(); - // Select today - today - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDateArray(inp.datepicker('getDate'), [date1, date1], - 'Range - enter/enter'); - // Can't select prior to start date - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_UP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDateArray(inp.datepicker('getDate'), [date1, date1], - 'Range - enter/ctrl+up/enter'); - // Can select after start date - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - date2.setDate(date2.getDate() + 7); - equalsDateArray(inp.datepicker('getDate'), [date1, date2], - 'Range - enter/ctrl+down/enter'); - equals(inp.val(), $.datepicker.formatDate('mm/dd/yy', date1) + ' - ' + - $.datepicker.formatDate('mm/dd/yy', date2), 'Range - value'); - // Select then cancel defaults to first date - inp.val('').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - equalsDateArray(inp.datepicker('getDate'), [date1, date1], - 'Range - enter/ctrl+down/esc'); - // Separator - inp.datepicker('option', {rangeSeparator: ' to '}). - datepicker('hide').val('06/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDateArray(inp.datepicker('getDate'), - [new Date(2008, 6 - 1, 4), new Date(2008, 6 - 1, 11)], - 'Range separator - enter/ctrl+down/enter'); - equals(inp.val(), '06/04/2008 to 06/11/2008', - 'Range separator - value'); - // Callbacks - inp.datepicker('option', {onSelect: callback, rangeSeparator: ' - '}). - datepicker('hide').val('06/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(selectedDate, '06/04/2008 - 06/11/2008', - 'Range onSelect - enter/ctrl+down/enter'); - inp.datepicker('option', {onChangeMonthYear: callback2, onSelect: null}). - datepicker('hide').val('05/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(selectedDate, '2008/4', - 'Range onChangeMonthYear - enter/ctrl+down/enter'); - inp.datepicker('option', {onClose: callback, onChangeMonthYear: null}). - datepicker('hide').val('03/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(selectedDate, '03/04/2008 - 03/11/2008', - 'Range onClose - enter/ctrl+down/enter'); - // Minimum/maximum - date1 = new Date(2008, 5 - 1, 20); - date2 = new Date(2008, 7 - 1, 2); - inp.datepicker('option', {minDate: date1, maxDate: date2, onClose: null}). - datepicker('hide').val('06/04/2008').datepicker('show'). - simulate('keydown', {keyCode: $.simulate.VK_PGUP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDateArray(inp.datepicker('getDate'), [date1, date2], - 'Range min/max - pgup/enter/pgdn/pgdn/enter'); - inp.val('06/04/2008').datepicker('show'). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_UP}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equalsDateArray(inp.datepicker('getDate'), - [new Date(2008, 5 - 1, 28), new Date(2008, 6 - 1, 11)], - 'Range min/max - ctrl+up/enter/ctrl+down/ctrl+down/enter'); - // Inline - var inl = init('#inl', {rangeSelect: true}); - var dp = $('.ui-datepicker-inline', inl); - date1 = new Date(); - date1.setDate(12); - date2 = new Date(); - date2.setDate(19); - $('.ui-datepicker tbody a:contains(12)', dp).simulate('click', {}); - $('.ui-datepicker tbody a:contains(12)', dp).simulate('click', {}); - equalsDateArray(inl.datepicker('getDate'), [date1, date1], - 'Range inline - same day'); - $('.ui-datepicker tbody a:contains(12)', dp).simulate('click', {}); - $('.ui-datepicker tbody a:contains(10)', dp).simulate('click', {}); // Doesn't select - equalsDateArray(inl.datepicker('getDate'), [date1, date1], - 'Range inline - prev'); - $('.ui-datepicker tbody a:contains(12)', dp).simulate('click', {}); // Selects - inl.datepicker('setDate', date1); - $('.ui-datepicker tbody a:contains(12)', dp).simulate('click', {}); - $('.ui-datepicker tbody a:contains(19)', dp).simulate('click', {}); - equalsDateArray(inl.datepicker('getDate'), [date1, date2], - 'Range inline - next'); -}); - test('altField', function() { var inp = init('#inp'); var alt = $('#alt'); @@ -1082,50 +932,6 @@ test('altField', function() { inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); equals(inp.val(), '', 'Alt field - dp - ctrl+end'); equals(alt.val(), '', 'Alt field - alt - ctrl+end'); - // Range select no alternate field set - alt.val(''); - inp.datepicker('option', {rangeSelect: true, altField: '', altFormat: ''}). - datepicker('hide').val('06/04/2008 - 07/14/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(inp.val(), '06/04/2008 - 06/04/2008', 'Alt field range - dp - enter'); - equals(alt.val(), '', 'Alt field range - alt not set'); - // Range select no movement - alt.val(''); - inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'}). - datepicker('hide').val('06/04/2008 - 07/14/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(inp.val(), '06/04/2008 - 06/04/2008', 'Alt field range - dp - enter'); - equals(alt.val(), '2008-06-04 - 2008-06-04', 'Alt field range - alt - enter'); - // Range select next month - alt.val(''); - inp.val('06/04/2008 - 07/14/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ENTER}); - equals(inp.val(), '06/04/2008 - 07/04/2008', - 'Alt field range - dp - enter/pgdn/enter'); - equals(alt.val(), '2008-06-04 - 2008-07-04', - 'Alt field range - alt - enter/pgdn/enter'); - // Range select escape - alt.val(''); - inp.val('06/04/2008 - 07/14/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {keyCode: $.simulate.VK_ESC}); - equals(inp.val(), '06/04/2008 - 06/04/2008', - 'Alt field range - dp - enter/pgdn/esc'); - equals(alt.val(), '2008-06-04 - 2008-06-04', - 'Alt field range - alt - enter/pgdn/esc'); - // Range select clear - alt.val(''); - inp.val('06/04/2008 - 07/14/2008').datepicker('show'); - inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}). - simulate('keydown', {keyCode: $.simulate.VK_PGDN}). - simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); - equals(inp.val(), '', 'Alt field range - dp - enter/pgdn/ctrl+end'); - equals(alt.val(), '', 'Alt field range - alt - enter/pgdn/ctrl+end'); }); test('daylightSaving', function() { diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js index 66d71f00f..ab391e7c5 100644 --- a/ui/ui.datepicker.js +++ b/ui/ui.datepicker.js @@ -98,8 +98,6 @@ function Datepicker() { showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0) stepMonths: 1, // Number of months to step back/forward stepBigMonths: 12, // Number of months to step back/forward for the big links - rangeSelect: false, // Allows for selecting a date range on one date picker - rangeSeparator: ' - ', // Text between two dates in a range altField: '', // Selector for an alternate field to store selected dates into altFormat: '', // The date format to use for the alternate field constrainInput: true, // The input is constrained by the current date format @@ -586,8 +584,8 @@ $.extend(Datepicker.prototype, { _updateDatepicker: function(inst) { var dims = {width: inst.dpDiv.width() + 4, height: inst.dpDiv.height() + 4}; - inst.dpDiv.empty().append(this._generateHTML(inst)). - find('iframe.ui-datepicker-cover'). + inst.dpDiv.empty().append(this._generateHTML(inst)) + .find('iframe.ui-datepicker-cover'). css({width: dims.width, height: dims.height}) .end() .find('button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a') @@ -649,8 +647,7 @@ $.extend(Datepicker.prototype, { var inst = this._curInst; if (!inst || (input && inst != $.data(input, PROP_NAME))) return; - var rangeSelect = this._get(inst, 'rangeSelect'); - if (rangeSelect && inst.stayOpen) + if (inst.stayOpen) this._selectDate('#' + inst.id, this._formatDate(inst, inst.currentDay, inst.currentMonth, inst.currentYear)); inst.stayOpen = false; @@ -757,25 +754,12 @@ $.extend(Datepicker.prototype, { return; var target = $(id); var inst = this._getInst(target[0]); - var rangeSelect = this._get(inst, 'rangeSelect'); - if (rangeSelect) { - inst.stayOpen = !inst.stayOpen; - if (inst.stayOpen) { - $('.ui-datepicker td', inst.dpDiv).removeClass(this._currentClass); - $(td).addClass(this._currentClass); - } - } inst.selectedDay = inst.currentDay = $('a', td).html(); inst.selectedMonth = inst.currentMonth = month; inst.selectedYear = inst.currentYear = year; if (inst.stayOpen) { inst.endDay = inst.endMonth = inst.endYear = null; } - else if (rangeSelect) { - inst.endDay = inst.currentDay; - inst.endMonth = inst.currentMonth; - inst.endYear = inst.currentYear; - } this._selectDate(id, this._formatDate(inst, inst.currentDay, inst.currentMonth, inst.currentYear)); if (inst.stayOpen) { @@ -783,14 +767,6 @@ $.extend(Datepicker.prototype, { new Date(inst.currentYear, inst.currentMonth, inst.currentDay)); this._updateDatepicker(inst); } - else if (rangeSelect) { - inst.selectedDay = inst.currentDay = inst.rangeStart.getDate(); - inst.selectedMonth = inst.currentMonth = inst.rangeStart.getMonth(); - inst.selectedYear = inst.currentYear = inst.rangeStart.getFullYear(); - inst.rangeStart = null; - if (inst.inline) - this._updateDatepicker(inst); - } }, /* Erase the input field and hide the date picker. */ @@ -807,9 +783,6 @@ $.extend(Datepicker.prototype, { var target = $(id); var inst = this._getInst(target[0]); dateStr = (dateStr != null ? dateStr : this._formatDate(inst)); - if (this._get(inst, 'rangeSelect') && dateStr) - dateStr = (inst.rangeStart ? this._formatDate(inst, inst.rangeStart) : - dateStr) + this._get(inst, 'rangeSeparator') + dateStr; if (inst.input) inst.input.val(dateStr); this._updateAlternate(inst); @@ -835,11 +808,7 @@ $.extend(Datepicker.prototype, { if (altField) { // update alternate field too var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat'); var date = this._getDate(inst); - dateStr = (isArray(date) ? (!date[0] && !date[1] ? '' : - this.formatDate(altFormat, date[0], this._getFormatConfig(inst)) + - this._get(inst, 'rangeSeparator') + this.formatDate( - altFormat, date[1] || date[0], this._getFormatConfig(inst))) : - this.formatDate(altFormat, date, this._getFormatConfig(inst))); + dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst)); $(altField).each(function() { $(this).val(dateStr); }); } }, @@ -1162,30 +1131,22 @@ $.extend(Datepicker.prototype, { /* Parse existing date and initialise date picker. */ _setDateFromField: function(inst) { var dateFormat = this._get(inst, 'dateFormat'); - var dates = inst.input ? inst.input.val().split(this._get(inst, 'rangeSeparator')) : null; + var dates = inst.input ? inst.input.val() : null; inst.endDay = inst.endMonth = inst.endYear = null; var date = defaultDate = this._getDefaultDate(inst); - if (dates.length > 0) { - var settings = this._getFormatConfig(inst); - if (dates.length > 1) { - date = this.parseDate(dateFormat, dates[1], settings) || defaultDate; - inst.endDay = date.getDate(); - inst.endMonth = date.getMonth(); - inst.endYear = date.getFullYear(); - } - try { - date = this.parseDate(dateFormat, dates[0], settings) || defaultDate; - } catch (event) { - this.log(event); - date = defaultDate; - } - } + var settings = this._getFormatConfig(inst); + try { + date = this.parseDate(dateFormat, dates, settings) || defaultDate; + } catch (event) { + this.log(event); + date = defaultDate; + } inst.selectedDay = date.getDate(); inst.drawMonth = inst.selectedMonth = date.getMonth(); inst.drawYear = inst.selectedYear = date.getFullYear(); - inst.currentDay = (dates[0] ? date.getDate() : 0); - inst.currentMonth = (dates[0] ? date.getMonth() : 0); - inst.currentYear = (dates[0] ? date.getFullYear() : 0); + inst.currentDay = (dates ? date.getDate() : 0); + inst.currentMonth = (dates ? date.getMonth() : 0); + inst.currentYear = (dates ? date.getFullYear() : 0); this._adjustInstDate(inst); }, @@ -1266,25 +1227,12 @@ $.extend(Datepicker.prototype, { inst.selectedDay = inst.currentDay = date.getDate(); inst.drawMonth = inst.selectedMonth = inst.currentMonth = date.getMonth(); inst.drawYear = inst.selectedYear = inst.currentYear = date.getFullYear(); - if (this._get(inst, 'rangeSelect')) { - if (endDate) { - endDate = this._determineDate(endDate, null); - inst.endDay = endDate.getDate(); - inst.endMonth = endDate.getMonth(); - inst.endYear = endDate.getFullYear(); - } else { - inst.endDay = inst.currentDay; - inst.endMonth = inst.currentMonth; - inst.endYear = inst.currentYear; - } - } if (origMonth != inst.selectedMonth || origYear != inst.selectedYear) this._notifyChange(inst); this._adjustInstDate(inst); - if (inst.input) - inst.input.val(clear ? '' : this._formatDate(inst) + - (!this._get(inst, 'rangeSelect') ? '' : this._get(inst, 'rangeSeparator') + - this._formatDate(inst, inst.endDay, inst.endMonth, inst.endYear))); + if (inst.input) { + inst.input.val(clear ? '' : this._formatDate(inst)); + } }, /* Retrieve the date(s) directly. */ @@ -1292,11 +1240,6 @@ $.extend(Datepicker.prototype, { var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null : this._daylightSavingAdjust(new Date( inst.currentYear, inst.currentMonth, inst.currentDay))); - if (this._get(inst, 'rangeSelect')) { - return [inst.rangeStart || startDate, - (!inst.endYear ? inst.rangeStart || startDate : - this._daylightSavingAdjust(new Date(inst.endYear, inst.endMonth, inst.endDay)))]; - } else return startDate; }, @@ -1341,10 +1284,10 @@ $.extend(Datepicker.prototype, { prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText, this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)), this._getFormatConfig(inst))); - var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ? + var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ? '<a class="ui-datepicker-prev ui-corner-all" onclick="jQuery.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' + ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' : - (hideIfNoPrevNext ? '' : '<label>' + prevText + '</label>')); + (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>')); var nextText = this._get(inst, 'nextText'); nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText, this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)), @@ -1352,7 +1295,7 @@ $.extend(Datepicker.prototype, { var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ? '<a class="ui-datepicker-next ui-corner-all" onclick="jQuery.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' + ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' : - (hideIfNoPrevNext ? '' : '<label>' + nextText + '</label>')); + (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>')); var currentText = this._get(inst, 'currentText'); var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today); currentText = (!navigationAsDateFormat ? currentText : @@ -1425,7 +1368,7 @@ $.extend(Datepicker.prototype, { (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ? // or defaultDate is current printedDate and defaultDate is selectedDate ' ' + this._dayOverClass : '') + // highlight selected day - (unselectable ? ' ' + this._unselectableClass : '') + // highlight unselectable days + (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable days (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates (printDate.getTime() >= currentDate.getTime() && printDate.getTime() <= endDate.getTime() ? // in current range ' ' + this._currentClass : '') + // highlight selected day |