Dev: fix the datepicker test suite and jshint everything. Fixes #8804 - Dev: re-enable the datepicker test suite

This commit is contained in:
Mike Sherov 2012-11-09 16:27:45 -05:00
parent 543abc9b1f
commit 254f2b3698
8 changed files with 209 additions and 203 deletions

View File

@ -13,7 +13,7 @@ var versions = {
"Autocomplete": "autocomplete/autocomplete.html", "Autocomplete": "autocomplete/autocomplete.html",
"Button": "button/button.html", "Button": "button/button.html",
"Core": "core/core.html", "Core": "core/core.html",
//"Datepicker": "datepicker/datepicker.html", "Datepicker": "datepicker/datepicker.html",
"Dialog": "dialog/dialog.html", "Dialog": "dialog/dialog.html",
"Draggable": "draggable/draggable.html", "Draggable": "draggable/draggable.html",
"Droppable": "droppable/droppable.html", "Droppable": "droppable/droppable.html",

View File

@ -281,13 +281,13 @@ grunt.initConfig({
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) { files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
// disabling everything that doesn't (quite) work with PhantomJS for now // disabling everything that doesn't (quite) work with PhantomJS for now
// TODO except for all|index|test, try to include more as we go // TODO except for all|index|test, try to include more as we go
return !( /(all|all-active|index|test|dialog|slider|datepicker|tabs|tooltip)\.html$/ ).test( file ); return !( /(all|all-active|index|test|dialog|slider|tabs|tooltip)\.html$/ ).test( file );
}) })
}, },
lint: { lint: {
ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) { ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
// TODO remove items from this list once rewritten // TODO remove items from this list once rewritten
return !( /(mouse|datepicker)\.js$/ ).test( file ); return !( /(mouse)\.js$/ ).test( file );
}), }),
grunt: [ "grunt.js", "build/**/*.js" ], grunt: [ "grunt.js", "build/**/*.js" ],
tests: "tests/unit/**/*.js" tests: "tests/unit/**/*.js"

View File

@ -20,7 +20,7 @@
"autocomplete/autocomplete.html", "autocomplete/autocomplete.html",
"button/button.html", "button/button.html",
"core/core.html", "core/core.html",
//"datepicker/datepicker.html", "datepicker/datepicker.html",
"dialog/dialog.html", "dialog/dialog.html",
"draggable/draggable.html", "draggable/draggable.html",
"droppable/droppable.html", "droppable/droppable.html",

View File

@ -28,7 +28,6 @@
<script src="datepicker_methods.js"></script> <script src="datepicker_methods.js"></script>
<script src="datepicker_options.js"></script> <script src="datepicker_options.js"></script>
<script src="datepicker_test_helpers.js"></script> <script src="datepicker_test_helpers.js"></script>
<script src="datepicker_tickets.js"></script>
<script src="../swarminject.js"></script> <script src="../swarminject.js"></script>
</head> </head>

View File

@ -126,4 +126,23 @@ test('events', function() {
equal(selectedThis, inp2[0], 'Callback close this'); equal(selectedThis, inp2[0], 'Callback close this');
}); });
test('beforeShowDay-getDate', function() {
expect( 3 );
var inp = TestHelpers.datepicker.init('#inp', {beforeShowDay: function() { inp.datepicker('getDate'); return [true, '']; }}),
dp = $('#ui-datepicker-div');
inp.val('01/01/2010').datepicker('show');
// contains non-breaking space
equal($('div.ui-datepicker-title').text(), 'January 2010', 'Initial month');
$('a.ui-datepicker-next', dp).click();
$('a.ui-datepicker-next', dp).click();
// contains non-breaking space
equal($('div.ui-datepicker-title').text(), 'March 2010', 'After next clicks');
inp.datepicker('hide').datepicker('show');
$('a.ui-datepicker-prev', dp).click();
$('a.ui-datepicker-prev', dp).click();
// contains non-breaking space
equal($('div.ui-datepicker-title').text(), 'November 2009', 'After prev clicks');
inp.datepicker('hide');
});
})(jQuery); })(jQuery);

View File

@ -810,6 +810,7 @@ test('parseDate', function() {
gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset()); gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset());
TestHelpers.datepicker.equalsDate($.datepicker.parseDate('@', '981158400000'), gmtDate, 'Parse date @'); TestHelpers.datepicker.equalsDate($.datepicker.parseDate('@', '981158400000'), gmtDate, 'Parse date @');
TestHelpers.datepicker.equalsDate($.datepicker.parseDate('!', '631167552000000000'), gmtDate, 'Parse date !'); TestHelpers.datepicker.equalsDate($.datepicker.parseDate('!', '631167552000000000'), gmtDate, 'Parse date !');
fr = $.datepicker.regional.fr; fr = $.datepicker.regional.fr;
settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
@ -819,12 +820,11 @@ test('parseDate', function() {
new Date(2001, 4 - 1, 9), 'Parse date d MM DD yy with settings'); new Date(2001, 4 - 1, 9), 'Parse date d MM DD yy with settings');
TestHelpers.datepicker.equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Lundi, Avril 9, 2001', settings), TestHelpers.datepicker.equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Lundi, Avril 9, 2001', settings),
new Date(2001, 4 - 1, 9), 'Parse date DD, MM d, yy with settings'); new Date(2001, 4 - 1, 9), 'Parse date DD, MM d, yy with settings');
TestHelpers.datepicker.equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy', TestHelpers.datepicker.equalsDate($.datepicker.parseDate("'jour' d 'de' MM (''DD''), yy", "jour 9 de Avril ('Lundi'), 2001", settings),
'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9), new Date(2001, 4 - 1, 9), "Parse date 'jour' d 'de' MM (''DD''), yy with settings");
'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings');
zh = $.datepicker.regional['zh-CN']; zh = $.datepicker.regional['zh-CN'];
TestHelpers.datepicker.equalsDate($.datepicker.parseDate('yy M d', '2011 十一 22', zh), TestHelpers.datepicker.equalsDate($.datepicker.parseDate('yy M d', '2011 十一 22', zh),
new Date(2011, 11 - 1, 22), 'Parse date yy M d with zh-CN'); new Date(2011, 11 - 1, 22), 'Parse date yy M d with zh-CN');
}); });
@ -881,6 +881,26 @@ test('parseDateErrors', function() {
'Lun. 9 Apr 01 - D d M y', 'Unknown name at position 7'); 'Lun. 9 Apr 01 - D d M y', 'Unknown name at position 7');
}); });
test('Ticket #7244: date parser does not fail when too many numbers are passed into the date function', function() {
expect( 4 );
var date;
try{
date = $.datepicker.parseDate('dd/mm/yy', '18/04/19881');
ok(false, "Did not properly detect an invalid date");
}catch(e){
ok("invalid date detected");
}
try {
date = $.datepicker.parseDate('dd/mm/yy', '18/04/1988 @ 2:43 pm');
equal(date.getDate(), 18);
equal(date.getMonth(), 3);
equal(date.getFullYear(), 1988);
} catch(e) {
ok(false, "Did not properly parse date with extra text separated by whitespace");
}
});
test('formatDate', function() { test('formatDate', function() {
expect( 16 ); expect( 16 );
TestHelpers.datepicker.init('#inp'); TestHelpers.datepicker.init('#inp');
@ -924,4 +944,44 @@ test('formatDate', function() {
'Format date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings'); 'Format date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings');
}); });
test('Ticket 6827: formatDate day of year calculation is wrong during day lights savings time', function(){
expect( 1 );
var time = $.datepicker.formatDate("oo", new Date("2010/03/30 12:00:00 CDT"));
equal(time, "089");
});
test('Ticket 7602: Stop datepicker from appearing with beforeShow event handler', function(){
expect( 3 );
var inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
return false;
}
}),
dp = $('#ui-datepicker-div');
inp.datepicker('show');
equal(dp.css('display'), 'none',"beforeShow returns false");
inp.datepicker('destroy');
inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
}
});
dp = $('#ui-datepicker-div');
inp.datepicker('show');
equal(dp.css('display'), 'block',"beforeShow returns nothing");
inp.datepicker('hide');
inp.datepicker('destroy');
inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
return true;
}
});
dp = $('#ui-datepicker-div');
inp.datepicker('show');
equal(dp.css('display'), 'block',"beforeShow returns true");
inp.datepicker('hide');
inp.datepicker('destroy');
});
})(jQuery); })(jQuery);

View File

@ -1,88 +0,0 @@
/*
* datepicker_tickets.js
*/
(function($) {
module("datepicker: tickets");
// http://forum.jquery.com/topic/several-breaking-changes-in-jquery-ui-1-8rc1
test('beforeShowDay-getDate', function() {
expect( 3 );
var inp = TestHelpers.datepicker.init('#inp', {beforeShowDay: function() { inp.datepicker('getDate'); return [true, '']; }}),
dp = $('#ui-datepicker-div');
inp.val('01/01/2010').datepicker('show');
// contains non-breaking space
equal($('div.ui-datepicker-title').text(), 'January 2010', 'Initial month');
$('a.ui-datepicker-next', dp).click();
$('a.ui-datepicker-next', dp).click();
// contains non-breaking space
equal($('div.ui-datepicker-title').text(), 'March 2010', 'After next clicks');
inp.datepicker('hide').datepicker('show');
$('a.ui-datepicker-prev', dp).click();
$('a.ui-datepicker-prev', dp).click();
// contains non-breaking space
equal($('div.ui-datepicker-title').text(), 'November 2009', 'After prev clicks');
inp.datepicker('hide');
});
test('Ticket 7602: Stop datepicker from appearing with beforeShow event handler', function(){
expect( 3 );
var inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
return false;
}
}),
dp = $('#ui-datepicker-div');
inp.datepicker('show');
equal(dp.css('display'), 'none',"beforeShow returns false");
inp.datepicker('destroy');
inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
}
});
dp = $('#ui-datepicker-div');
inp.datepicker('show');
equal(dp.css('display'), 'block',"beforeShow returns nothing");
inp.datepicker('hide');
inp.datepicker('destroy');
inp = TestHelpers.datepicker.init('#inp',{
beforeShow: function(){
return true;
}
});
dp = $('#ui-datepicker-div');
inp.datepicker('show');
equal(dp.css('display'), 'block',"beforeShow returns true");
inp.datepicker('hide');
inp.datepicker('destroy');
});
test('Ticket 6827: formatDate day of year calculation is wrong during day lights savings time', function(){
expect( 1 );
var time = $.datepicker.formatDate("oo", new Date("2010/03/30 12:00:00 CDT"));
equal(time, "089");
});
test('Ticket #7244: date parser does not fail when too many numbers are passed into the date function', function() {
expect( 4 );
var date;
try{
date = $.datepicker.parseDate('dd/mm/yy', '18/04/19881');
ok(false, "Did not properly detect an invalid date");
}catch(e){
ok("invalid date detected");
}
try {
date = $.datepicker.parseDate('dd/mm/yy', '18/04/1988 @ 2:43 pm');
equal(date.getDate(), 18);
equal(date.getMonth(), 3);
equal(date.getFullYear(), 1988);
} catch(e) {
ok(false, "Did not properly parse date with extra text separated by whitespace");
}
});
})(jQuery);

View File

@ -13,6 +13,7 @@
*/ */
(function( $, undefined ) { (function( $, undefined ) {
/*jshint onevar: false, curly: false, eqeqeq: false, shadow: true, devel: true, evil: true */
$.extend($.ui, { datepicker: { version: "@VERSION" } }); $.extend($.ui, { datepicker: { version: "@VERSION" } });
var PROP_NAME = 'datepicker'; var PROP_NAME = 'datepicker';
@ -132,16 +133,18 @@ $.extend(Datepicker.prototype, {
}, },
/* Override the default settings for all instances of the date picker. /* Override the default settings for all instances of the date picker.
@param settings object - the new settings to use as defaults (anonymous object) * @param settings object - the new settings to use as defaults (anonymous object)
@return the manager object */ * @return the manager object
*/
setDefaults: function(settings) { setDefaults: function(settings) {
extendRemove(this._defaults, settings || {}); extendRemove(this._defaults, settings || {});
return this; return this;
}, },
/* Attach the date picker to a jQuery selection. /* Attach the date picker to a jQuery selection.
@param target element - the target input field or division or span * @param target element - the target input field or division or span
@param settings object - the new settings to use for this date picker instance (anonymous) */ * @param settings object - the new settings to use for this date picker instance (anonymous)
*/
_attachDatepicker: function(target, settings) { _attachDatepicker: function(target, settings) {
// check for settings on the control itself - in namespace 'date:' // check for settings on the control itself - in namespace 'date:'
var inlineSettings = null; var inlineSettings = null;
@ -173,7 +176,7 @@ $.extend(Datepicker.prototype, {
/* Create a new instance object. */ /* Create a new instance object. */
_newInst: function(target, inline) { _newInst: function(target, inline) {
var id = target[0].id.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); // escape jQuery meta chars var id = target[0].id.replace(/([^A-Za-z0-9_\-])/g, '\\\\$1'); // escape jQuery meta chars
return {id: id, input: target, // associated target return {id: id, input: target, // associated target
selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
drawMonth: 0, drawYear: 0, // month being drawn drawMonth: 0, drawYear: 0, // month being drawn
@ -228,7 +231,7 @@ $.extend(Datepicker.prototype, {
$('<img/>').addClass(this._triggerClass). $('<img/>').addClass(this._triggerClass).
attr({ src: buttonImage, alt: buttonText, title: buttonText }) : attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
$('<button type="button"></button>').addClass(this._triggerClass). $('<button type="button"></button>').addClass(this._triggerClass).
html(buttonImage == '' ? buttonText : $('<img/>').attr( html(!buttonImage ? buttonText : $('<img/>').attr(
{ src:buttonImage, alt:buttonText, title:buttonText }))); { src:buttonImage, alt:buttonText, title:buttonText })));
input[isRTL ? 'before' : 'after'](inst.trigger); input[isRTL ? 'before' : 'after'](inst.trigger);
inst.trigger.click(function() { inst.trigger.click(function() {
@ -295,14 +298,15 @@ $.extend(Datepicker.prototype, {
}, },
/* Pop-up the date picker in a "dialog" box. /* Pop-up the date picker in a "dialog" box.
@param input element - ignored * @param input element - ignored
@param date string or Date - the initial date to display * @param date string or Date - the initial date to display
@param onSelect function - the function to call when a date is selected * @param onSelect function - the function to call when a date is selected
@param settings object - update the dialog date picker instance's settings (anonymous object) * @param settings object - update the dialog date picker instance's settings (anonymous object)
@param pos int[2] - coordinates for the dialog's position within the screen or * @param pos int[2] - coordinates for the dialog's position within the screen or
event - with x/y coordinates or * event - with x/y coordinates or
leave empty for default (screen centre) * leave empty for default (screen centre)
@return the manager object */ * @return the manager object
*/
_dialogDatepicker: function(input, date, onSelect, settings, pos) { _dialogDatepicker: function(input, date, onSelect, settings, pos) {
var inst = this._dialogInst; // internal instance var inst = this._dialogInst; // internal instance
if (!inst) { if (!inst) {
@ -343,7 +347,8 @@ $.extend(Datepicker.prototype, {
}, },
/* Detach a datepicker from its control. /* Detach a datepicker from its control.
@param target element - the target input field or division or span */ * @param target element - the target input field or division or span
*/
_destroyDatepicker: function(target) { _destroyDatepicker: function(target) {
var $target = $(target); var $target = $(target);
var inst = $.data(target, PROP_NAME); var inst = $.data(target, PROP_NAME);
@ -365,7 +370,8 @@ $.extend(Datepicker.prototype, {
}, },
/* Enable the date picker to a jQuery selection. /* Enable the date picker to a jQuery selection.
@param target element - the target input field or division or span */ * @param target element - the target input field or division or span
*/
_enableDatepicker: function(target) { _enableDatepicker: function(target) {
var $target = $(target); var $target = $(target);
var inst = $.data(target, PROP_NAME); var inst = $.data(target, PROP_NAME);
@ -390,7 +396,8 @@ $.extend(Datepicker.prototype, {
}, },
/* Disable the date picker to a jQuery selection. /* Disable the date picker to a jQuery selection.
@param target element - the target input field or division or span */ * @param target element - the target input field or division or span
*/
_disableDatepicker: function(target) { _disableDatepicker: function(target) {
var $target = $(target); var $target = $(target);
var inst = $.data(target, PROP_NAME); var inst = $.data(target, PROP_NAME);
@ -416,8 +423,9 @@ $.extend(Datepicker.prototype, {
}, },
/* Is the first field in a jQuery collection disabled as a datepicker? /* Is the first field in a jQuery collection disabled as a datepicker?
@param target element - the target input field or division or span * @param target element - the target input field or division or span
@return boolean - true if disabled, false if enabled */ * @return boolean - true if disabled, false if enabled
*/
_isDisabledDatepicker: function(target) { _isDisabledDatepicker: function(target) {
if (!target) { if (!target) {
return false; return false;
@ -430,9 +438,10 @@ $.extend(Datepicker.prototype, {
}, },
/* Retrieve the instance data for the target control. /* Retrieve the instance data for the target control.
@param target element - the target input field or division or span * @param target element - the target input field or division or span
@return object - the associated instance data * @return object - the associated instance data
@throws error if a jQuery problem getting data */ * @throws error if a jQuery problem getting data
*/
_getInst: function(target) { _getInst: function(target) {
try { try {
return $.data(target, PROP_NAME); return $.data(target, PROP_NAME);
@ -443,13 +452,14 @@ $.extend(Datepicker.prototype, {
}, },
/* Update or retrieve the settings for a date picker attached to an input field or division. /* Update or retrieve the settings for a date picker attached to an input field or division.
@param target element - the target input field or division or span * @param target element - the target input field or division or span
@param name object - the new settings to update or * @param name object - the new settings to update or
string - the name of the setting to change or retrieve, * string - the name of the setting to change or retrieve,
when retrieving also 'all' for all instance settings or * when retrieving also 'all' for all instance settings or
'defaults' for all global defaults * 'defaults' for all global defaults
@param value any - the new value for the setting * @param value any - the new value for the setting
(omit if above is an object or to retrieve a value) */ * (omit if above is an object or to retrieve a value)
*/
_optionDatepicker: function(target, name, value) { _optionDatepicker: function(target, name, value) {
var inst = this._getInst(target); var inst = this._getInst(target);
if (arguments.length == 2 && typeof name == 'string') { if (arguments.length == 2 && typeof name == 'string') {
@ -471,9 +481,9 @@ $.extend(Datepicker.prototype, {
var maxDate = this._getMinMaxDate(inst, 'max'); var maxDate = this._getMinMaxDate(inst, 'max');
extendRemove(inst.settings, settings); extendRemove(inst.settings, settings);
// reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided // reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided
if (minDate !== null && settings['dateFormat'] !== undefined && settings['minDate'] === undefined) if (minDate !== null && settings.dateFormat !== undefined && settings.minDate === undefined)
inst.settings.minDate = this._formatDate(inst, minDate); inst.settings.minDate = this._formatDate(inst, minDate);
if (maxDate !== null && settings['dateFormat'] !== undefined && settings['maxDate'] === undefined) if (maxDate !== null && settings.dateFormat !== undefined && settings.maxDate === undefined)
inst.settings.maxDate = this._formatDate(inst, maxDate); inst.settings.maxDate = this._formatDate(inst, maxDate);
this._attachments($(target), inst); this._attachments($(target), inst);
this._autoSize(inst); this._autoSize(inst);
@ -489,7 +499,8 @@ $.extend(Datepicker.prototype, {
}, },
/* Redraw the date picker attached to an input field or division. /* Redraw the date picker attached to an input field or division.
@param target element - the target input field or division or span */ * @param target element - the target input field or division or span
*/
_refreshDatepicker: function(target) { _refreshDatepicker: function(target) {
var inst = this._getInst(target); var inst = this._getInst(target);
if (inst) { if (inst) {
@ -498,8 +509,9 @@ $.extend(Datepicker.prototype, {
}, },
/* Set the dates for a jQuery selection. /* Set the dates for a jQuery selection.
@param target element - the target input field or division or span * @param target element - the target input field or division or span
@param date Date - the new date */ * @param date Date - the new date
*/
_setDateDatepicker: function(target, date) { _setDateDatepicker: function(target, date) {
var inst = this._getInst(target); var inst = this._getInst(target);
if (inst) { if (inst) {
@ -510,9 +522,10 @@ $.extend(Datepicker.prototype, {
}, },
/* Get the date(s) for the first entry in a jQuery selection. /* Get the date(s) for the first entry in a jQuery selection.
@param target element - the target input field or division or span * @param target element - the target input field or division or span
@param noDefault boolean - true if no default date is to be used * @param noDefault boolean - true if no default date is to be used
@return Date - the current date */ * @return Date - the current date
*/
_getDateDatepicker: function(target, noDefault) { _getDateDatepicker: function(target, noDefault) {
var inst = this._getInst(target); var inst = this._getInst(target);
if (inst && !inst.inline) if (inst && !inst.inline)
@ -545,7 +558,6 @@ $.extend(Datepicker.prototype, {
else else
$.datepicker._hideDatepicker(); $.datepicker._hideDatepicker();
return false; // don't submit the form return false; // don't submit the form
break; // select the value on enter
case 27: $.datepicker._hideDatepicker(); case 27: $.datepicker._hideDatepicker();
break; // hide on escape break; // hide on escape
case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ? case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
@ -602,7 +614,7 @@ $.extend(Datepicker.prototype, {
var inst = $.datepicker._getInst(event.target); var inst = $.datepicker._getInst(event.target);
if ($.datepicker._get(inst, 'constrainInput')) { if ($.datepicker._get(inst, 'constrainInput')) {
var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')); var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode); var chr = String.fromCharCode(event.charCode == null ? event.keyCode : event.charCode);
return event.ctrlKey || event.metaKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1); return event.ctrlKey || event.metaKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
} }
}, },
@ -629,9 +641,10 @@ $.extend(Datepicker.prototype, {
}, },
/* Pop-up the date picker for a given input field. /* Pop-up the date picker for a given input field.
If false returned from beforeShow event handler do not show. * If false returned from beforeShow event handler do not show.
@param input element - the input field attached to the date picker or * @param input element - the input field attached to the date picker or
event - if triggered by focus */ * event - if triggered by focus
*/
_showDatepicker: function(input) { _showDatepicker: function(input) {
input = input.target || input; input = input.target || input;
if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
@ -698,7 +711,6 @@ $.extend(Datepicker.prototype, {
/* Generate the date picker content. */ /* Generate the date picker content. */
_updateDatepicker: function(inst) { _updateDatepicker: function(inst) {
this.maxRows = 4; //Reset the max number of rows being displayed (see #7043) this.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
var borders = $.datepicker._getBorders(inst.dpDiv);
instActive = inst; // for delegate hover events instActive = inst; // for delegate hover events
inst.dpDiv.empty().append(this._generateHTML(inst)); inst.dpDiv.empty().append(this._generateHTML(inst));
this._attachHandlers(inst); this._attachHandlers(inst);
@ -732,8 +744,9 @@ $.extend(Datepicker.prototype, {
}, },
/* Retrieve the size of left and top borders for an element. /* Retrieve the size of left and top borders for an element.
@param elem (jQuery object) the element of interest * @param elem (jQuery object) the element of interest
@return (number[2]) the left and top borders */ * @return (number[2]) the left and top borders
*/
_getBorders: function(elem) { _getBorders: function(elem) {
var convert = function(value) { var convert = function(value) {
return {thin: 1, medium: 2, thick: 3}[value] || value; return {thin: 1, medium: 2, thick: 3}[value] || value;
@ -776,7 +789,8 @@ $.extend(Datepicker.prototype, {
}, },
/* Hide the date picker from view. /* Hide the date picker from view.
@param input element - the input field attached to the date picker */ * @param input element - the input field attached to the date picker
*/
_hideDatepicker: function(input) { _hideDatepicker: function(input) {
var inst = this._curInst; var inst = this._curInst;
if (!inst || (input && inst != $.data(input, PROP_NAME))) if (!inst || (input && inst != $.data(input, PROP_NAME)))
@ -827,7 +841,7 @@ $.extend(Datepicker.prototype, {
inst = $.datepicker._getInst($target[0]); inst = $.datepicker._getInst($target[0]);
if ( ( ( $target[0].id != $.datepicker._mainDivId && if ( ( ( $target[0].id != $.datepicker._mainDivId &&
$target.parents('#' + $.datepicker._mainDivId).length == 0 && $target.parents('#' + $.datepicker._mainDivId).length === 0 &&
!$target.hasClass($.datepicker.markerClassName) && !$target.hasClass($.datepicker.markerClassName) &&
!$target.closest("." + $.datepicker._triggerClass).length && !$target.closest("." + $.datepicker._triggerClass).length &&
$.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) || $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) ||
@ -895,7 +909,6 @@ $.extend(Datepicker.prototype, {
/* Erase the input field and hide the date picker. */ /* Erase the input field and hide the date picker. */
_clearDate: function(id) { _clearDate: function(id) {
var target = $(id); var target = $(id);
var inst = this._getInst(target[0]);
this._selectDate(target, ''); this._selectDate(target, '');
}, },
@ -935,16 +948,18 @@ $.extend(Datepicker.prototype, {
}, },
/* Set as beforeShowDay function to prevent selection of weekends. /* Set as beforeShowDay function to prevent selection of weekends.
@param date Date - the date to customise * @param date Date - the date to customise
@return [boolean, string] - is this date selectable?, what is its CSS class? */ * @return [boolean, string] - is this date selectable?, what is its CSS class?
*/
noWeekends: function(date) { noWeekends: function(date) {
var day = date.getDay(); var day = date.getDay();
return [(day > 0 && day < 6), '']; return [(day > 0 && day < 6), ''];
}, },
/* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition. /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
@param date Date - the date to get the week for * @param date Date - the date to get the week for
@return number - the number of the week within the year that contains this date */ * @return number - the number of the week within the year that contains this date
*/
iso8601Week: function(date) { iso8601Week: function(date) {
var checkDate = new Date(date.getTime()); var checkDate = new Date(date.getTime());
// Find Thursday of this week starting on Monday // Find Thursday of this week starting on Monday
@ -956,22 +971,23 @@ $.extend(Datepicker.prototype, {
}, },
/* Parse a string value into a date object. /* Parse a string value into a date object.
See formatDate below for the possible formats. * See formatDate below for the possible formats.
*
@param format string - the expected format of the date * @param format string - the expected format of the date
@param value string - the date in the above format * @param value string - the date in the above format
@param settings Object - attributes include: * @param settings Object - attributes include:
shortYearCutoff number - the cutoff year for determining the century (optional) * shortYearCutoff number - the cutoff year for determining the century (optional)
dayNamesShort string[7] - abbreviated names of the days from Sunday (optional) * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
dayNames string[7] - names of the days from Sunday (optional) * dayNames string[7] - names of the days from Sunday (optional)
monthNamesShort string[12] - abbreviated names of the months (optional) * monthNamesShort string[12] - abbreviated names of the months (optional)
monthNames string[12] - names of the months (optional) * monthNames string[12] - names of the months (optional)
@return Date - the extracted date value or null if value is blank */ * @return Date - the extracted date value or null if value is blank
*/
parseDate: function (format, value, settings) { parseDate: function (format, value, settings) {
if (format == null || value == null) if (format == null || value == null)
throw 'Invalid arguments'; throw 'Invalid arguments';
value = (typeof value == 'object' ? value.toString() : value + ''); value = (typeof value == 'object' ? value.toString() : value + '');
if (value == '') if (value === '')
return null; return null;
var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff; var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff : shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
@ -1126,32 +1142,33 @@ $.extend(Datepicker.prototype, {
Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000), Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
/* Format a date object into a string value. /* Format a date object into a string value.
The format can be combinations of the following: * The format can be combinations of the following:
d - day of month (no leading zero) * d - day of month (no leading zero)
dd - day of month (two digit) * dd - day of month (two digit)
o - day of year (no leading zeros) * o - day of year (no leading zeros)
oo - day of year (three digit) * oo - day of year (three digit)
D - day name short * D - day name short
DD - day name long * DD - day name long
m - month of year (no leading zero) * m - month of year (no leading zero)
mm - month of year (two digit) * mm - month of year (two digit)
M - month name short * M - month name short
MM - month name long * MM - month name long
y - year (two digit) * y - year (two digit)
yy - year (four digit) * yy - year (four digit)
@ - Unix timestamp (ms since 01/01/1970) * @ - Unix timestamp (ms since 01/01/1970)
! - Windows ticks (100ns since 01/01/0001) * ! - Windows ticks (100ns since 01/01/0001)
'...' - literal text * '...' - literal text
'' - single quote * '' - single quote
*
@param format string - the desired format of the date * @param format string - the desired format of the date
@param date Date - the date value to format * @param date Date - the date value to format
@param settings Object - attributes include: * @param settings Object - attributes include:
dayNamesShort string[7] - abbreviated names of the days from Sunday (optional) * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
dayNames string[7] - names of the days from Sunday (optional) * dayNames string[7] - names of the days from Sunday (optional)
monthNamesShort string[12] - abbreviated names of the months (optional) * monthNamesShort string[12] - abbreviated names of the months (optional)
monthNames string[12] - names of the months (optional) * monthNames string[12] - names of the months (optional)
@return string - the date in the above format */ * @return string - the date in the above format
*/
formatDate: function (format, date, settings) { formatDate: function (format, date, settings) {
if (!date) if (!date)
return ''; return '';
@ -1321,7 +1338,7 @@ $.extend(Datepicker.prototype, {
var year = date.getFullYear(); var year = date.getFullYear();
var month = date.getMonth(); var month = date.getMonth();
var day = date.getDate(); var day = date.getDate();
var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g; var pattern = /([+\-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
var matches = pattern.exec(offset); var matches = pattern.exec(offset);
while (matches) { while (matches) {
switch (matches[2] || 'd') { switch (matches[2] || 'd') {
@ -1355,11 +1372,12 @@ $.extend(Datepicker.prototype, {
}, },
/* Handle switch to/from daylight saving. /* Handle switch to/from daylight saving.
Hours may be non-zero on daylight saving cut-over: * Hours may be non-zero on daylight saving cut-over:
> 12 when midnight changeover, but then cannot generate * > 12 when midnight changeover, but then cannot generate
midnight datetime, so jump to 1AM, otherwise reset. * midnight datetime, so jump to 1AM, otherwise reset.
@param date (Date) the date to check * @param date (Date) the date to check
@return (Date) the corrected date */ * @return (Date) the corrected date
*/
_daylightSavingAdjust: function(date) { _daylightSavingAdjust: function(date) {
if (!date) return null; if (!date) return null;
date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0); date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
@ -1385,7 +1403,7 @@ $.extend(Datepicker.prototype, {
/* Retrieve the date(s) directly. */ /* Retrieve the date(s) directly. */
_getDate: function(inst) { _getDate: function(inst) {
var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null : var startDate = (!inst.currentYear || (inst.input && inst.input.val() === '') ? null :
this._daylightSavingAdjust(new Date( this._daylightSavingAdjust(new Date(
inst.currentYear, inst.currentMonth, inst.currentDay))); inst.currentYear, inst.currentMonth, inst.currentDay)));
return startDate; return startDate;
@ -1494,14 +1512,12 @@ $.extend(Datepicker.prototype, {
firstDay = (isNaN(firstDay) ? 0 : firstDay); firstDay = (isNaN(firstDay) ? 0 : firstDay);
var showWeek = this._get(inst, 'showWeek'); var showWeek = this._get(inst, 'showWeek');
var dayNames = this._get(inst, 'dayNames'); var dayNames = this._get(inst, 'dayNames');
var dayNamesShort = this._get(inst, 'dayNamesShort');
var dayNamesMin = this._get(inst, 'dayNamesMin'); var dayNamesMin = this._get(inst, 'dayNamesMin');
var monthNames = this._get(inst, 'monthNames'); var monthNames = this._get(inst, 'monthNames');
var monthNamesShort = this._get(inst, 'monthNamesShort'); var monthNamesShort = this._get(inst, 'monthNamesShort');
var beforeShowDay = this._get(inst, 'beforeShowDay'); var beforeShowDay = this._get(inst, 'beforeShowDay');
var showOtherMonths = this._get(inst, 'showOtherMonths'); var showOtherMonths = this._get(inst, 'showOtherMonths');
var selectOtherMonths = this._get(inst, 'selectOtherMonths'); var selectOtherMonths = this._get(inst, 'selectOtherMonths');
var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
var defaultDate = this._getDefaultDate(inst); var defaultDate = this._getDefaultDate(inst);
var html = ''; var html = '';
for (var row = 0; row < numMonths[0]; row++) { for (var row = 0; row < numMonths[0]; row++) {
@ -1524,8 +1540,8 @@ $.extend(Datepicker.prototype, {
calender += '">'; calender += '">';
} }
calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' + calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
(/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') + (/all|left/.test(cornerClass) && row === 0 ? (isRTL ? next : prev) : '') +
(/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') + (/all|right/.test(cornerClass) && row === 0 ? (isRTL ? prev : next) : '') +
this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate, this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
'</div><table class="ui-datepicker-calendar"><thead>' + '</div><table class="ui-datepicker-calendar"><thead>' +
@ -1631,8 +1647,8 @@ $.extend(Datepicker.prototype, {
var years = this._get(inst, 'yearRange').split(':'); var years = this._get(inst, 'yearRange').split(':');
var thisYear = new Date().getFullYear(); var thisYear = new Date().getFullYear();
var determineYear = function(value) { var determineYear = function(value) {
var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) : var year = (value.match(/c[+\-].*/) ? drawYear + parseInt(value.substring(1), 10) :
(value.match(/[+-].*/) ? thisYear + parseInt(value, 10) : (value.match(/[+\-].*/) ? thisYear + parseInt(value, 10) :
parseInt(value, 10))); parseInt(value, 10)));
return (isNaN(year) ? thisYear : year); return (isNaN(year) ? thisYear : year);
}; };
@ -1780,14 +1796,14 @@ function bindHover(dpDiv) {
function extendRemove(target, props) { function extendRemove(target, props) {
$.extend(target, props); $.extend(target, props);
for (var name in props) for (var name in props)
if (props[name] == null || props[name] == undefined) if (props[name] == null)
target[name] = props[name]; target[name] = props[name];
return target; return target;
}; }
/* Invoke the datepicker functionality. /* Invoke the datepicker functionality.
@param options string - a command, optionally followed by additional parameters or @param options string - a command, optionally followed by additional parameters or
Object - settings for attaching new datepicker functionality Object - settings for attaching new datepicker functionality
@return jQuery object */ @return jQuery object */
$.fn.datepicker = function(options){ $.fn.datepicker = function(options){