});
test('baseStructure', function() {
- var inp = init('#inp');
- inp.focus();
- var dp = $('#ui-datepicker-div');
- var iframe = ($.browser.msie && parseInt($.browser.version) < 7);
+ var header, title, table, thead, week, panel, inl, child,
+ inp = init('#inp').focus(),
+ dp = $('#ui-datepicker-div'),
+ iframe = ($.browser.msie && parseInt($.browser.version, 10) < 7);
ok(dp.is(':visible'), 'Structure - datepicker visible');
ok(!dp.is('.ui-datepicker-rtl'), 'Structure - not right-to-left');
ok(!dp.is('.ui-datepicker-multi'), 'Structure - not multi-month');
equal(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure - child count');
- var header = dp.children(':first');
+ header = dp.children(':first');
ok(header.is('div.ui-datepicker-header'), 'Structure - header division');
equal(header.children().length, 3, 'Structure - header child count');
- ok(header.children(':first').is('a.ui-datepicker-prev') && header.children(':first').html() != '', 'Structure - prev link');
- ok(header.children(':eq(1)').is('a.ui-datepicker-next') && header.children(':eq(1)').html() != '', 'Structure - next link');
+ ok(header.children(':first').is('a.ui-datepicker-prev') && header.children(':first').html() !== '', 'Structure - prev link');
+ ok(header.children(':eq(1)').is('a.ui-datepicker-next') && header.children(':eq(1)').html() !== '', 'Structure - next link');
- var title = header.children(':last');
- ok(title.is('div.ui-datepicker-title') && title.html() != '','Structure - title division');
+ title = header.children(':last');
+ ok(title.is('div.ui-datepicker-title') && title.html() !== '','Structure - title division');
equal(title.children().length, 2, 'Structure - title child count');
- ok(title.children(':first').is('span.ui-datepicker-month') && title.children(':first').text() != '', 'Structure - month text')
- ok(title.children(':last').is('span.ui-datepicker-year') && title.children(':last').text() != '', 'Structure - year text')
+ ok(title.children(':first').is('span.ui-datepicker-month') && title.children(':first').text() !== '', 'Structure - month text');
+ ok(title.children(':last').is('span.ui-datepicker-year') && title.children(':last').text() !== '', 'Structure - year text');
- var table = dp.children(':eq(1)');
+ table = dp.children(':eq(1)');
ok(table.is('table.ui-datepicker-calendar'), 'Structure - month table');
ok(table.children(':first').is('thead'), 'Structure - month table thead');
- var thead = table.children(':first').children(':first');
+ thead = table.children(':first').children(':first');
ok(thead.is('tr'), 'Structure - month table title row');
equal(thead.find('th').length, 7, 'Structure - month table title cells');
ok(table.children(':eq(1)').is('tbody'), 'Structure - month table body');
ok(table.children(':eq(1)').children('tr').length >= 4, 'Structure - month table week count');
- var week = table.children(':eq(1)').children(':first');
+ week = table.children(':eq(1)').children(':first');
ok(week.is('tr'), 'Structure - month table week row');
equal(week.children().length, 7, 'Structure - week child count');
ok(week.children(':first').is('td.ui-datepicker-week-end'), 'Structure - month table first day cell');
ok(week.children(':last').is('td.ui-datepicker-week-end'), 'Structure - month table second day cell');
- ok(dp.children('iframe').length == (iframe ? 1 : 0), 'Structure - iframe');
+ ok(dp.children('iframe').length === (iframe ? 1 : 0), 'Structure - iframe');
inp.datepicker('hide').datepicker('destroy');
// Editable month/year and button panel
inp = init('#inp', {changeMonth: true, changeYear: true, showButtonPanel: true});
inp.focus();
- var title = dp.find('div.ui-datepicker-title');
+ title = dp.find('div.ui-datepicker-title');
ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure - month selector');
ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure - year selector');
- var panel = dp.children(':last');
+ panel = dp.children(':last');
ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure - button panel division');
equal(panel.children().length, 2, 'Structure - button panel child count');
ok(panel.children(':first').is('button.ui-datepicker-current'), 'Structure - today button');
inp.focus();
ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month');
equal(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure multi [2] - child count');
- var child = dp.children(':first');
+ child = dp.children(':first');
ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first month division');
child = dp.children(':eq(1)');
ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second month division');
inp.datepicker('hide').datepicker('destroy');
// Inline
- var inl = init('#inl');
+ inl = init('#inl');
dp = inl.children();
ok(dp.is('.ui-datepicker-inline'), 'Structure inline - main div');
ok(!dp.is('.ui-datepicker-rtl'), 'Structure inline - not right-to-left');
ok(!dp.is('.ui-datepicker-multi'), 'Structure inline - not multi-month');
equal(dp.children().length, 2, 'Structure inline - child count');
- var header = dp.children(':first');
+ header = dp.children(':first');
ok(header.is('div.ui-datepicker-header'), 'Structure inline - header division');
equal(header.children().length, 3, 'Structure inline - header child count');
- var table = dp.children(':eq(1)');
+ table = dp.children(':eq(1)');
ok(table.is('table.ui-datepicker-calendar'), 'Structure inline - month table');
ok(table.children(':first').is('thead'), 'Structure inline - month table thead');
ok(table.children(':eq(1)').is('tbody'), 'Structure inline - month table body');
});
test('customStructure', function() {
- var dp = $('#ui-datepicker-div');
- // Check right-to-left localisation
- var inp = init('#inp', $.datepicker.regional['he']);
+ var iframe, header, panel, title, thead,
+ dp = $('#ui-datepicker-div'),
+ // Check right-to-left localisation
+ inp = init('#inp', $.datepicker.regional.he);
inp.data('showButtonPanel.datepicker',true);
inp.focus();
- var iframe = ($.browser.msie && parseInt($.browser.version) < 7);
+ iframe = ($.browser.msie && parseInt($.browser.version, 10) < 7);
ok(dp.is('.ui-datepicker-rtl'), 'Structure RTL - right-to-left');
- var header = dp.children(':first');
+ header = dp.children(':first');
ok(header.is('div.ui-datepicker-header'), 'Structure RTL - header division');
equal(header.children().length, 3, 'Structure RTL - header child count');
ok(header.children(':first').is('a.ui-datepicker-next'), 'Structure RTL - prev link');
ok(header.children(':eq(1)').is('a.ui-datepicker-prev'), 'Structure RTL - next link');
- var panel = dp.children(':last');
+ panel = dp.children(':last');
ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure RTL - button division');
equal(panel.children().length, 2, 'Structure RTL - button panel child count');
ok(panel.children(':first').is('button.ui-datepicker-close'), 'Structure RTL - close button');
// Hide prev/next
inp = init('#inp', {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)});
inp.val('02/10/2008').focus();
- var header = dp.children(':first');
+ header = dp.children(':first');
ok(header.is('div.ui-datepicker-header'), 'Structure hide prev/next - header division');
equal(header.children().length, 1, 'Structure hide prev/next - links child count');
ok(header.children(':first').is('div.ui-datepicker-title'), 'Structure hide prev/next - title division');
// Changeable Month with read-only year
inp = init('#inp', {changeMonth: true});
inp.focus();
- var title = dp.children(':first').children(':last');
+ title = dp.children(':first').children(':last');
equal(title.children().length, 2, 'Structure changeable month - title child count');
ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure changeable month - month selector');
ok(title.children(':last').is('span.ui-datepicker-year'), 'Structure changeable month - read-only year');
// Changeable year with read-only month
inp = init('#inp', {changeYear: true});
inp.focus();
- var title = dp.children(':first').children(':last');
+ title = dp.children(':first').children(':last');
equal(title.children().length, 2, 'Structure changeable year - title child count');
ok(title.children(':first').is('span.ui-datepicker-month'), 'Structure changeable year - read-only month');
ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure changeable year - year selector');
// Read-only first day of week
inp = init('#inp', {changeFirstDay: false});
inp.focus();
- var thead = dp.find('.ui-datepicker-calendar thead tr');
+ thead = dp.find('.ui-datepicker-calendar thead tr');
equal(thead.children().length, 7, 'Structure read-only first day - thead child count');
equal(thead.find('a').length, 0, 'Structure read-only first day - thead links count');
inp.datepicker('hide').datepicker('destroy');
});
test('keystrokes', function() {
- var inp = init('#inp');
- var date = new Date();
+ var inp = init('#inp'),
+ date = new Date();
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
equalsDate(inp.datepicker('getDate'), date, 'Keystroke enter');
});
test('mouse', function() {
- var inp = init('#inp');
- var dp = $('#ui-datepicker-div');
- var date = new Date();
+ var inl,
+ inp = init('#inp'),
+ dp = $('#ui-datepicker-div'),
+ date = new Date();
inp.val('').datepicker('show');
$('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {});
date.setDate(10);
equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 18),
'Mouse click - next + min/max');
// Inline
- var inl = init('#inl');
- var dp = $('.ui-datepicker-inline', inl);
- var date = new Date();
+ inl = init('#inl');
+ dp = $('.ui-datepicker-inline', inl);
+ date = new Date();
inl.datepicker('setDate', date);
$('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {});
date.setDate(10);
});
test('option', function() {
- var inp = init('#inp');
- var inst = $.data(inp[0], PROP_NAME);
+ var inp = init('#inp'),
+ inst = $.data(inp[0], PROP_NAME);
// Set option
equal(inst.settings.showOn, null, 'Initial setting showOn');
equal($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn');
});
test('change', function() {
- var inp = init('#inp');
- var inst = $.data(inp[0], PROP_NAME);
+ var inp = init('#inp'),
+ inst = $.data(inp[0], PROP_NAME);
equal(inst.settings.showOn, null, 'Initial setting showOn');
equal($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn');
equal($.datepicker._defaults.showOn, 'focus', 'Initial default showOn');
});
test('invocation', function() {
- var inp = init('#inp');
- var dp = $('#ui-datepicker-div');
- var body = $('body');
+ var button, image,
+ inp = init('#inp'),
+ dp = $('#ui-datepicker-div'),
+ body = $('body');
// On focus
- var button = inp.siblings('button');
- ok(button.length == 0, 'Focus - button absent');
- var image = inp.siblings('img');
- ok(image.length == 0, 'Focus - image absent');
+ button = inp.siblings('button');
+ ok(button.length === 0, 'Focus - button absent');
+ image = inp.siblings('img');
+ ok(image.length === 0, 'Focus - image absent');
inp.focus();
ok(dp.is(':visible'), 'Focus - rendered on focus');
inp.simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
ok(!dp.is(':visible'), 'Button - initially hidden');
button = inp.siblings('button');
image = inp.siblings('img');
- ok(button.length == 1, 'Button - button present');
- ok(image.length == 0, 'Button - image absent');
+ ok(button.length === 1, 'Button - button present');
+ ok(image.length === 0, 'Button - image absent');
equal(button.text(), 'Popup', 'Button - button text');
inp.focus();
ok(!dp.is(':visible'), 'Button - not rendered on focus');
buttonImage: 'img/calendar.gif', buttonText: 'Cal'});
ok(!dp.is(':visible'), 'Image button - initially hidden');
button = inp.siblings('button');
- ok(button.length == 0, 'Image button - button absent');
+ ok(button.length === 0, 'Image button - button absent');
image = inp.siblings('img');
- ok(image.length == 1, 'Image button - image present');
+ ok(image.length === 1, 'Image button - image present');
equal(image.attr('src'), 'img/calendar.gif', 'Image button - image source');
equal(image.attr('title'), 'Cal', 'Image button - image text');
inp.focus();
inp = init('#inp', {showOn: 'both', buttonImage: 'img/calendar.gif'});
ok(!dp.is(':visible'), 'Both - initially hidden');
button = inp.siblings('button');
- ok(button.length == 1, 'Both - button present');
+ ok(button.length === 1, 'Both - button present');
image = inp.siblings('img');
- ok(image.length == 0, 'Both - image absent');
+ ok(image.length === 0, 'Both - image absent');
image = button.children('img');
- ok(image.length == 1, 'Both - button image present');
+ ok(image.length === 1, 'Both - button image present');
inp.focus();
ok(dp.is(':visible'), 'Both - rendered on focus');
body.simulate('mousedown', {});
});
test('otherMonths', function() {
- var inp = init('#inp');
- var pop = $('#ui-datepicker-div');
+ var inp = init('#inp'),
+ pop = $('#ui-datepicker-div');
inp.val('06/01/2009').datepicker('show');
equal(pop.find('tbody').text(), '\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0',
'Other months - none');
- ok(pop.find('td:last *').length == 0, 'Other months - no content');
+ ok(pop.find('td:last *').length === 0, 'Other months - no content');
inp.datepicker('hide').datepicker('option', 'showOtherMonths', true).datepicker('show');
equal(pop.find('tbody').text(), '311234567891011121314151617181920212223242526272829301234',
'Other months - show');
- ok(pop.find('td:last span').length == 1, 'Other months - span content');
+ ok(pop.find('td:last span').length === 1, 'Other months - span content');
inp.datepicker('hide').datepicker('option', 'selectOtherMonths', true).datepicker('show');
equal(pop.find('tbody').text(), '311234567891011121314151617181920212223242526272829301234',
'Other months - select');
- ok(pop.find('td:last a').length == 1, 'Other months - link content');
+ ok(pop.find('td:last a').length === 1, 'Other months - link content');
inp.datepicker('hide').datepicker('option', 'showOtherMonths', false).datepicker('show');
equal(pop.find('tbody').text(), '\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0',
'Other months - none');
- ok(pop.find('td:last *').length == 0, 'Other months - no content');
+ ok(pop.find('td:last *').length === 0, 'Other months - no content');
});
test('defaultDate', function() {
- var inp = init('#inp');
- var date = new Date();
+ var inp = init('#inp'),
+ date = new Date();
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
equalsDate(inp.datepicker('getDate'), date, 'Default date null');
});
test('miscellaneous', function() {
- var dp = $('#ui-datepicker-div');
- var inp = init('#inp');
+ var curYear, longNames, shortNames, date,
+ dp = $('#ui-datepicker-div'),
+ inp = init('#inp');
// Year range
- var genRange = function(start, offset) {
- var range = '';
- for (var i = start; i < start + offset; i++) {
+ function genRange(start, offset) {
+ var i = start,
+ range = '';
+ for (; i < start + offset; i++) {
range += i;
}
return range;
- };
- var curYear = new Date().getFullYear();
+ }
+ curYear = new Date().getFullYear();
inp.val('02/04/2008').datepicker('show');
equal(dp.find('.ui-datepicker-year').text(), '2008', 'Year range - read-only default');
inp.datepicker('hide').datepicker('option', {changeYear: true}).datepicker('show');
equal(dp.find('.ui-datepicker-next').text(), 'Next', 'Navigation next - default');
inp.datepicker('hide').datepicker('option', {navigationAsDateFormat: true, prevText: '< M', currentText: 'MM', nextText: 'M >'}).
val('02/04/2008').datepicker('show');
- var longNames = $.datepicker.regional[''].monthNames;
- var shortNames = $.datepicker.regional[''].monthNamesShort;
- var date = new Date();
+ longNames = $.datepicker.regional[''].monthNames;
+ shortNames = $.datepicker.regional[''].monthNamesShort;
+ date = new Date();
equal(dp.find('.ui-datepicker-prev').text(), '< ' + shortNames[0], 'Navigation prev - as date format');
equal(dp.find('.ui-datepicker-current').text(),
longNames[date.getMonth()], 'Navigation current - as date format');
});
test('minMax', function() {
- var inp = init('#inp');
- var lastYear = new Date(2007, 6 - 1, 4);
- var nextYear = new Date(2009, 6 - 1, 4);
- var minDate = new Date(2008, 2 - 1, 29);
- var maxDate = new Date(2008, 12 - 1, 7);
+ var date,
+ inp = init('#inp'),
+ lastYear = new Date(2007, 6 - 1, 4),
+ nextYear = new Date(2009, 6 - 1, 4),
+ minDate = new Date(2008, 2 - 1, 29),
+ maxDate = new Date(2008, 12 - 1, 7);
inp.val('06/04/2008').datepicker('show');
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
equalsDate(inp.datepicker('getDate'), maxDate,
'Min/max - null, 12/07/2008 - ctrl+pgdn');
// Relative dates
- var date = new Date();
+ date = new Date();
date.setDate(date.getDate() - 7);
inp.datepicker('option', {minDate: '-1w', maxDate: '+1 M +10 D '}).
datepicker('hide').val('').datepicker('show');
});
test('setDate', function() {
- var inp = init('#inp');
- var date1 = new Date(2008, 6 - 1, 4);
- var date2 = new Date();
+ var inl, alt, minDate, maxDate, dateAndTimeToSet, dateAndTimeClone,
+ inp = init('#inp'),
+ date1 = new Date(2008, 6 - 1, 4),
+ date2 = new Date();
ok(inp.datepicker('getDate') == null, 'Set date - default');
inp.datepicker('setDate', date1);
equalsDate(inp.datepicker('getDate'), date1, 'Set date - 2008-06-04');
inp.datepicker('setDate', 'c -3 w');
equalsDate(inp.datepicker('getDate'), date1, 'Set date - c -3 w');
// Inline
- var inl = init('#inl');
+ inl = init('#inl');
date1 = new Date(2008, 6 - 1, 4);
date2 = new Date();
equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - default');
inl.datepicker('setDate');
ok(inl.datepicker('getDate') == null, 'Set date inline - null');
// Alternate field
- var alt = $('#alt');
+ alt = $('#alt');
inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'});
date1 = new Date(2008, 6 - 1, 4);
inp.datepicker('setDate', date1);
inp = init('#inp');
date1 = new Date(2008, 1 - 1, 4);
date2 = new Date(2008, 6 - 1, 4);
- var minDate = new Date(2008, 2 - 1, 29);
- var maxDate = new Date(2008, 3 - 1, 28);
+ minDate = new Date(2008, 2 - 1, 29);
+ maxDate = new Date(2008, 3 - 1, 28);
inp.val('').datepicker('option', {minDate: minDate}).datepicker('setDate', date2);
equalsDate(inp.datepicker('getDate'), date2, 'Set date min/max - setDate > min');
inp.datepicker('setDate', date1);
equalsDate(inp.datepicker('getDate'), minDate, 'Set date min/max - setDate < min');
inp.datepicker('setDate', date2);
equalsDate(inp.datepicker('getDate'), maxDate, 'Set date min/max - setDate > max');
- var dateAndTimeToSet = new Date(2008, 3 - 1, 28, 1, 11, 0);
- var dateAndTimeClone = new Date(2008, 3 - 1, 28, 1, 11, 0);
+ dateAndTimeToSet = new Date(2008, 3 - 1, 28, 1, 11, 0);
+ dateAndTimeClone = new Date(2008, 3 - 1, 28, 1, 11, 0);
inp.datepicker('setDate', dateAndTimeToSet);
equal(dateAndTimeToSet.getTime(), dateAndTimeClone.getTime(), 'Date object passed should not be changed by setDate');
});
test('altField', function() {
- var inp = init('#inp');
- var alt = $('#alt');
+ var inp = init('#inp'),
+ alt = $('#alt');
// No alternate field set
alt.val('');
inp.val('06/04/2008').datepicker('show');
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.END});
equal(inp.val(), '', 'Alt field - dp - ctrl+end');
equal(alt.val(), '', 'Alt field - alt - ctrl+end');
-
- return
- // TODO manual entry impl works (see altField demo) but this test doesn't
- // probably something the rewrite won't cover anymore anyway
-
- // Verify alt field is updated on keyup
- alt.val('');
- inp.val('06/04/200').datepicker('show');
- inp.simulate('keydown', {charCode: '8'.charCodeAt(0)});
- inp.simulate('keypress', {charCode: '8'.charCodeAt(0)});
- inp.simulate('keyup', {charCode: '8'.charCodeAt(0)});
- equal(inp.val(), '06/04/2008', 'Alt field - dp - manual entry');
- equal(alt.val(), '2008-06-04', 'Alt field - manual entry');
- // Verify alt field is not updated on keyup if date is invalid
- inp.val('12/04');
- inp.simulate('keydown', {charCode: '/'.charCodeAt(0)});
- inp.simulate('keypress', {charCode: '/'.charCodeAt(0)});
- inp.simulate('keyup', {charCode: '/'.charCodeAt(0)});
- equal(inp.val(), '12/04/', 'Alt field - dp - manual entry incomplete');
- equal(alt.val(), '2008-06-04', 'Alt field - manual entry - not updated');
});
test('autoSize', function() {
inp.datepicker('option', 'dateFormat', 'DD, MM dd, yy');
equal(inp.prop('size'), 29, 'Auto size - DD, MM dd, yy');
// French
- inp.datepicker('option', $.extend({autoSize: false}, $.datepicker.regional['fr']));
+ inp.datepicker('option', $.extend({autoSize: false}, $.datepicker.regional.fr));
equal(inp.prop('size'), 29, 'Auto size - fr - default');
inp.datepicker('option', 'autoSize', true);
equal(inp.prop('size'), 10, 'Auto size - fr - dd/mm/yy');
inp.datepicker('option', 'dateFormat', 'DD, MM dd, yy');
equal(inp.prop('size'), 28, 'Auto size - fr - DD, MM dd, yy');
// Hebrew
- inp.datepicker('option', $.extend({autoSize: false}, $.datepicker.regional['he']));
+ inp.datepicker('option', $.extend({autoSize: false}, $.datepicker.regional.he));
equal(inp.prop('size'), 28, 'Auto size - he - default');
inp.datepicker('option', 'autoSize', true);
equal(inp.prop('size'), 10, 'Auto size - he - dd/mm/yy');
});
test('daylightSaving', function() {
- var inp = init('#inp');
- var dp = $('#ui-datepicker-div');
+ var inp = init('#inp'),
+ dp = $('#ui-datepicker-div');
ok(true, 'Daylight saving - ' + new Date());
// Australia, Sydney - AM change, southern hemisphere
inp.val('04/01/2008').datepicker('show');
equal(inp.val(), '11/03/2008', 'Daylight saving - US 11/03/2008');
});
-var beforeShowThis = null;
-var beforeShowInput = null;
-var beforeShowInst = null;
+var beforeShowThis = null,
+ beforeShowInput = null,
+ beforeShowInst = null,
+ beforeShowDayThis = null,
+ beforeShowDayOK = true;
+
function beforeAll(input, inst) {
beforeShowThis = this;
return {currentText: 'Current'};
}
-var beforeShowDayThis = null;
-var beforeShowDayOK = true;
-
function beforeDay(date) {
beforeShowDayThis = this;
beforeShowDayOK &= (date > new Date(2008, 1 - 1, 26) &&
date < new Date(2008, 3 - 1, 6));
- return [(date.getDate() % 2 == 0), (date.getDate() % 10 == 0 ? 'day10' : ''),
- (date.getDate() % 3 == 0 ? 'Divisble by 3' : '')];
+ return [(date.getDate() % 2 === 0), (date.getDate() % 10 === 0 ? 'day10' : ''),
+ (date.getDate() % 3 === 0 ? 'Divisble by 3' : '')];
}
function calcWeek(date) {
- var doy = date.getDate() + 6;
- for (var m = date.getMonth() - 1; m >= 0; m--)
+ var doy = date.getDate() + 6,
+ m = date.getMonth() - 1;
+ for (; m >= 0; m--) {
doy += $.datepicker._getDaysInMonth(date.getFullYear(), m);
+ }
// Simple count from 01/01 starting at week 1
return Math.floor(doy / 7);
}
test('callbacks', function() {
// Before show
- var inp = init('#inp', {beforeShow: beforeAll});
- var inst = $.data(inp[0], 'datepicker');
+ var dp, day20, day21,
+ inp = init('#inp', {beforeShow: beforeAll}),
+ inst = $.data(inp[0], 'datepicker');
equal($.datepicker._get(inst, 'currentText'), 'Today', 'Before show - initial');
inp.val('02/04/2008').datepicker('show');
equal($.datepicker._get(inst, 'currentText'), 'Current', 'Before show - changed');
- ok(beforeShowThis.id == inp[0].id, 'Before show - this OK');
- ok(beforeShowInput.id == inp[0].id, 'Before show - input OK');
+ ok(beforeShowThis.id === inp[0].id, 'Before show - this OK');
+ ok(beforeShowInput.id === inp[0].id, 'Before show - input OK');
deepEqual(beforeShowInst, inst, 'Before show - inst OK');
inp.datepicker('hide').datepicker('destroy');
// Before show day
inp = init('#inp', {beforeShowDay: beforeDay});
- var dp = $('#ui-datepicker-div');
+ dp = $('#ui-datepicker-div');
inp.val('02/04/2008').datepicker('show');
- ok(beforeShowDayThis.id == inp[0].id, 'Before show day - this OK');
+ ok(beforeShowDayThis.id === inp[0].id, 'Before show day - this OK');
ok(beforeShowDayOK, 'Before show day - dates OK');
- var day20 = dp.find('.ui-datepicker-calendar td:contains("20")');
- var day21 = dp.find('.ui-datepicker-calendar td:contains("21")');
+ day20 = dp.find('.ui-datepicker-calendar td:contains("20")');
+ day21 = dp.find('.ui-datepicker-calendar td:contains("21")');
ok(!day20.is('.ui-datepicker-unselectable'), 'Before show day - unselectable 20');
ok(day21.is('.ui-datepicker-unselectable'), 'Before show day - unselectable 21');
ok(day20.is('.day10'), 'Before show day - CSS 20');
ok(!day21.is('.day10'), 'Before show day - CSS 21');
ok(!day20.attr('title'), 'Before show day - title 20');
- ok(day21.attr('title') == 'Divisble by 3', 'Before show day - title 21');
+ ok(day21.attr('title') === 'Divisble by 3', 'Before show day - title 21');
inp.datepicker('hide').datepicker('destroy');
});
test('localisation', function() {
- var inp = init('#inp', $.datepicker.regional['fr']);
+ var dp, month, day, date,
+ inp = init('#inp', $.datepicker.regional.fr);
inp.datepicker('option', {dateFormat: 'DD, d MM yy', showButtonPanel:true, changeMonth:true, changeYear:true}).val('').datepicker('show');
- var dp = $('#ui-datepicker-div');
+ dp = $('#ui-datepicker-div');
equal($('.ui-datepicker-close', dp).text(), 'Fermer', 'Localisation - close');
$('.ui-datepicker-close', dp).simulate('mouseover');
equal($('.ui-datepicker-prev', dp).text(), 'Précédent', 'Localisation - previous');
equal($('.ui-datepicker-current', dp).text(), 'Aujourd\'hui', 'Localisation - current');
equal($('.ui-datepicker-next', dp).text(), 'Suivant', 'Localisation - next');
- var month = 0;
+ month = 0;
$('.ui-datepicker-month option', dp).each(function() {
- equal($(this).text(), $.datepicker.regional['fr'].monthNamesShort[month],
+ equal($(this).text(), $.datepicker.regional.fr.monthNamesShort[month],
'Localisation - month ' + month);
month++;
});
- var day = 1;
+ day = 1;
$('.ui-datepicker-calendar th', dp).each(function() {
- equal($(this).text(), $.datepicker.regional['fr'].dayNamesMin[day],
+ equal($(this).text(), $.datepicker.regional.fr.dayNamesMin[day],
'Localisation - day ' + day);
day = (day + 1) % 7;
});
inp.simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
- var date = new Date();
- equal(inp.val(), $.datepicker.regional['fr'].dayNames[date.getDay()] + ', ' +
- date.getDate() + ' ' + $.datepicker.regional['fr'].monthNames[date.getMonth()] +
+ date = new Date();
+ equal(inp.val(), $.datepicker.regional.fr.dayNames[date.getDay()] + ', ' +
+ date.getDate() + ' ' + $.datepicker.regional.fr.monthNames[date.getMonth()] +
' ' + date.getFullYear(), 'Localisation - formatting');
});
test('noWeekends', function() {
- for (var i = 1; i <= 31; i++) {
- var date = new Date(2001, 1 - 1, i);
+ var i, date;
+ for (i = 1; i <= 31; i++) {
+ date = new Date(2001, 1 - 1, i);
deepEqual($.datepicker.noWeekends(date), [(i + 1) % 7 >= 2, ''],
'No weekends ' + date);
}
test('parseDate', function() {
init('#inp');
+ var currentYear, gmtDate, fr, settings, zh;
ok($.datepicker.parseDate('d m y', '') == null, 'Parse date empty');
equalsDate($.datepicker.parseDate('d m y', '3 2 01'),
new Date(2001, 2 - 1, 3), 'Parse date d m y');
equalsDate($.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy',
'day 3 of February (\'Saturday\'), 2001'), new Date(2001, 2 - 1, 3),
'Parse date \'day\' d \'of\' MM (\'\'DD\'\'), yy');
- var currentYear = new Date().getFullYear();
+ currentYear = new Date().getFullYear();
equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000) + '-02-03'),
new Date(currentYear, 2 - 1, 3), 'Parse date y-m-d - default cutuff');
equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 10) + '-02-03'),
new Date(currentYear + 60, 2 - 1, 3), 'Parse date y-m-d - cutoff +60');
equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 61) + '-02-03', {shortYearCutoff: '+60'}),
new Date(currentYear - 39, 2 - 1, 3), 'Parse date y-m-d - cutoff +60');
- var gmtDate = new Date(2001, 2 - 1, 3);
+ gmtDate = new Date(2001, 2 - 1, 3);
gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset());
equalsDate($.datepicker.parseDate('@', '981158400000'), gmtDate, 'Parse date @');
equalsDate($.datepicker.parseDate('!', '631167552000000000'), gmtDate, 'Parse date !');
- var fr = $.datepicker.regional['fr'];
- var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
+ fr = $.datepicker.regional.fr;
+ settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
equalsDate($.datepicker.parseDate('D d M y', 'Lun. 9 Avril 01', settings),
new Date(2001, 4 - 1, 9), 'Parse date D M y with settings');
'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9),
'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings');
- var zh = $.datepicker.regional['zh-CN'];
+ zh = $.datepicker.regional['zh-CN'];
equalsDate($.datepicker.parseDate('yy M d', '2011 十一 22', zh),
new Date(2011, 11 - 1, 22), 'Parse date yy M d with zh-CN');
});
test('parseDateErrors', function() {
init('#inp');
- var expectError = function(expr, value, error) {
+ var fr, settings;
+ function expectError(expr, value, error) {
try {
expr();
ok(false, 'Parsed error ' + value);
catch (e) {
equal(e, error, 'Parsed error ' + value);
}
- };
+ }
expectError(function() { $.datepicker.parseDate(null, 'Sat 2 01'); },
'Sat 2 01', 'Invalid arguments');
expectError(function() { $.datepicker.parseDate('d m y', null); },
'day 3 of Mon2 ("Day7"), 2001', 'Unexpected literal at position 19');
expectError(function() { $.datepicker.parseDate('d m y', '29 2 01'); },
'29 2 01 - d m y', 'Invalid date');
- var fr = $.datepicker.regional['fr'];
- var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
+ fr = $.datepicker.regional.fr;
+ settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
expectError(function() { $.datepicker.parseDate('D d M y', 'Mon 9 Avr 01', settings); },
'Mon 9 Avr 01 - D d M y', 'Unknown name at position 0');
test('formatDate', function() {
init('#inp');
+ var gmtDate, fr, settings;
equal($.datepicker.formatDate('d m y', new Date(2001, 2 - 1, 3)),
'3 2 01', 'Format date d m y');
equal($.datepicker.formatDate('dd mm yy', new Date(2001, 2 - 1, 3)),
equal($.datepicker.formatDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy',
new Date(2001, 2 - 1, 3)), 'day 3 of February (\'Saturday\'), 2001',
'Format date \'day\' d \'of\' MM (\'\'DD\'\'), yy');
- var gmtDate = new Date(2001, 2 - 1, 3);
+ gmtDate = new Date(2001, 2 - 1, 3);
gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset());
equal($.datepicker.formatDate('@', gmtDate), '981158400000', 'Format date @');
equal($.datepicker.formatDate('!', gmtDate), '631167552000000000', 'Format date !');
- var fr = $.datepicker.regional['fr'];
- var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
+ fr = $.datepicker.regional.fr;
+ settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
equal($.datepicker.formatDate('D M y', new Date(2001, 4 - 1, 9), settings),
'Lun. Avril 01', 'Format date D M y with settings');