2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* datepicker_methods.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2011-02-18 15:08:17 +00:00
|
|
|
module("datepicker: methods");
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
test('destroy', function() {
|
2012-04-19 15:17:35 +00:00
|
|
|
var inl,
|
|
|
|
inp = init('#inp');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(inp.is('.hasDatepicker'), 'Default - marker class set');
|
|
|
|
ok($.data(inp[0], PROP_NAME), 'Default - instance present');
|
|
|
|
ok(inp.next().is('#alt'), 'Default - button absent');
|
|
|
|
inp.datepicker('destroy');
|
|
|
|
inp = $('#inp');
|
|
|
|
ok(!inp.is('.hasDatepicker'), 'Default - marker class cleared');
|
|
|
|
ok(!$.data(inp[0], PROP_NAME), 'Default - instance absent');
|
|
|
|
ok(inp.next().is('#alt'), 'Default - button absent');
|
|
|
|
// With button
|
|
|
|
inp= init('#inp', {showOn: 'both'});
|
|
|
|
ok(inp.is('.hasDatepicker'), 'Button - marker class set');
|
|
|
|
ok($.data(inp[0], PROP_NAME), 'Button - instance present');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(inp.next().text() === '...', 'Button - button added');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('destroy');
|
|
|
|
inp = $('#inp');
|
|
|
|
ok(!inp.is('.hasDatepicker'), 'Button - marker class cleared');
|
|
|
|
ok(!$.data(inp[0], PROP_NAME), 'Button - instance absent');
|
|
|
|
ok(inp.next().is('#alt'), 'Button - button removed');
|
|
|
|
// With append text
|
|
|
|
inp = init('#inp', {appendText: 'Testing'});
|
|
|
|
ok(inp.is('.hasDatepicker'), 'Append - marker class set');
|
|
|
|
ok($.data(inp[0], PROP_NAME), 'Append - instance present');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(inp.next().text() === 'Testing', 'Append - append text added');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('destroy');
|
|
|
|
inp = $('#inp');
|
|
|
|
ok(!inp.is('.hasDatepicker'), 'Append - marker class cleared');
|
|
|
|
ok(!$.data(inp[0], PROP_NAME), 'Append - instance absent');
|
|
|
|
ok(inp.next().is('#alt'), 'Append - append text removed');
|
|
|
|
// With both
|
|
|
|
inp= init('#inp', {showOn: 'both', buttonImageOnly: true,
|
|
|
|
buttonImage: 'img/calendar.gif', appendText: 'Testing'});
|
|
|
|
ok(inp.is('.hasDatepicker'), 'Both - marker class set');
|
|
|
|
ok($.data(inp[0], PROP_NAME), 'Both - instance present');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(inp.next()[0].nodeName.toLowerCase() === 'img', 'Both - button added');
|
|
|
|
ok(inp.next().next().text() === 'Testing', 'Both - append text added');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('destroy');
|
|
|
|
inp = $('#inp');
|
|
|
|
ok(!inp.is('.hasDatepicker'), 'Both - marker class cleared');
|
|
|
|
ok(!$.data(inp[0], PROP_NAME), 'Both - instance absent');
|
|
|
|
ok(inp.next().is('#alt'), 'Both - button and append text absent');
|
|
|
|
// Inline
|
2012-04-19 15:17:35 +00:00
|
|
|
inl = init('#inl');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(inl.is('.hasDatepicker'), 'Inline - marker class set');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(inl.html() !== '', 'Inline - datepicker present');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok($.data(inl[0], PROP_NAME), 'Inline - instance present');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(inl.next().length === 0 || inl.next().is('p'), 'Inline - button absent');
|
2009-02-04 04:27:14 +00:00
|
|
|
inl.datepicker('destroy');
|
|
|
|
inl = $('#inl');
|
|
|
|
ok(!inl.is('.hasDatepicker'), 'Inline - marker class cleared');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(inl.html() === '', 'Inline - datepicker absent');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(!$.data(inl[0], PROP_NAME), 'Inline - instance absent');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(inl.next().length === 0 || inl.next().is('p'), 'Inline - button absent');
|
2009-02-04 04:27:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('enableDisable', function() {
|
2012-04-19 15:17:35 +00:00
|
|
|
var inl, dp,
|
|
|
|
inp = init('#inp');
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(!inp.datepicker('isDisabled'), 'Enable/disable - initially marked as enabled');
|
|
|
|
ok(!inp[0].disabled, 'Enable/disable - field initially enabled');
|
|
|
|
inp.datepicker('disable');
|
|
|
|
ok(inp.datepicker('isDisabled'), 'Enable/disable - now marked as disabled');
|
|
|
|
ok(inp[0].disabled, 'Enable/disable - field now disabled');
|
|
|
|
inp.datepicker('enable');
|
|
|
|
ok(!inp.datepicker('isDisabled'), 'Enable/disable - now marked as enabled');
|
|
|
|
ok(!inp[0].disabled, 'Enable/disable - field now enabled');
|
|
|
|
inp.datepicker('destroy');
|
|
|
|
// With a button
|
|
|
|
inp = init('#inp', {showOn: 'button'});
|
|
|
|
ok(!inp.datepicker('isDisabled'), 'Enable/disable button - initially marked as enabled');
|
|
|
|
ok(!inp[0].disabled, 'Enable/disable button - field initially enabled');
|
|
|
|
ok(!inp.next('button')[0].disabled, 'Enable/disable button - button initially enabled');
|
|
|
|
inp.datepicker('disable');
|
|
|
|
ok(inp.datepicker('isDisabled'), 'Enable/disable button - now marked as disabled');
|
|
|
|
ok(inp[0].disabled, 'Enable/disable button - field now disabled');
|
|
|
|
ok(inp.next('button')[0].disabled, 'Enable/disable button - button now disabled');
|
|
|
|
inp.datepicker('enable');
|
|
|
|
ok(!inp.datepicker('isDisabled'), 'Enable/disable button - now marked as enabled');
|
|
|
|
ok(!inp[0].disabled, 'Enable/disable button - field now enabled');
|
|
|
|
ok(!inp.next('button')[0].disabled, 'Enable/disable button - button now enabled');
|
|
|
|
inp.datepicker('destroy');
|
|
|
|
// With an image button
|
|
|
|
inp = init('#inp', {showOn: 'button', buttonImageOnly: true,
|
|
|
|
buttonImage: 'img/calendar.gif'});
|
|
|
|
ok(!inp.datepicker('isDisabled'), 'Enable/disable image - initially marked as enabled');
|
|
|
|
ok(!inp[0].disabled, 'Enable/disable image - field initially enabled');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(parseFloat(inp.next('img').css('opacity')) === 1, 'Enable/disable image - image initially enabled');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('disable');
|
|
|
|
ok(inp.datepicker('isDisabled'), 'Enable/disable image - now marked as disabled');
|
|
|
|
ok(inp[0].disabled, 'Enable/disable image - field now disabled');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(parseFloat(inp.next('img').css('opacity')) !== 1, 'Enable/disable image - image now disabled');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('enable');
|
|
|
|
ok(!inp.datepicker('isDisabled'), 'Enable/disable image - now marked as enabled');
|
|
|
|
ok(!inp[0].disabled, 'Enable/disable image - field now enabled');
|
2012-04-19 15:17:35 +00:00
|
|
|
ok(parseFloat(inp.next('img').css('opacity')) === 1, 'Enable/disable image - image now enabled');
|
2009-02-04 04:27:14 +00:00
|
|
|
inp.datepicker('destroy');
|
|
|
|
// Inline
|
2012-04-19 15:17:35 +00:00
|
|
|
inl = init('#inl', {changeYear: true});
|
|
|
|
dp = $('.ui-datepicker-inline', inl);
|
2009-02-04 04:27:14 +00:00
|
|
|
ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - initially marked as enabled');
|
|
|
|
ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visually disabled initially');
|
2011-06-08 21:02:57 +00:00
|
|
|
ok(!dp.find('select').prop('disabled'), 'Enable/disable inline - form element enabled initially');
|
2009-02-04 04:27:14 +00:00
|
|
|
inl.datepicker('disable');
|
|
|
|
ok(inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as disabled');
|
|
|
|
ok(dp.children().is('.ui-state-disabled'), 'Enable/disable inline - visually disabled');
|
2011-06-08 21:02:57 +00:00
|
|
|
ok(dp.find('select').prop('disabled'), 'Enable/disable inline - form element disabled');
|
2009-02-04 04:27:14 +00:00
|
|
|
inl.datepicker('enable');
|
|
|
|
ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as enabled');
|
|
|
|
ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visiually disabled');
|
2011-06-08 21:02:57 +00:00
|
|
|
ok(!dp.find('select').prop('disabled'), 'Enable/disable inline - form element enabled');
|
2009-02-04 04:27:14 +00:00
|
|
|
inl.datepicker('destroy');
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|