Author:
paz...@gmail.com
Date: Thu Jun 11 09:38:03 2009
New Revision: 2702
Modified:
branches/dev/datepicker/tests/unit/datepicker/datepicker_core.js
branches/dev/datepicker/tests/unit/datepicker/datepicker_events.js
branches/dev/datepicker/tests/unit/datepicker/datepicker_options.js
branches/dev/datepicker/ui/i18n/ui.datepicker-ar.js
branches/dev/datepicker/ui/ui.datepicker.js
Log:
datepicker: fixed unit tests for namespace change. further refactoring
(work in progress)
Modified: branches/dev/datepicker/tests/unit/datepicker/datepicker_core.js
==============================================================================
--- branches/dev/datepicker/tests/unit/datepicker/datepicker_core.js
(original)
+++ branches/dev/datepicker/tests/unit/datepicker/datepicker_core.js Thu
Jun 11 09:38:03 2009
@@ -32,7 +32,7 @@
}
function init(id, options) {
- $.datepicker.setDefaults($.datepicker.regional['']);
+ $.ui.datepicker.setDefaults($.ui.datepicker.regional['']);
return $(id).datepicker($.extend({duration: ''}, options || {}));
}
@@ -160,7 +160,7 @@
test('customStructure', function() {
var dp = $('#ui-datepicker-div');
// Check right-to-left localisation
- var inp = init('#inp', $.datepicker.regional['he']);
+ var inp = init('#inp', $.ui.datepicker.regional['he']);
inp.data('showButtonPanel.datepicker',true);
inp.focus();
var iframe = ($.browser.msie && parseInt($.browser.version) < 7);
Modified: branches/dev/datepicker/tests/unit/datepicker/datepicker_events.js
==============================================================================
--- branches/dev/datepicker/tests/unit/datepicker/datepicker_events.js
(original)
+++ branches/dev/datepicker/tests/unit/datepicker/datepicker_events.js Thu
Jun 11 09:38:03 2009
@@ -29,17 +29,17 @@
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
equals(selectedThis, inp[0], 'Callback selected this');
equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback selected inst');
- equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date),
+ equals(selectedDate, $.ui.datepicker.formatDate('mm/dd/yy', date),
'Callback selected date');
inp.val('').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}).
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
date.setDate(date.getDate() + 7);
- equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date),
+ equals(selectedDate, $.ui.datepicker.formatDate('mm/dd/yy', date),
'Callback selected date - ctrl+down');
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ESC});
- equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date),
+ equals(selectedDate, $.ui.datepicker.formatDate('mm/dd/yy', date),
'Callback selected date - esc');
// onChangeMonthYear
inp.datepicker('option', {onChangeMonthYear: callback2, onSelect: null}).
@@ -104,7 +104,7 @@
equals(selectedDate, '', 'Callback close date - esc');
inp.val('').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
- equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', new Date()),
+ equals(selectedDate, $.ui.datepicker.formatDate('mm/dd/yy', new Date()),
'Callback close date - enter');
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ESC});
Modified:
branches/dev/datepicker/tests/unit/datepicker/datepicker_options.js
==============================================================================
--- branches/dev/datepicker/tests/unit/datepicker/datepicker_options.js
(original)
+++ branches/dev/datepicker/tests/unit/datepicker/datepicker_options.js Thu
Jun 11 09:38:03 2009
@@ -8,11 +8,11 @@
test('setDefaults', function() {
var inp = init('#inp');
- equals($.datepicker._defaults.showOn, 'focus', 'Initial showOn');
- $.datepicker.setDefaults({showOn: 'button'});
- equals($.datepicker._defaults.showOn, 'button', 'Change default showOn');
- $.datepicker.setDefaults({showOn: 'focus'});
- equals($.datepicker._defaults.showOn, 'focus', 'Restore showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Initial showOn');
+ $.ui.datepicker.setDefaults({showOn: 'button'});
+ equals($.ui.datepicker._defaults.showOn, 'button', 'Change default
showOn');
+ $.ui.datepicker.setDefaults({showOn: 'focus'});
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Restore showOn');
});
test('option', function() {
@@ -20,20 +20,20 @@
var inst = $.data(inp[0], PROP_NAME);
// Set option
equals(inst.settings.showOn, null, 'Initial setting showOn');
- equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance
showOn');
- equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn');
+ equals($.ui.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance
showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Initial default
showOn');
inp.datepicker('option', 'showOn', 'button');
equals(inst.settings.showOn, 'button', 'Change setting showOn');
- equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance
showOn');
- equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
+ equals($.ui.datepicker._get(inst, 'showOn'), 'button', 'Change instance
showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Retain default
showOn');
inp.datepicker('option', {showOn: 'both'});
equals(inst.settings.showOn, 'both', 'Change setting showOn');
- equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance
showOn');
- equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
+ equals($.ui.datepicker._get(inst, 'showOn'), 'both', 'Change instance
showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Retain default
showOn');
inp.datepicker('option', 'showOn', undefined);
equals(inst.settings.showOn, null, 'Clear setting showOn');
- equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance
showOn');
- equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
+ equals($.ui.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance
showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Retain default
showOn');
// Get option
inp = init('#inp');
equals(inp.datepicker('option', 'showOn'), 'focus', 'Initial setting
showOn');
@@ -42,7 +42,7 @@
inp.datepicker('option', 'showOn', undefined);
equals(inp.datepicker('option', 'showOn'), 'focus', 'Reset instance
showOn');
same(inp.datepicker('option', 'all'), {duration: ''}, 'Get instance
settings');
- same(inp.datepicker('option', 'defaults'), $.datepicker._defaults,
+ same(inp.datepicker('option', 'defaults'), $.ui.datepicker._defaults,
'Get default settings');
});
@@ -50,20 +50,20 @@
var inp = init('#inp');
var inst = $.data(inp[0], PROP_NAME);
equals(inst.settings.showOn, null, 'Initial setting showOn');
- equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance
showOn');
- equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn');
+ equals($.ui.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance
showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Initial default
showOn');
inp.datepicker('change', 'showOn', 'button');
equals(inst.settings.showOn, 'button', 'Change setting showOn');
- equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance
showOn');
- equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
+ equals($.ui.datepicker._get(inst, 'showOn'), 'button', 'Change instance
showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Retain default
showOn');
inp.datepicker('change', {showOn: 'both'});
equals(inst.settings.showOn, 'both', 'Change setting showOn');
- equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance
showOn');
- equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
+ equals($.ui.datepicker._get(inst, 'showOn'), 'both', 'Change instance
showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Retain default
showOn');
inp.datepicker('change', 'showOn', undefined);
equals(inst.settings.showOn, null, 'Clear setting showOn');
- equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance
showOn');
- equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');
+ equals($.ui.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance
showOn');
+ equals($.ui.datepicker._defaults.showOn, 'focus', 'Retain default
showOn');
});
test('invocation', function() {
@@ -245,8 +245,8 @@
equals(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 longNames = $.ui.datepicker.regional[''].monthNames;
+ var shortNames = $.ui.datepicker.regional[''].monthNamesShort;
var date = new Date();
equals(dp.find('.ui-datepicker-prev').text(), '< ' +
shortNames[0], 'Navigation prev - as date format');
equals(dp.find('.ui-datepicker-current').text(),
@@ -572,7 +572,7 @@
function calcWeek(date) {
var doy = date.getDate() + 6;
for (var m = date.getMonth() - 1; m >= 0; m--)
- doy += $.datepicker._getDaysInMonth(date.getFullYear(), m);
+ doy += $.ui.datepicker._getDaysInMonth(date.getFullYear(), m);
// Simple count from 01/01 starting at week 1
return Math.floor(doy / 7);
}
@@ -581,9 +581,9 @@
// Before show
var inp = init('#inp', {beforeShow: beforeAll});
var inst = $.data(inp[0], 'datepicker');
- equals($.datepicker._get(inst, 'currentText'), 'Today', 'Before show -
initial');
+ equals($.ui.datepicker._get(inst, 'currentText'), 'Today', 'Before show -
initial');
inp.val('02/04/2008').datepicker('show');
- equals($.datepicker._get(inst, 'currentText'), 'Current', 'Before show -
changed');
+ equals($.ui.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');
isObj(beforeShowInst, inst, 'Before show - inst OK');
@@ -606,7 +606,7 @@
});
test('localisation', function() {
- var inp = init('#inp', $.datepicker.regional['fr']);
+ var inp = init('#inp', $.ui.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');
equals($('.ui-datepicker-close', dp).text(), 'Fermer', 'Localisation -
close');
@@ -616,106 +616,106 @@
equals($('.ui-datepicker-next', dp).text(), 'Suiv>', 'Localisation -
next');
var month = 0;
$('.ui-datepicker-month option', dp).each(function() {
- equals($(this).text(),
$.datepicker.regional['fr'].monthNamesShort[month],
+ equals($(this).text(),
$.ui.datepicker.regional['fr'].monthNamesShort[month],
'Localisation - month ' + month);
month++;
});
var day = 1;
$('.ui-datepicker-calendar th', dp).each(function() {
- equals($(this).text(), $.datepicker.regional['fr'].dayNamesMin[day],
+ equals($(this).text(), $.ui.datepicker.regional['fr'].dayNamesMin[day],
'Localisation - day ' + day);
day = (day + 1) % 7;
});
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});
var date = new Date();
- equals(inp.val(), $.datepicker.regional['fr'].dayNames[date.getDay()]
+ ', ' +
- date.getDate() + ' ' +
$.datepicker.regional['fr'].monthNames[date.getMonth()] +
+ equals(inp.val(), $.ui.datepicker.regional['fr'].dayNames[date.getDay()]
+ ', ' +
+ date.getDate() + ' ' +
$.ui.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);
- isSet($.datepicker.noWeekends(date), [(i + 1) % 7 >= 2, ''],
+ isSet($.ui.datepicker.noWeekends(date), [(i + 1) % 7 >= 2, ''],
'No weekends ' + date);
}
});
test('iso8601Week', function() {
var date = new Date(2000, 12 - 1, 31);
- equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date);
date = new Date(2001, 1 - 1, 1);
- equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2001, 1 - 1, 7);
- equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2001, 1 - 1, 8);
- equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date);
date = new Date(2003, 12 - 1, 28);
- equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date);
date = new Date(2003, 12 - 1, 29);
- equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2004, 1 - 1, 4);
- equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2004, 1 - 1, 5);
- equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date);
date = new Date(2009, 12 - 1, 28);
- equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date);
date = new Date(2010, 1 - 1, 3);
- equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date);
date = new Date(2010, 1 - 1, 4);
- equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
date = new Date(2010, 1 - 1, 10);
- equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
+ equals($.ui.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date);
});
test('parseDate', function() {
init('#inp');
- ok($.datepicker.parseDate('d m y', '') == null, 'Parse date empty');
- equalsDate($.datepicker.parseDate('d m y', '3 2 01'),
+ ok($.ui.datepicker.parseDate('d m y', '') == null, 'Parse date empty');
+ equalsDate($.ui.datepicker.parseDate('d m y', '3 2 01'),
new Date(2001, 2 - 1, 3), 'Parse date d m y');
- equalsDate($.datepicker.parseDate('dd mm yy', '03 02 2001'),
+ equalsDate($.ui.datepicker.parseDate('dd mm yy', '03 02 2001'),
new Date(2001, 2 - 1, 3), 'Parse date dd mm yy');
- equalsDate($.datepicker.parseDate('d m y', '13 12 01'),
+ equalsDate($.ui.datepicker.parseDate('d m y', '13 12 01'),
new Date(2001, 12 - 1, 13), 'Parse date d m y');
- equalsDate($.datepicker.parseDate('dd mm yy', '13 12 2001'),
+ equalsDate($.ui.datepicker.parseDate('dd mm yy', '13 12 2001'),
new Date(2001, 12 - 1, 13), 'Parse date dd mm yy');
- equalsDate($.datepicker.parseDate('y-o', '2001-34'),
+ equalsDate($.ui.datepicker.parseDate('y-o', '2001-34'),
new Date(2001, 2 - 1, 3), 'Parse date y-o');
- equalsDate($.datepicker.parseDate('yy-oo', '2001-347'),
+ equalsDate($.ui.datepicker.parseDate('yy-oo', '2001-347'),
new Date(2001, 12 - 1, 13), 'Parse date yy oo');
- equalsDate($.datepicker.parseDate('oo yy', '348 2004'),
+ equalsDate($.ui.datepicker.parseDate('oo yy', '348 2004'),
new Date(2004, 12 - 1, 13), 'Parse date oo-yy');
- equalsDate($.datepicker.parseDate('D d M y', 'Sat 3 Feb 01'),
+ equalsDate($.ui.datepicker.parseDate('D d M y', 'Sat 3 Feb 01'),
new Date(2001, 2 - 1, 3), 'Parse date D d M y');
- equalsDate($.datepicker.parseDate('d MM DD yy', '3 February Saturday
2001'),
+ equalsDate($.ui.datepicker.parseDate('d MM DD yy', '3 February Saturday
2001'),
new Date(2001, 2 - 1, 3), 'Parse date dd MM DD yy');
- equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Saturday, February 3,
2001'),
+ equalsDate($.ui.datepicker.parseDate('DD, MM d, yy', 'Saturday, February
3, 2001'),
new Date(2001, 2 - 1, 3), 'Parse date DD, MM d, yy');
- equalsDate($.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy',
+ equalsDate($.ui.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');
- equalsDate($.datepicker.parseDate('y-m-d', '01-02-03'),
+ equalsDate($.ui.datepicker.parseDate('y-m-d', '01-02-03'),
new Date(2001, 2 - 1, 3), 'Parse date y-m-d - default cutoff');
- equalsDate($.datepicker.parseDate('y-m-d', '51-02-03'),
+ equalsDate($.ui.datepicker.parseDate('y-m-d', '51-02-03'),
new Date(1951, 2 - 1, 3), 'Parse date y-m-d - default cutoff');
- equalsDate($.datepicker.parseDate('y-m-d', '51-02-03', {shortYearCutoff:
80}),
+ equalsDate($.ui.datepicker.parseDate('y-m-d', '51-02-03',
{shortYearCutoff: 80}),
new Date(2051, 2 - 1, 3), 'Parse date y-m-d - cutoff 80');
- equalsDate($.datepicker.parseDate('y-m-d', '51-02-03',
{shortYearCutoff: '+60'}),
+ equalsDate($.ui.datepicker.parseDate('y-m-d', '51-02-03',
{shortYearCutoff: '+60'}),
new Date(2051, 2 - 1, 3), 'Parse date y-m-d - cutoff +60');
var 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'];
+ equalsDate($.ui.datepicker.parseDate('@', '981158400000'),
gmtDate, 'Parse date @');
+ equalsDate($.ui.datepicker.parseDate('!', '631167552000000000'),
gmtDate, 'Parse date !');
+ var fr = $.ui.datepicker.regional['fr'];
var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
- equalsDate($.datepicker.parseDate('D d M y', 'Lun 9 Avr 01', settings),
+ equalsDate($.ui.datepicker.parseDate('D d M y', 'Lun 9 Avr 01', settings),
new Date(2001, 4 - 1, 9), 'Parse date D M y with settings');
- equalsDate($.datepicker.parseDate('d MM DD yy', '9 Avril Lundi 2001',
settings),
+ equalsDate($.ui.datepicker.parseDate('d MM DD yy', '9 Avril Lundi 2001',
settings),
new Date(2001, 4 - 1, 9), 'Parse date d MM DD yy with settings');
- equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Lundi, Avril 9, 2001',
settings),
+ equalsDate($.ui.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');
- equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy',
+ equalsDate($.ui.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'),
yy',
'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9),
'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings');
});
@@ -731,83 +731,83 @@
equals(e, error, 'Parsed error ' + value);
}
};
- expectError(function() { $.datepicker.parseDate(null, 'Sat 2 01'); },
+ expectError(function() { $.ui.datepicker.parseDate(null, 'Sat 2 01'); },
'Sat 2 01', 'Invalid arguments');
- expectError(function() { $.datepicker.parseDate('d m y', null); },
+ expectError(function() { $.ui.datepicker.parseDate('d m y', null); },
'null', 'Invalid arguments');
- expectError(function() { $.datepicker.parseDate('d m y', 'Sat 2 01'); },
+ expectError(function() { $.ui.datepicker.parseDate('d m y', 'Sat 2 01');
},
'Sat 2 01 - d m y', 'Missing number at position 0');
- expectError(function() { $.datepicker.parseDate('dd mm yy', 'Sat 2 01');
},
+ expectError(function() { $.ui.datepicker.parseDate('dd mm yy', 'Sat 2
01'); },
'Sat 2 01 - dd mm yy', 'Missing number at position 0');
- expectError(function() { $.datepicker.parseDate('d m y', '3 Feb 01'); },
+ expectError(function() { $.ui.datepicker.parseDate('d m y', '3 Feb 01');
},
'3 Feb 01 - d m y', 'Missing number at position 2');
- expectError(function() { $.datepicker.parseDate('dd mm yy', '3 Feb 01');
},
+ expectError(function() { $.ui.datepicker.parseDate('dd mm yy', '3 Feb
01'); },
'3 Feb 01 - dd mm yy', 'Missing number at position 2');
- expectError(function() { $.datepicker.parseDate('d m y', '3 2 AD01'); },
+ expectError(function() { $.ui.datepicker.parseDate('d m y', '3 2 AD01');
},
'3 2 AD01 - d m y', 'Missing number at position 4');
- expectError(function() { $.datepicker.parseDate('d m yy', '3 2 AD01'); },
+ expectError(function() { $.ui.datepicker.parseDate('d m yy', '3 2 AD01');
},
'3 2 AD01 - dd mm yy', 'Missing number at position 4');
- expectError(function() { $.datepicker.parseDate('y-o', '2001-D01'); },
+ expectError(function() { $.ui.datepicker.parseDate('y-o', '2001-D01'); },
'2001-D01 - y-o', 'Missing number at position 5');
- expectError(function() { $.datepicker.parseDate('yy-oo', '2001-D01'); },
+ expectError(function() { $.ui.datepicker.parseDate('yy-oo', '2001-D01');
},
'2001-D01 - yy-oo', 'Missing number at position 5');
- expectError(function() { $.datepicker.parseDate('D d M y', 'D7 3 Feb
01'); },
+ expectError(function() { $.ui.datepicker.parseDate('D d M y', 'D7 3 Feb
01'); },
'D7 3 Feb 01 - D d M y', 'Unknown name at position 0');
- expectError(function() { $.datepicker.parseDate('D d M y', 'Sat 3 M2
01'); },
+ expectError(function() { $.ui.datepicker.parseDate('D d M y', 'Sat 3 M2
01'); },
'Sat 3 M2 01 - D d M y', 'Unknown name at position 6');
- expectError(function() { $.datepicker.parseDate('DD, MM d,
yy', 'Saturday- Feb 3, 2001'); },
+ expectError(function() { $.ui.datepicker.parseDate('DD, MM d,
yy', 'Saturday- Feb 3, 2001'); },
'Saturday- Feb 3, 2001 - DD, MM d, yy', 'Unexpected literal at position
8');
- expectError(function() { $.datepicker.parseDate('\'day\' d \'of\' MM
(\'\'DD\'\'), yy',
+ expectError(function() { $.ui.datepicker.parseDate('\'day\' d \'of\' MM
(\'\'DD\'\'), yy',
'day 3 of February ("Saturday"), 2001'); },
'day 3 of Mon2 ("Day7"), 2001', 'Unexpected literal at position 19');
- expectError(function() { $.datepicker.parseDate('d m y', '29 2 01'); },
+ expectError(function() { $.ui.datepicker.parseDate('d m y', '29 2 01'); },
'29 2 01 - d m y', 'Invalid date');
- var fr = $.datepicker.regional['fr'];
+ var fr = $.ui.datepicker.regional['fr'];
var 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); },
+ expectError(function() { $.ui.datepicker.parseDate('D d M y', 'Mon 9 Avr
01', settings); },
'Mon 9 Avr 01 - D d M y', 'Unknown name at position 0');
- expectError(function() { $.datepicker.parseDate('D d M y', 'Lun 9 Apr
01', settings); },
+ expectError(function() { $.ui.datepicker.parseDate('D d M y', 'Lun 9 Apr
01', settings); },
'Lun 9 Apr 01 - D d M y', 'Unknown name at position 6');
});
test('formatDate', function() {
init('#inp');
- equals($.datepicker.formatDate('d m y', new Date(2001, 2 - 1, 3)),
+ equals($.ui.datepicker.formatDate('d m y', new Date(2001, 2 - 1, 3)),
'3 2 01', 'Format date d m y');
- equals($.datepicker.formatDate('dd mm yy', new Date(2001, 2 - 1, 3)),
+ equals($.ui.datepicker.formatDate('dd mm yy', new Date(2001, 2 - 1, 3)),
'03 02 2001', 'Format date dd mm yy');
- equals($.datepicker.formatDate('d m y', new Date(2001, 12 - 1, 13)),
+ equals($.ui.datepicker.formatDate('d m y', new Date(2001, 12 - 1, 13)),
'13 12 01', 'Format date d m y');
- equals($.datepicker.formatDate('dd mm yy', new Date(2001, 12 - 1, 13)),
+ equals($.ui.datepicker.formatDate('dd mm yy', new Date(2001, 12 - 1, 13)),
'13 12 2001', 'Format date dd mm yy');
- equals($.datepicker.formatDate('yy-o', new Date(2001, 2 - 1, 3)),
+ equals($.ui.datepicker.formatDate('yy-o', new Date(2001, 2 - 1, 3)),
'2001-34', 'Format date yy-o');
- equals($.datepicker.formatDate('yy-oo', new Date(2001, 2 - 1, 3)),
+ equals($.ui.datepicker.formatDate('yy-oo', new Date(2001, 2 - 1, 3)),
'2001-034', 'Format date yy-oo');
- equals($.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3)),
+ equals($.ui.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3)),
'Sat Feb 01', 'Format date D M y');
- equals($.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3)),
+ equals($.ui.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3)),
'Saturday February 2001', 'Format date DD MM yy');
- equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1, 3)),
+ equals($.ui.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1,
3)),
'Saturday, February 3, 2001', 'Format date DD, MM d, yy');
- equals($.datepicker.formatDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy',
+ equals($.ui.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.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset());
- equals($.datepicker.formatDate('@', gmtDate), '981158400000', 'Format
date @');
- equals($.datepicker.formatDate('!',
gmtDate), '631167552000000000', 'Format date !');
- var fr = $.datepicker.regional['fr'];
+ equals($.ui.datepicker.formatDate('@', gmtDate), '981158400000', 'Format
date @');
+ equals($.ui.datepicker.formatDate('!',
gmtDate), '631167552000000000', 'Format date !');
+ var fr = $.ui.datepicker.regional['fr'];
var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
- equals($.datepicker.formatDate('D M y', new Date(2001, 4 - 1, 9),
settings),
+ equals($.ui.datepicker.formatDate('D M y', new Date(2001, 4 - 1, 9),
settings),
'Lun Avr 01', 'Format date D M y with settings');
- equals($.datepicker.formatDate('DD MM yy', new Date(2001, 4 - 1, 9),
settings),
+ equals($.ui.datepicker.formatDate('DD MM yy', new Date(2001, 4 - 1, 9),
settings),
'Lundi Avril 2001', 'Format date DD MM yy with settings');
- equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 4 - 1, 9),
settings),
+ equals($.ui.datepicker.formatDate('DD, MM d, yy', new Date(2001, 4 - 1,
9), settings),
'Lundi, Avril 9, 2001', 'Format date DD, MM d, yy with settings');
- equals($.datepicker.formatDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy',
+ equals($.ui.datepicker.formatDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy',
new Date(2001, 4 - 1, 9), settings), 'jour 9 de Avril (\'Lundi\'), 2001',
'Format date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings');
});
Modified: branches/dev/datepicker/ui/i18n/ui.datepicker-ar.js
==============================================================================
--- branches/dev/datepicker/ui/i18n/ui.datepicker-ar.js (original)
+++ branches/dev/datepicker/ui/i18n/ui.datepicker-ar.js Thu Jun 11 09:38:03
2009
@@ -2,8 +2,8 @@
/* Khaled Al Horani --
kok...@gmail.com */
/* خالد الحوراني --
kok...@gmail.com */
/* NOTE: monthNames are the original months names and they are the Arabic
names, not the new months name فبراير - يناير and there isn't any Arabic
roots for these months */
-jQuery(function($){
- $.datepicker.regional['ar'] = {
+jQuery(function($) {
+ $.ui.datepicker.regional['ar'] = {
closeText: 'إغلاق',
prevText: '<السابق',
nextText: 'التالي>',
@@ -19,5 +19,5 @@
isRTL: true,
showMonthAfterYear: false,
yearSuffix: ''};
- $.datepicker.setDefaults($.datepicker.regional['ar']);
+ $.ui.datepicker.setDefaults($.ui.datepicker.regional['ar']);
});
Modified: branches/dev/datepicker/ui/ui.datepicker.js
==============================================================================
--- branches/dev/datepicker/ui/ui.datepicker.js (original)
+++ branches/dev/datepicker/ui/ui.datepicker.js Thu Jun 11 09:38:03 2009
@@ -13,30 +13,25 @@
(function($) {
-var PROP_NAME = 'datepicker';
+var PROP_NAME = 'datepicker',
+ ticksTo1970 = (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970
/ 100) + Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
+ /* Class name added to elements to indicate already configured with a
date picker. */
+ markerClassName = 'hasDatepicker';
-$.widget('ui.datepicker', {
+$.widget('ui.datepicker', {
_init: function() {
- var self = this, o = this.options;
+ var self = this,
+ options = self.options;
- this._defaults = o;
- this.debug = false; // Change this to true to start debugging
- this._curInst = null; // The current instance in use
- this._keyEvent = false; // If the last event was a key event
- this._disabledInputs = []; // List of date picker inputs that have been
disabled
- this._datepickerShowing = false; // True if the popup picker is
showing , false if not
- this._inDialog = false; // True if showing within a "dialog", false if
not
- this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker
division
- this._inlineClass = 'ui-datepicker-inline'; // The name of the inline
marker class
- this._appendClass = 'ui-datepicker-append'; // The name of the append
marker class
- this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger
marker class
- this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog
marker class
- this._disableClass = 'ui-datepicker-disabled'; // The name of the
disabled covering marker class
- this._unselectableClass = 'ui-datepicker-unselectable'; // The name of
the unselectable cell marker class
- this._currentClass = 'ui-datepicker-current-day'; // The name of the
current day marker class
- this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the
day hover marker class
- this.regional = []; // Available regional settings, indexed by language
code
- this.regional[''] = { // Default regional settings
+ self._defaults = options;
+ self.debug = false; // Change this to true to start debugging
+ self._curInst = null; // The current instance in use
+ self._keyEvent = false; // If the last event was a key event
+ self._disabledInputs = []; // List of date picker inputs that have been
disabled
+ self._datepickerShowing = false; // True if the popup picker is
showing , false if not
+ self._inDialog = false; // True if showing within a "dialog", false if
not
+ self.regional = []; // Available regional settings, indexed by language
code
+ self.regional[''] = { // Default regional settings
closeText: 'Done', // Display text for close link
prevText: 'Prev', // Display text for previous month link
nextText: 'Next', // Display text for next month link
@@ -55,26 +50,39 @@
};
// TODO: move this to the correct place
- $.extend(this._defaults, this.regional['']);
-
- self.dpDiv = $('<div id="' + self._mainDivId + '" class="ui-datepicker
ui-widget ui-widget-content ui-helper-clearfix ui-corner-all
ui-helper-hidden-accessible"></div>');
-
+ $.extend(self._defaults, self.regional['']);
+
+ // draw widget
+ var widget = self._draw();
+
$(document).mousedown(function(event){ self._checkExternalClick(event);
})
.find('body')
.append(self.dpDiv);
- self._attachDatepicker(self.element[0],o);
+ self._attachDatepicker(self.element[0],options);
},
-
- /* Class name added to elements to indicate already configured with a
date picker. */
- markerClassName: 'hasDatepicker',
-
- /* Debug logging (if enabled). */
- log: function () {
- if (this.debug)
- console.log.apply('', arguments);
+ _draw: function() {
+ var self = this;
+
+ self._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker
division
+ self._inlineClass = 'ui-datepicker-inline'; // The name of the inline
marker class
+ self._appendClass = 'ui-datepicker-append'; // The name of the append
marker class
+ self._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger
marker class
+ self._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog
marker class
+ self._disableClass = 'ui-datepicker-disabled'; // The name of the
disabled covering marker class
+ self._unselectableClass = 'ui-datepicker-unselectable'; // The name of
the unselectable cell marker class
+ self._currentClass = 'ui-datepicker-current-day'; // The name of the
current day marker class
+ self._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the
day hover marker class
+
+ self.dpDiv = $('<div id="' + self._mainDivId + '" class="ui-datepicker
ui-widget ui-widget-content ui-helper-clearfix ui-corner-all
ui-helper-hidden-accessible"></div>');
},
-
+ destroy: function() {
+
+ this.element.removeClass('hasDatepicker');
+
+ $.widget.prototype.destroy.apply(this, arguments);
+ },
+
/* Attach the date picker to a jQuery selection.
@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) */
@@ -121,7 +129,7 @@
var self = this, input = $(target);
inst.append = $([]);
inst.trigger = $([]);
- if (input.hasClass(this.markerClassName))
+ if (input.hasClass(markerClassName))
return;
var appendText = this._get(inst, 'appendText');
var isRTL = this._get(inst, 'isRTL');
@@ -154,7 +162,7 @@
return false;
});
}
- input.addClass(this.markerClassName)
+ input.addClass(markerClassName)
.keydown(function(event) {
self._doKeyDown(event);
})
@@ -175,9 +183,9 @@
/* Attach an inline date picker to a div. */
_inlineDatepicker: function(target, inst) {
var divSpan = $(target);
- if (divSpan.hasClass(this.markerClassName))
+ if (divSpan.hasClass(markerClassName))
return;
- divSpan.addClass(this.markerClassName).append(inst.dpDiv).
+ divSpan.addClass(markerClassName).append(inst.dpDiv).
bind("setData.datepicker", function(event, key, value){
inst.settings[key] = value;
}).bind("getData.datepicker", function(event, key){
@@ -240,7 +248,7 @@
_destroyDatepicker: function(target) {
var $target = $(target);
var inst = $.data(target, PROP_NAME);
- if (!$target.hasClass(this.markerClassName)) {
+ if (!$target.hasClass(markerClassName)) {
return;
}
var nodeName = target.nodeName.toLowerCase();
@@ -248,13 +256,13 @@
if (nodeName == 'input') {
inst.append.remove();
inst.trigger.remove();
- $target.removeClass(this.markerClassName).
+ $target.removeClass(markerClassName).
unbind('focus', this._showDatepicker).
unbind('keydown', this._doKeyDown).
unbind('keypress', this._doKeyPress).
unbind('keyup', this._doKeyUp);
} else if (nodeName == 'div' || nodeName == 'span')
- $target.removeClass(this.markerClassName).empty();
+ $target.removeClass(markerClassName).empty();
},
/* Enable the date picker to a jQuery selection.
@@ -262,7 +270,7 @@
_enableDatepicker: function(target) {
var $target = $(target);
var inst = $.data(target, PROP_NAME);
- if (!$target.hasClass(this.markerClassName)) {
+ if (!$target.hasClass(markerClassName)) {
return;
}
var nodeName = target.nodeName.toLowerCase();
@@ -285,7 +293,7 @@
_disableDatepicker: function(target) {
var $target = $(target);
var inst = $.data(target, PROP_NAME);
- if (!$target.hasClass(this.markerClassName)) {
+ if (!$target.hasClass(markerClassName)) {
return;
}
var nodeName = target.nodeName.toLowerCase();
@@ -743,7 +751,7 @@
return;
var $target = $(event.target);
if (($target.parents('#' + self._mainDivId).length == 0) &&
- !$target.hasClass(self.markerClassName) &&
+ !$target.hasClass(markerClassName) &&
!$target.hasClass(self._triggerClass) &&
self._datepickerShowing && !(self._inDialog && $.blockUI))
self._hideDatepicker(null, '');
@@ -858,343 +866,67 @@
}
},
- /* Set as beforeShowDay function to prevent selection of weekends.
- @param date Date - the date to customise
- @return [boolean, string] - is this date selectable?, what is its CSS
class? */
- noWeekends: function(date) {
- var day = date.getDay();
- return [(day > 0 && day < 6), ''];
- },
-
- /* 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
- @return number - the number of the week within the year that contains
this date */
- iso8601Week: function(date) {
- var checkDate = new Date(date.getTime());
- // Find Thursday of this week starting on Monday
- checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
- var time = checkDate.getTime();
- checkDate.setMonth(0); // Compare with Jan 1
- checkDate.setDate(1);
- return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
- },
-
- /* Parse a string value into a date object.
- See formatDate below for the possible formats.
-
- @param format string - the expected format of the date
- @param value string - the date in the above format
- @param settings Object - attributes include:
- shortYearCutoff number - the cutoff year for
determining the century (optional)
- dayNamesShort string[7] - abbreviated 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)
- monthNames string[12] - names of the months
(optional)
- @return Date - the extracted date value or null if value is blank */
- parseDate: function (format, value, settings) {
- if (format == null || value == null)
- throw 'Invalid arguments';
- value = (typeof value == 'object' ? value.toString() : value + '');
- if (value == '')
- return null;
- var shortYearCutoff = (settings ? settings.shortYearCutoff : null) ||
this._defaults.shortYearCutoff;
- var dayNamesShort = (settings ? settings.dayNamesShort : null) ||
this._defaults.dayNamesShort;
- var dayNames = (settings ? settings.dayNames : null) ||
this._defaults.dayNames;
- var monthNamesShort = (settings ? settings.monthNamesShort : null) ||
this._defaults.monthNamesShort;
- var monthNames = (settings ? settings.monthNames : null) ||
this._defaults.monthNames;
- var year = -1;
- var month = -1;
- var day = -1;
- var doy = -1;
+ /* Extract all possible characters from the date format. */
+ _possibleChars: function (format) {
+ var chars = '';
var literal = false;
- // Check whether a format character is doubled
- var lookAhead = function(match) {
- var matches = (iFormat + 1 < format.length && format.charAt(iFormat +
1) == match);
- if (matches)
- iFormat++;
- return matches;
- };
- // Extract a number from the string value
- var getNumber = function(match) {
- lookAhead(match);
- var size = (match == '@' ? 14 : (match == '!' ? 20 :
- (match == 'y' ? 4 : (match == 'o' ? 3 : 2))));
- var digits = new RegExp('^\\d{1,' + size + '}');
- var num = value.substring(iValue).match(digits);
- if (!num)
- throw 'Missing number at position ' + iValue;
- iValue += num[0].length;
- return parseInt(num[0], 10);
- };
- // Extract a name from the string value and convert to an index
- var getName = function(match, shortNames, longNames) {
- var names = (lookAhead(match) ? longNames : shortNames);
- for (var i = 0; i < names.length; i++) {
- if (value.substr(iValue, names[i].length) == names[i]) {
- iValue += names[i].length;
- return i + 1;
- }
- }
- throw 'Unknown name at position ' + iValue;
- };
- // Confirm that a literal character matches the string value
- var checkLiteral = function() {
- if (value.charAt(iValue) != format.charAt(iFormat))
- throw 'Unexpected literal at position ' + iValue;
- iValue++;
- };
- var iValue = 0;
- for (var iFormat = 0; iFormat < format.length; iFormat++) {
+ for (var iFormat = 0; iFormat < format.length; iFormat++)
if (literal)
if (format.charAt(iFormat) == "'" && !lookAhead("'"))
literal = false;
else
- checkLiteral();
+ chars += format.charAt(iFormat);
else
switch (format.charAt(iFormat)) {
- case 'd':
- day = getNumber('d');
- break;
- case 'D':
- getName('D', dayNamesShort, dayNames);
- break;
- case 'o':
- doy = getNumber('o');
- break;
- case 'm':
- month = getNumber('m');
- break;
- case 'M':
- month = getName('M', monthNamesShort, monthNames);
- break;
- case 'y':
- year = getNumber('y');
- break;
- case '@':
- var date = new Date(getNumber('@'));
- year = date.getFullYear();
- month = date.getMonth() + 1;
- day = date.getDate();
- break;
- case '!':
- var date = new Date((getNumber('!') - this._ticksTo1970) / 10000);
- year = date.getFullYear();
- month = date.getMonth() + 1;
- day = date.getDate();
+ case 'd': case 'm': case 'y': case '@':
+ chars += '0123456789';
break;
+ case 'D': case 'M':
+ return null; // Accept anything
case "'":
if (lookAhead("'"))
- checkLiteral();
+ chars += "'";
else
literal = true;
break;
default:
- checkLiteral();
+ chars += format.charAt(iFormat);
}
- }
- if (year == -1)
- year = new Date().getFullYear();
- else if (year < 100)
- year += new Date().getFullYear() - new Date().getFullYear() % 100 +
- (year <= shortYearCutoff ? 0 : -100);
- if (doy > -1) {
- month = 1;
- day = doy;
- do {
- var dim = this._getDaysInMonth(year, month - 1);
- if (day <= dim)
- break;
- month++;
- day -= dim;
- } while (true);
- }
- var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
- if (date.getFullYear() != year || date.getMonth() + 1 != month ||
date.getDate() != day)
- throw 'Invalid date'; // E.g. 31/02/*
- return date;
+ return chars;
},
- /* Standard date formats. */
- ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
- COOKIE: 'D, dd M yy',
- ISO_8601: 'yy-mm-dd',
- RFC_822: 'D, d M y',
- RFC_850: 'DD, dd-M-y',
- RFC_1036: 'D, d M y',
- RFC_1123: 'D, d M yy',
- RFC_2822: 'D, d M yy',
- RSS: 'D, d M y', // RFC 822
- TICKS: '!',
- TIMESTAMP: '@',
- W3C: 'yy-mm-dd', // ISO 8601
+ /* Get a setting value, defaulting if necessary. */
+ _get: function(inst, name) {
+ return inst.settings[name] !== undefined ?
+ inst.settings[name] : this.options[name];
+ },
- _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970
/ 100) +
- Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
+ /* Parse existing date and initialise date picker. */
+ _setDateFromField: function(inst) {
+ var dateFormat = this._get(inst, 'dateFormat');
+ var dates = inst.input ? inst.input.val() : null;
+ var date = defaultDate = this._getDefaultDate(inst);
+ 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 ? date.getDate() : 0);
+ inst.currentMonth = (dates ? date.getMonth() : 0);
+ inst.currentYear = (dates ? date.getFullYear() : 0);
+ this._adjustInstDate(inst);
+ },
- /* Format a date object into a string value.
- The format can be combinations of the following:
- d - day of month (no leading zero)
- dd - day of month (two digit)
- o - day of year (no leading zeros)
- oo - day of year (three digit)
- D - day name short
- DD - day name long
- m - month of year (no leading zero)
- mm - month of year (two digit)
- M - month name short
- MM - month name long
- y - year (two digit)
- yy - year (four digit)
- @ - Unix timestamp (ms since 01/01/1970)
- ! - Windows ticks (100ns since 01/01/0001)
- '...' - literal text
- '' - single quote
-
- @param format string - the desired format of the date
- @param date Date - the date value to format
- @param settings Object - attributes include:
- dayNamesShort string[7] - abbreviated 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)
- monthNames string[12] - names of the months
(optional)
- @return string - the date in the above format */
- formatDate: function (format, date, settings) {
- if (!date)
- return '';
- var dayNamesShort = (settings ? settings.dayNamesShort : null) ||
this._defaults.dayNamesShort;
- var dayNames = (settings ? settings.dayNames : null) ||
this._defaults.dayNames;
- var monthNamesShort = (settings ? settings.monthNamesShort : null) ||
this._defaults.monthNamesShort;
- var monthNames = (settings ? settings.monthNames : null) ||
this._defaults.monthNames;
- // Check whether a format character is doubled
- var lookAhead = function(match) {
- var matches = (iFormat + 1 < format.length && format.charAt(iFormat +
1) == match);
- if (matches)
- iFormat++;
- return matches;
- };
- // Format a number, with leading zero if necessary
- var formatNumber = function(match, value, len) {
- var num = '' + value;
- if (lookAhead(match))
- while (num.length < len)
- num = '0' + num;
- return num;
- };
- // Format a name, short or long as requested
- var formatName = function(match, value, shortNames, longNames) {
- return (lookAhead(match) ? longNames[value] : shortNames[value]);
- };
- var output = '';
- var literal = false;
- if (date)
- for (var iFormat = 0; iFormat < format.length; iFormat++) {
- if (literal)
- if (format.charAt(iFormat) == "'" && !lookAhead("'"))
- literal = false;
- else
- output += format.charAt(iFormat);
- else
- switch (format.charAt(iFormat)) {
- case 'd':
- output += formatNumber('d', date.getDate(), 2);
- break;
- case 'D':
- output += formatName('D', date.getDay(), dayNamesShort, dayNames);
- break;
- case 'o':
- output += formatNumber('o',
- (date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) /
86400000, 3);
- break;
- case 'm':
- output += formatNumber('m', date.getMonth() + 1, 2);
- break;
- case 'M':
- output += formatName('M', date.getMonth(), monthNamesShort,
monthNames);
- break;
- case 'y':
- output += (lookAhead('y') ? date.getFullYear() :
- (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
- break;
- case '@':
- output += date.getTime();
- break;
- case '!':
- output += date.getTime() * 10000 + this._ticksTo1970;
- break;
- case "'":
- if (lookAhead("'"))
- output += "'";
- else
- literal = true;
- break;
- default:
- output += format.charAt(iFormat);
- }
- }
- return output;
- },
-
- /* Extract all possible characters from the date format. */
- _possibleChars: function (format) {
- var chars = '';
- var literal = false;
- for (var iFormat = 0; iFormat < format.length; iFormat++)
- if (literal)
- if (format.charAt(iFormat) == "'" && !lookAhead("'"))
- literal = false;
- else
- chars += format.charAt(iFormat);
- else
- switch (format.charAt(iFormat)) {
- case 'd': case 'm': case 'y': case '@':
- chars += '0123456789';
- break;
- case 'D': case 'M':
- return null; // Accept anything
- case "'":
- if (lookAhead("'"))
- chars += "'";
- else
- literal = true;
- break;
- default:
- chars += format.charAt(iFormat);
- }
- return chars;
- },
-
- /* Get a setting value, defaulting if necessary. */
- _get: function(inst, name) {
- return inst.settings[name] !== undefined ?
- inst.settings[name] : this.options[name];
- },
-
- /* Parse existing date and initialise date picker. */
- _setDateFromField: function(inst) {
- var dateFormat = this._get(inst, 'dateFormat');
- var dates = inst.input ? inst.input.val() : null;
- var date = defaultDate = this._getDefaultDate(inst);
- 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 ? date.getDate() : 0);
- inst.currentMonth = (dates ? date.getMonth() : 0);
- inst.currentYear = (dates ? date.getFullYear() : 0);
- this._adjustInstDate(inst);
- },
-
- /* Retrieve the default date shown on opening. */
- _getDefaultDate: function(inst) {
- return this._restrictMinMax(inst,
- this._determineDate(this._get(inst, 'defaultDate'), new Date()));
- },
+ /* Retrieve the default date shown on opening. */
+ _getDefaultDate: function(inst) {
+ return this._restrictMinMax(inst,
+ this._determineDate(this._get(inst, 'defaultDate'), new Date()));
+ },
/* A date may be specified as an exact value or a relative one. */
_determineDate: function(date, defaultDate) {
@@ -1593,18 +1325,276 @@
this._daylightSavingAdjust(new Date(inst.currentYear,
inst.currentMonth, inst.currentDay)));
return this.formatDate(this._get(inst, 'dateFormat'), date,
this._getFormatConfig(inst));
},
-
- destroy: function() {
-
- this.element.removeClass('hasDatepicker');
-
- $.widget.prototype.destroy.apply(this, arguments);
- },
-
+
_setData: function(key, value) {
$.widget.prototype._setData.apply(this, arguments);
- }
+ },
+
+ /* Debug logging (if enabled). */
+ log: function () {
+ if (this.debug)
+ console.log.apply('', arguments);
+ },
+
+ /* Set as beforeShowDay function to prevent selection of weekends.
+ @param date Date - the date to customise
+ @return [boolean, string] - is this date selectable?, what is its CSS
class? */
+ noWeekends: function(date) {
+ var day = date.getDay();
+ return [(day > 0 && day < 6), ''];
+ },
+
+ /* 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
+ @return number - the number of the week within the year that contains
this date */
+ iso8601Week: function(date) {
+ var checkDate = new Date(date.getTime());
+ // Find Thursday of this week starting on Monday
+ checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
+ var time = checkDate.getTime();
+ checkDate.setMonth(0); // Compare with Jan 1
+ checkDate.setDate(1);
+ return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
+ },
+
+ /* Parse a string value into a date object.
+ See formatDate below for the possible formats.
+
+ @param format string - the expected format of the date
+ @param value string - the date in the above format
+ @param settings Object - attributes include:
+ shortYearCutoff number - the cutoff year for
determining the century (optional)
+ dayNamesShort string[7] - abbreviated 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)
+ monthNames string[12] - names of the months
(optional)
+ @return Date - the extracted date value or null if value is blank */
+ parseDate: function (format, value, settings) {
+ if (format == null || value == null)
+ throw 'Invalid arguments';
+ value = (typeof value == 'object' ? value.toString() : value + '');
+ if (value == '')
+ return null;
+ var shortYearCutoff = (settings ? settings.shortYearCutoff : null) ||
this._defaults.shortYearCutoff;
+ var dayNamesShort = (settings ? settings.dayNamesShort : null) ||
this._defaults.dayNamesShort;
+ var dayNames = (settings ? settings.dayNames : null) ||
this._defaults.dayNames;
+ var monthNamesShort = (settings ? settings.monthNamesShort : null) ||
this._defaults.monthNamesShort;
+ var monthNames = (settings ? settings.monthNames : null) ||
this._defaults.monthNames;
+ var year = -1;
+ var month = -1;
+ var day = -1;
+ var doy = -1;
+ var literal = false;
+ // Check whether a format character is doubled
+ var lookAhead = function(match) {
+ var matches = (iFormat + 1 < format.length && format.charAt(iFormat +
1) == match);
+ if (matches)
+ iFormat++;
+ return matches;
+ };
+ // Extract a number from the string value
+ var getNumber = function(match) {
+ lookAhead(match);
+ var size = (match == '@' ? 14 : (match == '!' ? 20 :
+ (match == 'y' ? 4 : (match == 'o' ? 3 : 2))));
+ var digits = new RegExp('^\\d{1,' + size + '}');
+ var num = value.substring(iValue).match(digits);
+ if (!num)
+ throw 'Missing number at position ' + iValue;
+ iValue += num[0].length;
+ return parseInt(num[0], 10);
+ };
+ // Extract a name from the string value and convert to an index
+ var getName = function(match, shortNames, longNames) {
+ var names = (lookAhead(match) ? longNames : shortNames);
+ for (var i = 0; i < names.length; i++) {
+ if (value.substr(iValue, names[i].length) == names[i]) {
+ iValue += names[i].length;
+ return i + 1;
+ }
+ }
+ throw 'Unknown name at position ' + iValue;
+ };
+ // Confirm that a literal character matches the string value
+ var checkLiteral = function() {
+ if (value.charAt(iValue) != format.charAt(iFormat))
+ throw 'Unexpected literal at position ' + iValue;
+ iValue++;
+ };
+ var iValue = 0;
+ for (var iFormat = 0; iFormat < format.length; iFormat++) {
+ if (literal)
+ if (format.charAt(iFormat) == "'" && !lookAhead("'"))
+ literal = false;
+ else
+ checkLiteral();
+ else
+ switch (format.charAt(iFormat)) {
+ case 'd':
+ day = getNumber('d');
+ break;
+ case 'D':
+ getName('D', dayNamesShort, dayNames);
+ break;
+ case 'o':
+ doy = getNumber('o');
+ break;
+ case 'm':
+ month = getNumber('m');
+ break;
+ case 'M':
+ month = getName('M', monthNamesShort, monthNames);
+ break;
+ case 'y':
+ year = getNumber('y');
+ break;
+ case '@':
+ var date = new Date(getNumber('@'));
+ year = date.getFullYear();
+ month = date.getMonth() + 1;
+ day = date.getDate();
+ break;
+ case '!':
+ var date = new Date((getNumber('!') - ticksTo1970) / 10000);
+ year = date.getFullYear();
+ month = date.getMonth() + 1;
+ day = date.getDate();
+ break;
+ case "'":
+ if (lookAhead("'"))
+ checkLiteral();
+ else
+ literal = true;
+ break;
+ default:
+ checkLiteral();
+ }
+ }
+ if (year == -1)
+ year = new Date().getFullYear();
+ else if (year < 100)
+ year += new Date().getFullYear() - new Date().getFullYear() % 100 +
+ (year <= shortYearCutoff ? 0 : -100);
+ if (doy > -1) {
+ month = 1;
+ day = doy;
+ do {
+ var dim = this._getDaysInMonth(year, month - 1);
+ if (day <= dim)
+ break;
+ month++;
+ day -= dim;
+ } while (true);
+ }
+ var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
+ if (date.getFullYear() != year || date.getMonth() + 1 != month ||
date.getDate() != day)
+ throw 'Invalid date'; // E.g. 31/02/*
+ return date;
+ },
+
+ /* Format a date object into a string value.
+ The format can be combinations of the following:
+ d - day of month (no leading zero)
+ dd - day of month (two digit)
+ o - day of year (no leading zeros)
+ oo - day of year (three digit)
+ D - day name short
+ DD - day name long
+ m - month of year (no leading zero)
+ mm - month of year (two digit)
+ M - month name short
+ MM - month name long
+ y - year (two digit)
+ yy - year (four digit)
+ @ - Unix timestamp (ms since 01/01/1970)
+ ! - Windows ticks (100ns since 01/01/0001)
+ '...' - literal text
+ '' - single quote
+
+ @param format string - the desired format of the date
+ @param date Date - the date value to format
+ @param settings Object - attributes include:
+ dayNamesShort string[7] - abbreviated 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)
+ monthNames string[12] - names of the months
(optional)
+ @return string - the date in the above format */
+ formatDate: function (format, date, settings) {
+ if (!date)
+ return '';
+ var dayNamesShort = (settings ? settings.dayNamesShort : null) ||
this._defaults.dayNamesShort;
+ var dayNames = (settings ? settings.dayNames : null) ||
this._defaults.dayNames;
+ var monthNamesShort = (settings ? settings.monthNamesShort : null) ||
this._defaults.monthNamesShort;
+ var monthNames = (settings ? settings.monthNames : null) ||
this._defaults.monthNames;
+ // Check whether a format character is doubled
+ var lookAhead = function(match) {
+ var matches = (iFormat + 1 < format.length && format.charAt(iFormat +
1) == match);
+ if (matches)
+ iFormat++;
+ return matches;
+ };
+ // Format a number, with leading zero if necessary
+ var formatNumber = function(match, value, len) {
+ var num = '' + value;
+ if (lookAhead(match))
+ while (num.length < len)
+ num = '0' + num;
+ return num;
+ };
+ // Format a name, short or long as requested
+ var formatName = function(match, value, shortNames, longNames) {
+ return (lookAhead(match) ? longNames[value] : shortNames[value]);
+ };
+ var output = '';
+ var literal = false;
+ if (date)
+ for (var iFormat = 0; iFormat < format.length; iFormat++) {
+ if (literal)
+ if (format.charAt(iFormat) == "'" && !lookAhead("'"))
+ literal = false;
+ else
+ output += format.charAt(iFormat);
+ else
+ switch (format.charAt(iFormat)) {
+ case 'd':
+ output += formatNumber('d', date.getDate(), 2);
+ break;
+ case 'D':
+ output += formatName('D', date.getDay(), dayNamesShort, dayNames);
+ break;
+ case 'o':
+ output += formatNumber('o',
+ (date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) /
86400000, 3);
+ break;
+ case 'm':
+ output += formatNumber('m', date.getMonth() + 1, 2);
+ break;
+ case 'M':
+ output += formatName('M', date.getMonth(), monthNamesShort,
monthNames);
+ break;
+ case 'y':
+ output += (lookAhead('y') ? date.getFullYear() :
+ (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
+ break;
+ case '@':
+ output += date.getTime();
+ break;
+ case '!':
+ output += date.getTime() * 10000 + ticksTo1970;
+ break;
+ case "'":
+ if (lookAhead("'"))
+ output += "'";
+ else
+ literal = true;
+ break;
+ default:
+ output += format.charAt(iFormat);
+ }
+ }
+ return output;
+ },
});
@@ -1665,7 +1655,22 @@
},
uuid: new Date().getTime(),
- regional: []
+ regional: [],
+
+ /* Standard date formats. */
+ ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
+ COOKIE: 'D, dd M yy',
+ ISO_8601: 'yy-mm-dd',
+ RFC_822: 'D, d M y',
+ RFC_850: 'DD, dd-M-y',
+ RFC_1036: 'D, d M y',
+ RFC_1123: 'D, d M yy',
+ RFC_2822: 'D, d M yy',
+ RSS: 'D, d M y', // RFC 822
+ TICKS: '!',
+ TIMESTAMP: '@',
+ W3C: 'yy-mm-dd' // ISO 8601
+
});
/* jQuery extend now ignores nulls! */
@@ -1682,8 +1687,5 @@
return (a && (($.browser.safari && typeof a == 'object' && a.length) ||
(a.constructor && a.constructor.toString().match(/\Array\(\)/))));
};
-
-// For backwards compatibility
-$.datepicker = $.ui.datepicker;
})(jQuery);