2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* datepicker_events.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2011-02-18 15:08:17 +00:00
|
|
|
module("datepicker: events");
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
var selectedThis = null,
|
|
|
|
selectedDate = null,
|
|
|
|
selectedInst = null;
|
2009-02-04 04:27:14 +00:00
|
|
|
|
|
|
|
function callback(date, inst) {
|
|
|
|
selectedThis = this;
|
|
|
|
selectedDate = date;
|
|
|
|
selectedInst = inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
function callback2(year, month, inst) {
|
|
|
|
selectedThis = this;
|
|
|
|
selectedDate = year + '/' + month;
|
|
|
|
selectedInst = inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
test('events', function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 26 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var dateStr, newMonthYear, inp2,
|
|
|
|
inp = init('#inp', {onSelect: callback}),
|
|
|
|
date = new Date();
|
2009-02-04 04:27:14 +00:00
|
|
|
// onSelect
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedThis, inp[0], 'Callback selected this');
|
2012-10-23 14:36:42 +00:00
|
|
|
equal(selectedInst, $.data(inp[0], TestHelpers.PROP_NAME), 'Callback selected inst');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, $.datepicker.formatDate('mm/dd/yy', date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback selected date');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.DOWN}).
|
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setDate(date.getDate() + 7);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, $.datepicker.formatDate('mm/dd/yy', date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback selected date - ctrl+down');
|
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, $.datepicker.formatDate('mm/dd/yy', date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback selected date - esc');
|
2012-04-19 15:17:35 +00:00
|
|
|
dateStr = '02/04/2008';
|
2011-06-28 15:49:47 +00:00
|
|
|
inp.val(dateStr).datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dateStr, selectedDate,
|
2011-06-28 15:49:47 +00:00
|
|
|
'onSelect is called after enter keydown');
|
2009-02-04 04:27:14 +00:00
|
|
|
// onChangeMonthYear
|
|
|
|
inp.datepicker('option', {onChangeMonthYear: callback2, onSelect: null}).
|
|
|
|
val('').datepicker('show');
|
2012-04-19 15:17:35 +00:00
|
|
|
newMonthYear = function(date) {
|
2009-02-04 04:27:14 +00:00
|
|
|
return date.getFullYear() + '/' + (date.getMonth() + 1);
|
|
|
|
};
|
|
|
|
date = new Date();
|
|
|
|
date.setDate(1);
|
2012-03-27 18:46:13 +00:00
|
|
|
inp.simulate('keydown', {keyCode: $.ui.keyCode.PAGE_UP});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() - 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedThis, inp[0], 'Callback change month/year this');
|
2012-10-23 14:36:42 +00:00
|
|
|
equal(selectedInst, $.data(inp[0], TestHelpers.PROP_NAME), 'Callback change month/year inst');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year date - pgup');
|
2012-03-27 18:46:13 +00:00
|
|
|
inp.simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() + 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year date - pgdn');
|
2012-03-27 18:46:13 +00:00
|
|
|
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setFullYear(date.getFullYear() - 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year date - ctrl+pgup');
|
2012-03-27 18:46:13 +00:00
|
|
|
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.HOME});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setFullYear(date.getFullYear() + 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year date - ctrl+home');
|
2012-03-27 18:46:13 +00:00
|
|
|
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setFullYear(date.getFullYear() + 1);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year date - ctrl+pgdn');
|
|
|
|
inp.datepicker('setDate', new Date(2007, 1 - 1, 26));
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, '2007/1', 'Callback change month/year date - setDate');
|
2009-02-04 04:27:14 +00:00
|
|
|
selectedDate = null;
|
|
|
|
inp.datepicker('setDate', new Date(2007, 1 - 1, 12));
|
|
|
|
ok(selectedDate == null, 'Callback change month/year date - setDate no change');
|
|
|
|
// onChangeMonthYear step by 2
|
|
|
|
inp.datepicker('option', {stepMonths: 2}).
|
|
|
|
datepicker('hide').val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.PAGE_UP});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() - 14);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year by 2 date - pgup');
|
2012-03-27 18:46:13 +00:00
|
|
|
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() - 12);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year by 2 date - ctrl+pgup');
|
2012-03-27 18:46:13 +00:00
|
|
|
inp.simulate('keydown', {keyCode: $.ui.keyCode.PAGE_DOWN});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() + 2);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year by 2 date - pgdn');
|
2012-03-27 18:46:13 +00:00
|
|
|
inp.simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN});
|
2009-02-04 04:27:14 +00:00
|
|
|
date.setMonth(date.getMonth() + 12);
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, newMonthYear(date),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback change month/year by 2 date - ctrl+pgdn');
|
|
|
|
// onClose
|
|
|
|
inp.datepicker('option', {onClose: callback, onChangeMonthYear: null, stepMonths: 1}).
|
|
|
|
val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedThis, inp[0], 'Callback close this');
|
2012-10-23 14:36:42 +00:00
|
|
|
equal(selectedInst, $.data(inp[0], TestHelpers.PROP_NAME), 'Callback close inst');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, '', 'Callback close date - esc');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.val('').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ENTER});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, $.datepicker.formatDate('mm/dd/yy', new Date()),
|
2009-02-04 04:27:14 +00:00
|
|
|
'Callback close date - enter');
|
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {keyCode: $.ui.keyCode.ESCAPE});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, '02/04/2008', 'Callback close date - preset');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.val('02/04/2008').datepicker('show').
|
2012-03-27 18:46:13 +00:00
|
|
|
simulate('keydown', {ctrlKey: true, keyCode: $.ui.keyCode.END});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedDate, '', 'Callback close date - ctrl+end');
|
2011-05-06 20:58:06 +00:00
|
|
|
|
2012-04-19 15:17:35 +00:00
|
|
|
inp2 = init('#inp2');
|
2011-05-06 20:58:06 +00:00
|
|
|
inp2.datepicker().datepicker('option', {onClose: callback}).datepicker('show');
|
|
|
|
inp.datepicker('show');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(selectedThis, inp2[0], 'Callback close this');
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|