2015-04-07 00:06:31 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-08-20 13:48:11 +00:00
|
|
|
"ui/widgets/datepicker"
|
2015-04-07 14:30:07 +00:00
|
|
|
], function( $, testHelper ) {
|
2013-11-02 13:54:05 +00:00
|
|
|
|
|
|
|
module( "datepicker: options" );
|
|
|
|
|
2013-11-15 13:42:20 +00:00
|
|
|
test( "appendTo", function() {
|
|
|
|
expect( 6 );
|
|
|
|
var container,
|
|
|
|
detached = $( "<div>" ),
|
|
|
|
input = $( "#datepicker" );
|
|
|
|
|
|
|
|
input.datepicker();
|
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, document.body, "defaults to body" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
2015-10-08 13:06:55 +00:00
|
|
|
input.datepicker( { appendTo: "#qunit-fixture" } );
|
2013-11-15 13:42:20 +00:00
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, $( "#qunit-fixture" )[ 0 ], "child of specified element" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
2015-10-08 13:06:55 +00:00
|
|
|
input.datepicker( { appendTo: "#does-not-exist" } );
|
2013-11-15 13:42:20 +00:00
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, document.body, "set to body if element does not exist" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
|
|
|
input.datepicker()
|
|
|
|
.datepicker( "option", "appendTo", "#qunit-fixture" );
|
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, $( "#qunit-fixture" )[ 0 ], "modified after init" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
2015-10-08 13:06:55 +00:00
|
|
|
input.datepicker( { appendTo: detached } );
|
2013-11-15 13:42:20 +00:00
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, detached[ 0 ], "detached jQuery object" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
2015-10-08 13:06:55 +00:00
|
|
|
input.datepicker( { appendTo: detached[ 0 ] } );
|
2013-11-15 13:42:20 +00:00
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, detached[ 0 ], "detached DOM element" );
|
|
|
|
input.datepicker( "destroy" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-11-15 13:42:20 +00:00
|
|
|
|
2014-08-29 19:19:30 +00:00
|
|
|
test( "Pass-through options", function() {
|
2015-07-28 21:10:16 +00:00
|
|
|
expect( 11 );
|
2014-08-29 19:19:30 +00:00
|
|
|
|
|
|
|
var options = {
|
2014-09-01 13:36:38 +00:00
|
|
|
buttons: { "Test": $.noop },
|
|
|
|
dateFormat: { date: "full" },
|
|
|
|
disabled: true,
|
|
|
|
eachDay: function( day ) { day; },
|
2015-07-28 21:10:16 +00:00
|
|
|
locale: "de",
|
2014-09-01 13:36:38 +00:00
|
|
|
max: new Date( 2000, 0, 1 ),
|
|
|
|
min: new Date( 2000, 0, 2 ),
|
|
|
|
numberOfMonths: 3,
|
|
|
|
showWeek: true
|
2014-06-19 22:13:20 +00:00
|
|
|
},
|
2014-08-29 19:19:30 +00:00
|
|
|
input = $( "#datepicker" ).val( "1/1/14" ).datepicker(),
|
|
|
|
datepickerInstance = input.datepicker( "instance" );
|
2014-06-19 22:13:20 +00:00
|
|
|
|
2014-08-29 19:19:30 +00:00
|
|
|
$.each( options, function( key, value ) {
|
|
|
|
input.datepicker( "option", key, value );
|
2014-06-19 22:13:20 +00:00
|
|
|
|
2014-08-29 19:19:30 +00:00
|
|
|
deepEqual(
|
|
|
|
datepickerInstance.calendar.calendar( "option", key ),
|
|
|
|
value,
|
|
|
|
"option " + key + ": correct value"
|
|
|
|
);
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2014-08-29 19:19:30 +00:00
|
|
|
if ( key === "dateFormat" ) {
|
|
|
|
equal( input.val(), "Wednesday, January 1, 2014", "option " + key + ": updated format" );
|
2013-11-19 13:35:19 +00:00
|
|
|
}
|
2015-07-28 21:10:16 +00:00
|
|
|
|
|
|
|
if ( key === "locale" ) {
|
|
|
|
equal( input.val(), "Mittwoch, 1. Januar 2014", "option " + key + ": updated locale" );
|
|
|
|
}
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2015-10-08 13:06:55 +00:00
|
|
|
asyncTest( "position", function( assert ) {
|
2013-11-18 14:23:15 +00:00
|
|
|
expect( 3 );
|
2015-10-08 13:06:55 +00:00
|
|
|
var input = $( "<input>" ).datepicker().appendTo( "body" ).css( {
|
2013-11-18 14:23:15 +00:00
|
|
|
position: "absolute",
|
|
|
|
top: 0,
|
|
|
|
left: 0
|
2015-10-08 13:06:55 +00:00
|
|
|
} ),
|
2013-11-18 14:23:15 +00:00
|
|
|
container = input.datepicker( "widget" );
|
|
|
|
|
|
|
|
input.datepicker( "open" );
|
2015-10-08 13:06:55 +00:00
|
|
|
setTimeout( function() {
|
2015-07-15 13:40:38 +00:00
|
|
|
assert.close( input.offset().left, container.offset().left, 1, "left sides line up by default" );
|
|
|
|
assert.close( container.offset().top, input.offset().top + input.outerHeight(), 1,
|
2013-11-18 14:23:15 +00:00
|
|
|
"datepicker directly under input by default" );
|
|
|
|
|
|
|
|
// Change the position option using option()
|
|
|
|
input.datepicker( "option", "position", {
|
|
|
|
my: "left top",
|
|
|
|
at: "right bottom"
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2015-07-15 13:40:38 +00:00
|
|
|
assert.close( container.offset().left, input.offset().left + input.outerWidth(), 1,
|
2013-11-18 14:23:15 +00:00
|
|
|
"datepicker on right hand side of input after position change" );
|
|
|
|
|
|
|
|
input.remove();
|
|
|
|
start();
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
test( "Stop datepicker from appearing with beforeOpen event handler", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 3 );
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
var input = testHelper.init( "#datepicker", {
|
2014-06-03 21:18:51 +00:00
|
|
|
beforeOpen: function() {}
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-02-01 21:52:04 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
input.datepicker( "open" );
|
|
|
|
ok( input.datepicker( "widget" ).is( ":visible" ), "beforeOpen returns nothing" );
|
|
|
|
input.datepicker( "close" ).datepicker( "destroy" );
|
2012-11-09 21:27:45 +00:00
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
input = testHelper.init( "#datepicker", {
|
2014-06-03 21:18:51 +00:00
|
|
|
beforeOpen: function() {
|
2012-11-09 21:27:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2014-06-03 21:18:51 +00:00
|
|
|
input.datepicker( "open" );
|
|
|
|
ok( input.datepicker( "widget" ).is( ":visible" ), "beforeOpen returns true" );
|
|
|
|
input.datepicker( "close" ).datepicker( "destroy" );
|
2013-04-07 18:40:26 +00:00
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
input = testHelper.init( "#datepicker", {
|
2014-06-03 21:18:51 +00:00
|
|
|
beforeOpen: function() {
|
2013-04-07 18:40:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2014-06-03 21:18:51 +00:00
|
|
|
input.datepicker( "open" );
|
|
|
|
ok( !input.datepicker( "widget" ).is( ":visible" ), "beforeOpen returns false" );
|
|
|
|
input.datepicker( "destroy" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2012-11-09 21:27:45 +00:00
|
|
|
|
2015-04-07 00:06:31 +00:00
|
|
|
} );
|