2013-11-02 13:54:05 +00:00
|
|
|
(function( $ ) {
|
|
|
|
|
|
|
|
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" );
|
|
|
|
|
|
|
|
input.datepicker({ appendTo: "#qunit-fixture" });
|
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, $( "#qunit-fixture" )[ 0 ], "child of specified element" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
|
|
|
input.datepicker({ appendTo: "#does-not-exist" });
|
|
|
|
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" );
|
|
|
|
|
|
|
|
input.datepicker({ appendTo: detached });
|
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, detached[ 0 ], "detached jQuery object" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
|
|
|
input.datepicker({ appendTo: detached[ 0 ] });
|
|
|
|
container = input.datepicker( "widget" ).parent()[ 0 ];
|
|
|
|
equal( container, detached[ 0 ], "detached DOM element" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
});
|
|
|
|
|
2014-06-19 22:13:20 +00:00
|
|
|
test("buttons", function() {
|
|
|
|
expect( 3 );
|
|
|
|
|
|
|
|
var button,
|
|
|
|
buttons = {
|
|
|
|
"Ok": function() {},
|
|
|
|
"Cancel": function() {}
|
|
|
|
},
|
|
|
|
element = $( "#datepicker" ).datepicker({ buttons: buttons });
|
|
|
|
|
|
|
|
button = element.datepicker( "widget" ).find( ".ui-calendar-buttonpane button" );
|
|
|
|
equal( button.length, 2, "number of buttons" );
|
|
|
|
ok( button.parent().hasClass( "ui-calendar-buttonset" ), "buttons in container");
|
|
|
|
ok( element.datepicker( "widget" ).hasClass( "ui-calendar-buttons" ), "calendar wrapper adds class about having buttons" );
|
|
|
|
});
|
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
test( "dateFormat", function() {
|
2013-11-20 13:37:24 +00:00
|
|
|
expect( 2 );
|
2013-11-30 12:22:17 +00:00
|
|
|
var input = $( "#datepicker" ).val( "1/1/14" ).datepicker(),
|
2013-11-20 13:37:24 +00:00
|
|
|
picker = input.datepicker( "widget" ),
|
2014-04-23 15:49:03 +00:00
|
|
|
firstDayLink = picker.find( "td[id]:first a" );
|
2013-11-20 13:37:24 +00:00
|
|
|
|
|
|
|
input.datepicker( "open" );
|
|
|
|
firstDayLink.trigger( "mousedown" );
|
2013-11-30 12:22:17 +00:00
|
|
|
equal( input.val(), "1/1/14", "default formatting" );
|
2013-11-20 13:37:24 +00:00
|
|
|
|
2013-11-30 12:22:17 +00:00
|
|
|
input.datepicker( "option", "dateFormat", { date: "full" } );
|
|
|
|
equal( input.val(), "Wednesday, January 1, 2014", "updated formatting" );
|
2013-11-20 13:37:24 +00:00
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
2013-11-02 13:54:05 +00:00
|
|
|
});
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
test( "eachDay", function() {
|
2013-11-19 13:35:19 +00:00
|
|
|
expect( 5 );
|
|
|
|
var timestamp,
|
|
|
|
input = $( "#datepicker" ).datepicker(),
|
2014-04-23 15:49:03 +00:00
|
|
|
picker = input.datepicker( "widget" ),
|
2013-11-19 13:35:19 +00:00
|
|
|
firstCell = picker.find( "td[id]:first" );
|
|
|
|
|
|
|
|
equal( firstCell.find( "a" ).length, 1, "days are selectable by default" );
|
|
|
|
timestamp = parseInt( firstCell.find( "a" ).attr( "data-timestamp" ), 10 );
|
|
|
|
equal( new Date( timestamp ).getDate(), 1, "first available day is the 1st by default" );
|
|
|
|
|
|
|
|
// Do not render the 1st of the month
|
|
|
|
input.datepicker( "option", "eachDay", function( day ) {
|
|
|
|
if ( day.date === 1 ) {
|
|
|
|
day.render = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
firstCell = picker.find( "td[id]:first" );
|
|
|
|
timestamp = parseInt( firstCell.find( "a" ).attr( "data-timestamp" ), 10 );
|
|
|
|
equal( new Date( timestamp ).getDate(), 2, "first available day is the 2nd" );
|
|
|
|
|
|
|
|
// Display the 1st of the month but make it not selectable.
|
|
|
|
input.datepicker( "option", "eachDay", function( day ) {
|
|
|
|
if ( day.date === 1 ) {
|
|
|
|
day.selectable = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
firstCell = picker.find( "td[id]:first" );
|
|
|
|
equal( firstCell.find( "a" ).length, 0, "the 1st is not selectable" );
|
|
|
|
|
|
|
|
input.datepicker( "option", "eachDay", function( day ) {
|
|
|
|
if ( day.date === 1 ) {
|
|
|
|
day.extraClasses = "ui-custom";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ok( picker.find( "td[id]:first a" ).hasClass( "ui-custom" ), "extraClasses applied" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
2013-11-02 13:54:05 +00:00
|
|
|
});
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2013-11-18 14:23:15 +00:00
|
|
|
asyncTest( "position", function() {
|
|
|
|
expect( 3 );
|
|
|
|
var input = $( "<input>" ).datepicker().appendTo( "body" ).css({
|
|
|
|
position: "absolute",
|
|
|
|
top: 0,
|
|
|
|
left: 0
|
|
|
|
}),
|
|
|
|
container = input.datepicker( "widget" );
|
|
|
|
|
|
|
|
input.datepicker( "open" );
|
|
|
|
setTimeout(function() {
|
|
|
|
closeEnough( input.offset().left, container.offset().left, 1, "left sides line up by default" );
|
|
|
|
closeEnough( container.offset().top, input.offset().top + input.outerHeight(), 1,
|
|
|
|
"datepicker directly under input by default" );
|
|
|
|
|
|
|
|
// Change the position option using option()
|
|
|
|
input.datepicker( "option", "position", {
|
|
|
|
my: "left top",
|
|
|
|
at: "right bottom"
|
|
|
|
});
|
|
|
|
closeEnough( container.offset().left, input.offset().left + input.outerWidth(), 1,
|
|
|
|
"datepicker on right hand side of input after position change" );
|
|
|
|
|
|
|
|
input.remove();
|
|
|
|
start();
|
|
|
|
});
|
2013-11-02 13:54:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "showWeek", function() {
|
2013-11-15 14:17:13 +00:00
|
|
|
expect( 7 );
|
|
|
|
var input = $( "#datepicker" ).datepicker(),
|
|
|
|
container = input.datepicker( "widget" );
|
|
|
|
|
|
|
|
equal( container.find( "thead th" ).length, 7, "just 7 days, no column cell" );
|
2014-06-03 21:18:51 +00:00
|
|
|
equal( container.find( ".ui-calendar-week-col" ).length, 0,
|
2013-11-15 14:17:13 +00:00
|
|
|
"no week column cells present" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
|
|
|
input = $( "#datepicker" ).datepicker({ showWeek: true });
|
|
|
|
container = input.datepicker( "widget" );
|
|
|
|
equal( container.find( "thead th" ).length, 8, "7 days + a column cell" );
|
2014-06-03 21:18:51 +00:00
|
|
|
ok( container.find( "thead th:first" ).is( ".ui-calendar-week-col" ),
|
|
|
|
"first cell should have ui-calendar-week-col class name" );
|
|
|
|
equal( container.find( ".ui-calendar-week-col" ).length,
|
2013-11-15 14:17:13 +00:00
|
|
|
container.find( "tr" ).length, "one week cell for each week" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
|
|
|
|
input = $( "#datepicker" ).datepicker();
|
|
|
|
container = input.datepicker( "widget" );
|
|
|
|
equal( container.find( "thead th" ).length, 7, "no week column" );
|
|
|
|
input.datepicker( "option", "showWeek", true );
|
|
|
|
equal( container.find( "thead th" ).length, 8, "supports changing option after init" );
|
2013-11-02 13:54:05 +00:00
|
|
|
});
|
2014-06-19 22:13:20 +00:00
|
|
|
|
2014-06-04 17:07:23 +00:00
|
|
|
test( "min / max", function() {
|
|
|
|
expect( 14 );
|
|
|
|
|
|
|
|
var inp = TestHelpers.datepicker.init( "#datepicker" ),
|
|
|
|
minDate = new Date( 2008, 2 - 1, 29 ),
|
|
|
|
maxDate = new Date( 2008, 12 - 1, 7 );
|
|
|
|
|
|
|
|
inp.val( "6/4/08" ).datepicker( "option", { min: minDate } );
|
|
|
|
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > min" );
|
|
|
|
ok( inp.datepicker( "isValid" ) );
|
|
|
|
|
|
|
|
inp.datepicker( "option", { min: null } ).val( "1/4/08" ).datepicker( "option", { min: minDate } );
|
|
|
|
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 1 - 1, 4 ), "Min/max - value < min" );
|
|
|
|
ok( !inp.datepicker( "isValid" ) );
|
|
|
|
|
|
|
|
inp.datepicker( "option", { min: null } ).val( "6/4/08" ).datepicker( "option", { max: maxDate } );
|
|
|
|
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < max" );
|
|
|
|
ok( inp.datepicker( "isValid" ) );
|
|
|
|
|
|
|
|
inp.datepicker( "option", { max: null } ).val( "1/4/09" ).datepicker( "option", { max: maxDate } );
|
|
|
|
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2009, 1 - 1, 4 ), "Min/max - setDate > max" );
|
|
|
|
ok( !inp.datepicker( "isValid" ) );
|
|
|
|
|
|
|
|
inp.datepicker( "option", { max: null } ).val( "1/4/08" ).datepicker( "option", { min: minDate, max: maxDate } );
|
|
|
|
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 1 - 1, 4 ), "Min/max - value < min" );
|
|
|
|
ok( !inp.datepicker( "isValid" ) );
|
|
|
|
|
|
|
|
inp.datepicker( "option", { max: null } ).val( "6/4/08" ).datepicker( "option", { min: minDate, max: maxDate } );
|
|
|
|
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > min, < max" );
|
|
|
|
ok( inp.datepicker( "isValid" ) );
|
|
|
|
|
|
|
|
inp.datepicker( "option", { max: null } ).val( "1/4/09" ).datepicker( "option", { min: minDate, max: maxDate } );
|
|
|
|
TestHelpers.datepicker.equalsDate( inp.datepicker( "valueAsDate" ), new Date( 2009, 1 - 1, 4 ), "Min/max - value > max" );
|
|
|
|
ok( !inp.datepicker( "isValid" ) );
|
|
|
|
});
|
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
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
var input = TestHelpers.datepicker.init( "#datepicker", {
|
|
|
|
beforeOpen: function() {}
|
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
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
input = TestHelpers.datepicker.init( "#datepicker", {
|
|
|
|
beforeOpen: function() {
|
2012-11-09 21:27:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
input = TestHelpers.datepicker.init( "#datepicker", {
|
|
|
|
beforeOpen: function() {
|
2013-04-07 18:40:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2014-06-03 21:18:51 +00:00
|
|
|
input.datepicker( "open" );
|
|
|
|
ok( !input.datepicker( "widget" ).is( ":visible" ), "beforeOpen returns false" );
|
|
|
|
input.datepicker( "destroy" );
|
2012-11-09 21:27:45 +00:00
|
|
|
});
|
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
})(jQuery);
|