From 73a3d4e2915840306a826c4b47d03807f9de67b8 Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Fri, 16 May 2014 00:19:32 +0200
Subject: [PATCH 01/94] Datepicker: Introduce value option
Change status caching, fix existing value related methods, introduce
$.date construction with date object, add selected getter
---
external/date.js | 6 ++++
ui/datepicker.js | 85 +++++++++++++++++++++++++++++-------------------
2 files changed, 58 insertions(+), 33 deletions(-)
diff --git a/external/date.js b/external/date.js
index 06a67553205..71963981129 100644
--- a/external/date.js
+++ b/external/date.js
@@ -26,6 +26,9 @@ $.date = function( date, globalFormat ) {
if ( typeof date === "string" && date.length ) {
this.dateObject = Globalize.parseDate( date, globalFormat );
}
+ if ( date instanceof Date ) {
+ this.dateObject = date;
+ }
this.dateObject = this.dateObject || new Date();
this.globalFormat = globalFormat;
@@ -180,6 +183,9 @@ $.date.prototype = {
this.selected = this.clone();
return this;
},
+ selectedDate: function() {
+ return this.selected;
+ },
clone: function() {
var date = this.dateObject;
return new $.date( new Date( date.getFullYear(), date.getMonth(),
diff --git a/ui/datepicker.js b/ui/datepicker.js
index f2dfa2d1594..28a3e478325 100644
--- a/ui/datepicker.js
+++ b/ui/datepicker.js
@@ -45,6 +45,7 @@ $.widget( "ui.datepicker", {
showWeek: false,
show: true,
hide: true,
+ value: null,
// callbacks
beforeOpen: null,
@@ -54,17 +55,22 @@ $.widget( "ui.datepicker", {
},
_create: function() {
- this.date = $.date( null, this.options.dateFormat );
-
- this.date.eachDay = this.options.eachDay;
this.id = "ui-datepicker-" + idIncrement;
idIncrement++;
+
if ( this.element.is( "input" ) ) {
+ if ( !this.options.value && this.isValid() ) {
+ this.options.value = this._getParsedValue();
+ }
this._createPicker();
} else {
this.inline = true;
this.picker = this.element;
}
+
+ this.date = $.date( this.options.value, this.options.dateFormat ).select();
+ this.date.eachDay = this.options.eachDay;
+
this._on( this.picker, {
"click .ui-datepicker-prev": function( event ) {
event.preventDefault();
@@ -106,7 +112,7 @@ $.widget( "ui.datepicker", {
_handleKeydown: function( event ) {
if ( jQuery.inArray( event.keyCode, [ 13, 33, 34, 35, 36, 37, 38, 39, 40 ] ) === -1 ) {
- //only interested navigation keys
+ // only interested navigation keys
return;
}
event.preventDefault();
@@ -171,7 +177,7 @@ $.widget( "ui.datepicker", {
_createPicker: function() {
this.picker = $( "" )
.addClass( "ui-front" )
- // TODO add a ui-datepicker-popup class, move position:absolte to that
+ // TODO add a ui-datepicker-popup class, move position:absolute to that
.css( "position", "absolute" )
.uniqueId()
.hide();
@@ -217,6 +223,7 @@ $.widget( "ui.datepicker", {
}
}
break;
+ // TODO this is not in specs, keep?
case $.ui.keyCode.END:
if ( event.ctrlKey ) {
this.element.val( "" );
@@ -230,12 +237,12 @@ $.widget( "ui.datepicker", {
},
keyup: function() {
if ( this.isValid() && !this.inline ) {
- this.date.setTime( this.element.val() ).select();
+ this.date.setTime( this._getParsedValue() ).select();
this.refresh();
}
},
mousedown: function( event ) {
- if (this.isOpen) {
+ if ( this.isOpen ) {
suppressExpandOnFocus = true;
this.close();
return;
@@ -312,6 +319,7 @@ $.widget( "ui.datepicker", {
return element;
},
+
_createTmpl: function() {
this._createDatepicker();
this.picker.find( "button" ).button();
@@ -323,6 +331,7 @@ $.widget( "ui.datepicker", {
this.picker.find( ".ui-datepicker" ).css( "display", "block" );
this.grid = this.picker.find( ".ui-datepicker-calendar" );
},
+
_createDatepicker: function() {
var multiClasses = [],
pickerHtml = "";
@@ -345,6 +354,7 @@ $.widget( "ui.datepicker", {
.html( pickerHtml )
.appendTo( this.picker );
},
+
_buildMultiplePicker: function() {
var headerClass,
html = "",
@@ -572,8 +582,8 @@ $.widget( "ui.datepicker", {
// with the prev and next links would cause loss of focus issues because the links being
// interacted with will disappear while focused.
refresh: function() {
- //determine which day gridcell to focus after refresh
- //TODO: Prevent disabled cells from being focused
+ // determine which day gridcell to focus after refresh
+ // TODO: Prevent disabled cells from being focused
if ( this.options.numberOfMonths === 1 ) {
this.grid = $( this._buildGrid() );
$( ".ui-datepicker-title", this.picker ).html( this._buildTitle() );
@@ -605,10 +615,6 @@ $.widget( "ui.datepicker", {
return;
}
- // TODO explain this
- this.date = $.date( this.element.val(), this.options.dateFormat );
- this.date.eachDay = this.options.eachDay;
- this.date.select();
this.refresh();
this.picker
@@ -649,46 +655,38 @@ $.widget( "ui.datepicker", {
},
_buildPosition: function() {
- return $.extend( {}, {
- of: this.element
- }, this.options.position );
+ return $.extend( {}, { of: this.element }, this.options.position );
},
_select: function( event, time ) {
- this.date.setTime( time ).select();
- this.refresh();
+ this._setOption( "value", new Date( time ) );
if ( !this.inline ) {
- this.element.val( this.date.format() );
this.close();
this._focusTrigger();
}
this._trigger( "select", event, {
// TODO replace with value option to initialise and read
- date: this.date.format()
+ date: this.value()
});
},
- _value: function( value ) {
- this.date.setTime( value ).select();
- if ( !this.inline ) {
- this.element.val( this.date.format() );
- }
- this.refresh();
- },
-
value: function( value ) {
if ( arguments.length ) {
- this._value( value );
+ this._setOption( "value", Globalize.parseDate( value, this.options.dateFormat ) );
} else {
- return this.isValid() ? this.date.format() : this.element.val();
+ if ( this.inline ) {
+ return Globalize.format( this.date.selected(), this.options.dateFormat );
+ } else {
+ return this.element.val();
+ }
}
},
valueAsDate: function( value ) {
if ( arguments.length ) {
- this._value( value );
+ this._setOption( "value", value );
} else {
- return this.isValid() ? this.date.date() : null;
+ return this.option( "value" );
}
},
@@ -697,7 +695,7 @@ $.widget( "ui.datepicker", {
return true;
}
- return Globalize.parseDate( this.element.val(), this.options.dateFormat ) !== null;
+ return this._getParsedValue() !== null;
},
_destroy: function() {
@@ -715,7 +713,28 @@ $.widget( "ui.datepicker", {
return this.picker;
},
+ _getParsedValue: function() {
+ return Globalize.parseDate( this.element.val(), this.options.dateFormat );
+ },
+
+ option: function( key ) {
+ if ( arguments.length === 0 || ( arguments.length === 1 && key === "value" ) ) {
+ this.options.value = this.inline ? this.date.selected() : this._getParsedValue();
+ }
+ return this._superApply( arguments );
+ },
+
_setOption: function( key, value ) {
+ if ( key === "value" ) {
+ if ( value instanceof Date ) {
+ this.date.setTime( value.getTime() ).select();
+ this.refresh();
+ if ( !this.inline ) {
+ this.element.val( this.date.format() );
+ }
+ }
+ }
+
this._super( key, value );
if ( key === "appendTo" ) {
From 500ba8de08fa92cc5c957ae4dc1330df3b0ac795 Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Tue, 3 Jun 2014 23:18:51 +0200
Subject: [PATCH 02/94] Calendar: Add calendar widget
Add calendar widget by copying and renaming datepicker widget files
---
Gruntfile.js | 1 +
build/tasks/testswarm.js | 1 +
demos/calendar/buttonbar.html | 33 +
demos/calendar/date-formats.html | 59 +
demos/calendar/default.html | 31 +
demos/calendar/dropdown-month-year.html | 34 +
demos/calendar/index.html | 28 +
demos/calendar/localization.html | 40 +
demos/calendar/min-max.html | 31 +
demos/calendar/multiple-calendars.html | 34 +
demos/calendar/other-months.html | 40 +
demos/calendar/show-week.html | 35 +
demos/index.html | 1 +
tests/unit/all.html | 1 +
tests/unit/calendar/all.html | 26 +
tests/unit/calendar/calendar.html | 49 +
tests/unit/calendar/calendar_common.js | 7 +
tests/unit/calendar/calendar_core.js | 711 ++++++++++
tests/unit/calendar/calendar_events.js | 150 +++
tests/unit/calendar/calendar_methods.js | 130 ++
tests/unit/calendar/calendar_options.js | 1273 ++++++++++++++++++
tests/unit/calendar/calendar_test_helpers.js | 28 +
tests/unit/index.html | 1 +
themes/base/base.css | 1 +
themes/base/calendar.css | 179 +++
ui/calendar.js | 766 +++++++++++
26 files changed, 3690 insertions(+)
create mode 100644 demos/calendar/buttonbar.html
create mode 100644 demos/calendar/date-formats.html
create mode 100644 demos/calendar/default.html
create mode 100644 demos/calendar/dropdown-month-year.html
create mode 100644 demos/calendar/index.html
create mode 100644 demos/calendar/localization.html
create mode 100644 demos/calendar/min-max.html
create mode 100644 demos/calendar/multiple-calendars.html
create mode 100644 demos/calendar/other-months.html
create mode 100644 demos/calendar/show-week.html
create mode 100644 tests/unit/calendar/all.html
create mode 100644 tests/unit/calendar/calendar.html
create mode 100644 tests/unit/calendar/calendar_common.js
create mode 100644 tests/unit/calendar/calendar_core.js
create mode 100644 tests/unit/calendar/calendar_events.js
create mode 100644 tests/unit/calendar/calendar_methods.js
create mode 100644 tests/unit/calendar/calendar_options.js
create mode 100644 tests/unit/calendar/calendar_test_helpers.js
create mode 100644 themes/base/calendar.css
create mode 100644 ui/calendar.js
diff --git a/Gruntfile.js b/Gruntfile.js
index b8610b6f641..3d9a11963db 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -28,6 +28,7 @@ var
"core",
"accordion",
"autocomplete",
+ "calendar",
"button",
"datepicker",
"dialog",
diff --git a/build/tasks/testswarm.js b/build/tasks/testswarm.js
index a147b8f573c..0d500ef09dd 100644
--- a/build/tasks/testswarm.js
+++ b/build/tasks/testswarm.js
@@ -14,6 +14,7 @@ var versions = {
"Accordion": "accordion/accordion.html",
"Autocomplete": "autocomplete/autocomplete.html",
"Button": "button/button.html",
+ "Calendar": "calendar/calendar.html",
"Core": "core/core.html",
"Core_deprecated": "core/core_deprecated.html",
"Datepicker": "datepicker/datepicker.html",
diff --git a/demos/calendar/buttonbar.html b/demos/calendar/buttonbar.html
new file mode 100644
index 00000000000..77da1ab5749
--- /dev/null
+++ b/demos/calendar/buttonbar.html
@@ -0,0 +1,33 @@
+
+
+
+
+ jQuery UI Calendar - Display button bar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+
+
Display a button for selecting Today's date and a Done button for closing the calendar with the boolean showButtonPanel
option. Each button is enabled by default when the bar is displayed, but can be turned off with additional options. Button text is customizable.
+
+
+
diff --git a/demos/calendar/date-formats.html b/demos/calendar/date-formats.html
new file mode 100644
index 00000000000..95adf01fd64
--- /dev/null
+++ b/demos/calendar/date-formats.html
@@ -0,0 +1,59 @@
+
+
+
+
+ jQuery UI Calendar - Format date
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+Format options:
+
+ Short - M/d/yy in "en" locale
+ Long - MMMM d, y in "en" locale
+ ISO 8601 - yyyy-MM-dd
+
+
+
+
+
Display date feedback in a variety of ways. Choose a date format from the dropdown, then click on the input and select a date to see it in that format.
+
+
+
diff --git a/demos/calendar/default.html b/demos/calendar/default.html
new file mode 100644
index 00000000000..26c4c2eb3d5
--- /dev/null
+++ b/demos/calendar/default.html
@@ -0,0 +1,31 @@
+
+
+
+
+ jQuery UI Calendar - Default functionality
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+
+
The calendar is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.
+
+
+
diff --git a/demos/calendar/dropdown-month-year.html b/demos/calendar/dropdown-month-year.html
new file mode 100644
index 00000000000..30d4fa80b87
--- /dev/null
+++ b/demos/calendar/dropdown-month-year.html
@@ -0,0 +1,34 @@
+
+
+
+
+ jQuery UI Calendar - Display month & year menus
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+
+
Show month and year dropdowns in place of the static month/year header to facilitate navigation through large timeframes. Add the boolean changeMonth
and changeYear
options.
+
+
+
diff --git a/demos/calendar/index.html b/demos/calendar/index.html
new file mode 100644
index 00000000000..48097f5983e
--- /dev/null
+++ b/demos/calendar/index.html
@@ -0,0 +1,28 @@
+
+
+
+
+
+ jQuery UI Calendar Demos
+
+
+
+
+
+
+
diff --git a/demos/calendar/localization.html b/demos/calendar/localization.html
new file mode 100644
index 00000000000..8f97bbcc8ef
--- /dev/null
+++ b/demos/calendar/localization.html
@@ -0,0 +1,40 @@
+
+
+
+
+ jQuery UI Calendar - Localize calendar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+ German (Deutsch)
+ English
+
+
+
+
Localize the calendar calendar language and format (English / Western formatting is the default). The calendar includes built-in support for languages that read right-to-left, such as Arabic and Hebrew.
+
+
+
diff --git a/demos/calendar/min-max.html b/demos/calendar/min-max.html
new file mode 100644
index 00000000000..94826c71a71
--- /dev/null
+++ b/demos/calendar/min-max.html
@@ -0,0 +1,31 @@
+
+
+
+
+ jQuery UI Calendar - Restrict date range
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+
+
Restrict the range of selectable dates with the minDate
and maxDate
options. Set the beginning and end dates as actual dates (new Date(2009, 1 - 1, 26)), as a numeric offset from today (-20), or as a string of periods and units ('+1M +10D'). For the last, use 'D' for days, 'W' for weeks, 'M' for months, or 'Y' for years.
+
+
+
diff --git a/demos/calendar/multiple-calendars.html b/demos/calendar/multiple-calendars.html
new file mode 100644
index 00000000000..9fe2b7ab526
--- /dev/null
+++ b/demos/calendar/multiple-calendars.html
@@ -0,0 +1,34 @@
+
+
+
+
+ jQuery UI Calendar - Display multiple months
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+
+
Set the numberOfMonths
option to an integer of 2 or more to show multiple months in a single calendar.
+
+
+
diff --git a/demos/calendar/other-months.html b/demos/calendar/other-months.html
new file mode 100644
index 00000000000..3ad1aba37d9
--- /dev/null
+++ b/demos/calendar/other-months.html
@@ -0,0 +1,40 @@
+
+
+
+
+ jQuery UI Calendar - Dates in other months
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+
+
The calendar can show dates that come from other than the main month
+ being displayed. These other dates can also be made selectable.
+
+
+
diff --git a/demos/calendar/show-week.html b/demos/calendar/show-week.html
new file mode 100644
index 00000000000..e7fcb84957b
--- /dev/null
+++ b/demos/calendar/show-week.html
@@ -0,0 +1,35 @@
+
+
+
+
+ jQuery UI Calendar - Show week of the year
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Date:
+
+
+
The calendar can show the week of the year. The calculation follows
+ Unicode CLDR specification .
+ This means that some days from one year may be placed into weeks 'belonging' to another year.
+
+
+
diff --git a/demos/index.html b/demos/index.html
index f37874a4481..c4a0fdf9501 100644
--- a/demos/index.html
+++ b/demos/index.html
@@ -11,6 +11,7 @@
accordion
autocomplete
button
+ calendar
datepicker
dialog
draggable
diff --git a/tests/unit/all.html b/tests/unit/all.html
index f8a4636d051..85e21077412 100644
--- a/tests/unit/all.html
+++ b/tests/unit/all.html
@@ -21,6 +21,7 @@
"button/button.html",
"core/core.html",
"core/core_deprecated.html",
+ "calendar/calendar.html",
"datepicker/datepicker.html",
"dialog/dialog.html",
"draggable/draggable.html",
diff --git a/tests/unit/calendar/all.html b/tests/unit/calendar/all.html
new file mode 100644
index 00000000000..26c46415a6e
--- /dev/null
+++ b/tests/unit/calendar/all.html
@@ -0,0 +1,26 @@
+
+
+
+
+ jQuery UI calendar Test Suite
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/unit/calendar/calendar.html b/tests/unit/calendar/calendar.html
new file mode 100644
index 00000000000..5a5256a6bab
--- /dev/null
+++ b/tests/unit/calendar/calendar.html
@@ -0,0 +1,49 @@
+
+
+
+
+ jQuery UI calendar Test Suite
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/unit/calendar/calendar_common.js b/tests/unit/calendar/calendar_common.js
new file mode 100644
index 00000000000..b0df728acb6
--- /dev/null
+++ b/tests/unit/calendar/calendar_common.js
@@ -0,0 +1,7 @@
+/*
+TestHelpers.commonWidgetTests( "calendar", {
+ defaults: {
+ disabled: false
+ }
+});
+*/
diff --git a/tests/unit/calendar/calendar_core.js b/tests/unit/calendar/calendar_core.js
new file mode 100644
index 00000000000..18f00274ec3
--- /dev/null
+++ b/tests/unit/calendar/calendar_core.js
@@ -0,0 +1,711 @@
+(function( $ ) {
+
+module( "calendar: core" );
+
+TestHelpers.testJshint( "calendar" );
+
+test( "input's value determines starting date", function() {
+ expect( 3 );
+
+ var input = $( "#calendar" ).val( "1/1/14" ).calendar(),
+ picker = input.calendar( "widget" );
+
+ input.calendar( "open" );
+
+ equal( picker.find( ".ui-calendar-month" ).html(), "January", "correct month displayed" );
+ equal( picker.find( ".ui-calendar-year" ).html(), "2014", "correct year displayed" );
+ equal( picker.find( ".ui-state-focus" ).html(), "1", "correct day highlighted" );
+
+ input.val( "" ).calendar( "destroy" );
+});
+
+asyncTest( "baseStructure", function() {
+ expect( 42 );
+ var header, title, table, thead, week, panel, inl, child,
+ inp = TestHelpers.calendar.initNewInput(),
+ dp = inp.calendar( "widget" ).find( ".ui-calendar" );
+
+ function step1() {
+ inp.focus();
+ setTimeout(function() {
+ ok( dp.is( ":visible" ), "Structure - calendar visible" );
+ ok( !dp.is( ".ui-calendar-rtl" ), "Structure - not right-to-left" );
+ ok( !dp.is( ".ui-calendar-multi" ), "Structure - not multi-month" );
+ equal( dp.children().length, 3, "Structure - child count (header, calendar, buttonpane)" );
+
+ header = dp.children( ":first" );
+ ok( header.is( "div.ui-calendar-header" ), "Structure - header division" );
+ equal( header.children().length, 3, "Structure - header child count" );
+ ok( header.children( ":first" ).is( ".ui-calendar-prev" ) && header.children( ":first" ).html() !== "", "Structure - prev link" );
+ ok( header.children( ":eq(1)" ).is( ".ui-calendar-next" ) && header.children( ":eq(1)" ).html() !== "", "Structure - next link" );
+
+ title = header.children( ":last" ).children( ":first" );
+ ok( title.is( "div.ui-calendar-title" ) && title.html() !== "", "Structure - title division" );
+ equal( title.children().length, 2, "Structure - title child count" );
+ ok( title.children( ":first" ).is( "span.ui-calendar-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" );
+ ok( title.children( ":last" ).is( "span.ui-calendar-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" );
+
+ table = dp.children( ":eq(1)" );
+ ok( table.is( "table.ui-calendar-calendar" ), "Structure - month table" );
+ ok( table.children( ":first" ).is( "thead" ), "Structure - month table thead" );
+
+ thead = table.children( ":first" ).children( ":first" );
+ ok( thead.is( "tr" ), "Structure - month table title row" );
+ equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
+ ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" );
+ ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" );
+
+ week = table.children( ":eq(1)" ).children( ":first" );
+ ok( week.is( "tr" ), "Structure - month table week row" );
+ equal( week.children().length, 7, "Structure - week child count" );
+ // TODO: Preserve these class names or let the user use :first-child and :last-child?
+ // ok( week.children( ":first" ).is( "td.ui-calendar-week-end" ), "Structure - month table first day cell" );
+ // ok( week.children( ":last" ).is( "td.ui-calendar-week-end" ), "Structure - month table second day cell" );
+
+ inp.calendar( "close" ).calendar( "destroy" );
+ step2();
+ });
+ }
+
+ function step2() {
+ // Editable month/year and button panel
+ inp = TestHelpers.calendar.initNewInput({
+ changeMonth: true,
+ changeYear: true,
+ showButtonPanel: true
+ });
+ dp = inp.calendar( "widget" ).find( ".ui-calendar" );
+ inp.focus();
+ setTimeout(function() {
+ title = dp.find( "div.ui-calendar-title" );
+ // TODO: Re-add tests when changeMonth and changeYear are re-implemented
+ //ok( title.children( ":first" ).is( "select.ui-calendar-month" ), "Structure - month selector" );
+ //ok( title.children( ":last" ).is( "select.ui-calendar-year" ), "Structure - year selector" );
+
+ panel = dp.children( ":last" );
+ ok( panel.is( "div.ui-calendar-buttonpane" ), "Structure - button panel division" );
+ equal( panel.children().length, 2, "Structure - button panel child count" );
+ ok( panel.children( ":first" ).is( "button.ui-calendar-current" ), "Structure - today button" );
+ ok( panel.children( ":last" ).is( "button.ui-calendar-close" ), "Structure - close button" );
+
+ inp.calendar( "close" ).calendar( "destroy" );
+ step3();
+ });
+ }
+
+ function step3() {
+ // Multi-month 2
+ inp = TestHelpers.calendar.initNewInput({ numberOfMonths: 2 } );
+ dp = inp.calendar( "widget" ).find( ".ui-calendar" );
+ inp.focus();
+ setTimeout(function() {
+ ok( dp.is( ".ui-calendar-multi" ), "Structure multi [2] - multi-month" );
+ equal( dp.children().length, 4, "Structure multi [2] - child count" );
+
+ child = dp.children( ":first" );
+ // TODO: Implement ui-calendar-group-first class name
+ // ok( child.is( "div.ui-calendar-group" ) && child.is( "div.ui-calendar-group-first" ), "Structure multi [2] - first month division" );
+
+ child = dp.children( ":eq(1)" );
+ // TODO: Implement ui-calendar-group-last class name
+ // ok( child.is( "div.ui-calendar-group" ) && child.is( "div.ui-calendar-group-last" ), "Structure multi [2] - second month division" );
+
+ child = dp.children( ":eq(2)" );
+ ok( child.is( "div.ui-calendar-row-break" ), "Structure multi [2] - row break" );
+ ok( dp.is( ".ui-calendar-multi-2" ), "Structure multi [2] - multi-2" );
+
+ inp.calendar( "close" ).calendar( "destroy" );
+ step4();
+ });
+ }
+
+ function step4() {
+ // Multi-month 3
+ inp = TestHelpers.calendar.initNewInput({ numberOfMonths: 3 } );
+ dp = inp.calendar( "widget" ).find( ".ui-calendar" );
+ inp.focus();
+ setTimeout(function() {
+ ok( dp.is( ".ui-calendar-multi-3" ), "Structure multi [3] - multi-3" );
+ ok( !dp.is( ".ui-calendar-multi-2" ), "Structure multi [3] - Trac #6704" );
+
+ inp.calendar( "close" ).calendar( "destroy" );
+ step5();
+ });
+ }
+
+ function step5() {
+ // Multi-month [2, 2]
+ inp = TestHelpers.calendar.initNewInput({ numberOfMonths: [ 2, 2 ] } );
+ dp = inp.calendar( "widget" ).find( ".ui-calendar" );
+ inp.focus();
+ setTimeout(function() {
+ /*
+ TODO: Re-add after array form of the numberOfMonths option is implemented.
+ ok( dp.is( ".ui-calendar-multi" ), "Structure multi - multi-month" );
+ equal( dp.children().length, 6, "Structure multi [2,2] - child count" );
+
+ child = dp.children( ":first" );
+ ok( child.is( "div.ui-calendar-group" ) && child.is( "div.ui-calendar-group-first" ), "Structure multi [2,2] - first month division" );
+
+ child = dp.children( ":eq(1)" );
+ ok( child.is( "div.ui-calendar-group" ) && child.is( "div.ui-calendar-group-last" ), "Structure multi [2,2] - second month division" );
+
+ child = dp.children( ":eq(2)" );
+ ok( child.is( "div.ui-calendar-row-break" ), "Structure multi [2,2] - row break" );
+
+ child = dp.children( ":eq(3)" );
+ ok( child.is( "div.ui-calendar-group" ) && child.is( "div.ui-calendar-group-first" ), "Structure multi [2,2] - third month division" );
+
+ child = dp.children( ":eq(4)" );
+ ok( child.is( "div.ui-calendar-group" ) && child.is( "div.ui-calendar-group-last" ), "Structure multi [2,2] - fourth month division" );
+
+ child = dp.children( ":eq(5)" );
+ ok( child.is( "div.ui-calendar-row-break" ), "Structure multi [2,2] - row break" );
+ */
+ inp.calendar( "close" ).calendar( "destroy" );
+ step6();
+ });
+ }
+
+ function step6() {
+ // Inline
+ inl = TestHelpers.calendar.init( "#inline" );
+ dp = inl.children();
+
+ ok( dp.is( ".ui-calendar-inline" ), "Structure inline - main div" );
+ ok( !dp.is( ".ui-calendar-rtl" ), "Structure inline - not right-to-left" );
+ ok( !dp.is( ".ui-calendar-multi" ), "Structure inline - not multi-month" );
+ equal( dp.children().length, 3, "Structure inline - child count (header, calendar, buttonpane)" );
+
+ header = dp.children( ":first" );
+ ok( header.is( "div.ui-calendar-header" ), "Structure inline - header division" );
+ equal( header.children().length, 3, "Structure inline - header child count" );
+
+ table = dp.children( ":eq(1)" );
+ ok( table.is( "table.ui-calendar-calendar" ), "Structure inline - month table" );
+ ok( table.children( ":first" ).is( "thead" ), "Structure inline - month table thead" );
+ ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure inline - month table body" );
+
+ inl.calendar( "destroy" );
+
+ step7();
+ }
+
+ function step7() {
+ // Inline multi-month
+ inl = TestHelpers.calendar.init( "#inline", { numberOfMonths: 2 } );
+ dp = inl.calendar( "widget" ).find( ".ui-calendar" );
+
+ ok( dp.is( ".ui-calendar-inline" ) && dp.is( ".ui-calendar-multi" ), "Structure inline multi - main div" );
+ equal( dp.children().length, 4, "Structure inline multi - child count" );
+
+ child = dp.children( ":first" );
+ // TODO: Implement ui-calendar-group-first class name
+ // ok( child.is( "div.ui-calendar-group" ) && child.is( "div.ui-calendar-group-first" ), "Structure inline multi - first month division" );
+
+ child = dp.children( ":eq(1)" );
+ // TODO: Implement ui-calendar-group-last class name
+ // ok( child.is( "div.ui-calendar-group" ) && child.is( "div.ui-calendar-group-last" ), "Structure inline multi - second month division" );
+
+ child = dp.children( ":eq(2)" );
+ ok( child.is( "div.ui-calendar-row-break" ), "Structure inline multi - row break" );
+
+ inl.calendar( "destroy" );
+ start();
+ }
+
+ step1();
+});
+
+// Skip these tests for now as none are implemented yet.
+/*
+asyncTest( "customStructure", function() {
+ expect( 0 );
+
+ var header, panel, title,
+ inp = TestHelpers.calendar.initNewInput(),
+ dp = inp.calendar( "widget" ).find( ".ui-calendar" );
+
+ start();
+
+ function step1() {
+ Globalize.culture( "he" );
+ inp.focus();
+
+ setTimeout(function() {
+ ok( dp.is( ".ui-calendar-rtl" ), "Structure RTL - right-to-left" );
+
+ header = dp.children( ":first" );
+ ok( header.is( "div.ui-calendar-header" ), "Structure RTL - header division" );
+ equal( header.children().length, 3, "Structure RTL - header child count" );
+ ok( header.children( ":first" ).is( "a.ui-calendar-next" ), "Structure RTL - prev link" );
+ ok( header.children( ":eq(1)" ).is( "a.ui-calendar-prev" ), "Structure RTL - next link" );
+
+ panel = dp.children( ":last" );
+ ok( panel.is( "div.ui-calendar-buttonpane" ), "Structure RTL - button division" );
+ equal( panel.children().length, 2, "Structure RTL - button panel child count" );
+ ok( panel.children( ":first" ).is( "button.ui-calendar-close" ), "Structure RTL - close button" );
+ ok( panel.children( ":last" ).is( "button.ui-calendar-current" ), "Structure RTL - today button" );
+
+ inp.calendar( "close" ).calendar( "destroy" );
+ Globalize.culture( "en-US" );
+ step2();
+ });
+ }
+
+ // Hide prev/next
+ // TODO: If we decide the hideIfNoPrevNext option is being removed these tests can be as well.
+ function stepX() {
+ inp = TestHelpers.calendar.initNewInput({
+ hideIfNoPrevNext: true,
+ minDate: new Date( 2008, 2 - 1, 4 ),
+ maxDate: new Date( 2008, 2 - 1, 14 )
+ });
+ inp.val( "02/10/2008" );
+
+ TestHelpers.calendar.onFocus( inp, function() {
+ header = dp.children( ":first" );
+ ok( header.is( "div.ui-calendar-header" ), "Structure hide prev/next - header division" );
+ equal( header.children().length, 1, "Structure hide prev/next - links child count" );
+ ok( header.children( ":first" ).is( "div.ui-calendar-title" ), "Structure hide prev/next - title division" );
+
+ inp.calendar( "hide" ).calendar( "destroy" );
+ step3();
+ });
+ }
+
+ // Changeable Month with read-only year
+ function step2() {
+ inp = TestHelpers.calendar.initNewInput({ changeMonth: true } );
+ dp = inp.calendar( "widget" ).find( ".ui-calendar" );
+
+ inp.focus();
+ setTimeout(function() {
+ title = dp.children( ":first" ).children( ":last" );
+
+ // TODO: Implement changeMonth option
+ // equal( title.children().length, 2, "Structure changeable month - title child count" );
+ // ok( title.children( ":first" ).is( "select.ui-calendar-month" ), "Structure changeable month - month selector" );
+ // ok( title.children( ":last" ).is( "span.ui-calendar-year" ), "Structure changeable month - read-only year" );
+
+ inp.calendar( "close" ).calendar( "destroy" );
+ step3();
+ });
+ }
+
+ // Changeable year with read-only month
+ function step3() {
+ inp = TestHelpers.calendar.initNewInput({ changeYear: true } );
+
+ TestHelpers.calendar.onFocus( inp, function() {
+ title = dp.children( ":first" ).children( ":last" );
+
+ // TODO: Implement changeYear option
+ // equal( title.children().length, 2, "Structure changeable year - title child count" );
+ // ok( title.children( ":first" ).is( "span.ui-calendar-month" ), "Structure changeable year - read-only month" );
+ // ok( title.children( ":last" ).is( "select.ui-calendar-year" ), "Structure changeable year - year selector" );
+
+ inp.calendar( "close" ).calendar( "destroy" );
+ start();
+ });
+ }
+
+ // TODO: figure out why this setTimeout is needed in IE,
+ // it only is necessary when the previous baseStructure tests runs first
+ // Support: IE
+ setTimeout( step1 );
+});
+*/
+
+test( "Keyboard handling", function() {
+ expect( 9 );
+ var input = $( "#calendar" ).calendar(),
+ instance = input.calendar( "instance" ),
+ date = new Date();
+
+ input.calendar( "open" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date, "Keystroke enter" );
+
+ // Enter = Select today's date by default
+ input.val( "1/1/14" ).calendar( "open" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2014, 0, 1 ),
+ "Keystroke enter - preset" );
+
+ // Control + Home = Change the calendar to the current month
+ input.val( "1/1/14" ).calendar( "open" )
+ .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.HOME } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date, "Keystroke ctrl+home" );
+
+ // Control + End = Close the calendar and clear the input
+ input.val( "1/1/14" ).calendar( "open" )
+ .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.END } );
+ equal( input.val(), "", "Keystroke ctrl+end" );
+
+ input.val( "" ).calendar( "open" );
+ ok( instance.isOpen, "calendar is open before escape" );
+ input.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
+ ok( !instance.isOpen, "escape closes the calendar" );
+
+ input.val( "1/1/14" ).calendar( "open" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2014, 0, 1 ),
+ "Keystroke esc - preset" );
+
+ input.val( "1/1/14" ).calendar( "open" )
+ .simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2014, 0, 1 ),
+ "Keystroke esc - abandoned" );
+
+ input.val( "1/2/14" )
+ .simulate( "keyup" );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2014, 0, 2 ),
+ "Picker updated as user types into input" );
+
+ input.calendar( "destroy" );
+});
+
+asyncTest( "keyboard handling", function() {
+ expect( 14 );
+ var picker,
+ input = $( "#calendar" ),
+ date = new Date();
+
+ function step1() {
+ input.calendar();
+ picker = input.calendar( "widget" );
+ ok( !picker.is( ":visible" ), "calendar closed" );
+ input.val( "" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ ok( picker.is( ":visible" ), "Keystroke down opens calendar" );
+ input.calendar( "destroy" );
+ step2();
+ });
+ }
+
+ function step2() {
+ input.calendar();
+ picker = input.calendar( "widget" );
+ ok( !picker.is( ":visible" ), "calendar closed" );
+ input.val( "" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
+
+ setTimeout(function() {
+ ok( picker.is( ":visible" ), "Keystroke up opens calendar" );
+ input.calendar( "destroy" );
+ step3();
+ });
+ }
+
+ function step3() {
+ input.calendar()
+ .val( "1/1/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2013, 12 - 1, 31 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke left to switch to previous day" );
+
+ input.calendar( "destroy" );
+ step4();
+ }, 100 );
+ }
+
+ function step4() {
+ input.calendar()
+ .val( "1/1/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2014, 1 - 1, 2 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke right to switch to next day" );
+
+ input.calendar( "destroy" );
+ step5();
+ }, 100 );
+ }
+
+ function step5() {
+ input.calendar()
+ .val( "1/1/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.UP } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2013, 12 - 1, 25 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke up to move to the previous week" );
+
+ input.calendar( "destroy" );
+ step6();
+ }, 100 );
+ }
+
+ function step6() {
+ input.calendar()
+ .val( "1/1/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2014, 1 - 1, 8 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke down to move to the next week" );
+
+ input.calendar( "destroy" );
+ step7();
+ }, 100 );
+ }
+
+ function step7() {
+ input.calendar()
+ .val( "1/1/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2013, 12 - 1, 1 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke Page Up moves date to previous month" );
+
+ input.calendar( "destroy" );
+ step8();
+ }, 100 );
+ }
+
+ function step8() {
+ input.calendar()
+ .val( "1/1/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP, altKey: true } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2013, 1 - 1, 1 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke Page Up + Ctrl moves date to previous year" );
+
+ input.calendar( "destroy" );
+ step9();
+ }, 100 );
+ }
+
+ function step9() {
+ input.calendar()
+ .val( "1/1/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2014, 2 - 1, 1 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke Page Down moves date to next month" );
+
+ input.calendar( "destroy" );
+ step10();
+ }, 100 );
+ }
+
+ function step10() {
+ input.calendar()
+ .val( "1/1/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN, altKey: true } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2015, 1 - 1, 1 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke Page Down + Ctrl moves date to next year" );
+
+ input.calendar( "destroy" );
+ step11();
+ }, 100 );
+ }
+
+ // Check for moving to short months
+ function step11() {
+ input.calendar()
+ .val( "3/31/14" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2014, 2 - 1, 28 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke Page Up and short months" );
+
+ input.calendar( "destroy" );
+ step12();
+ }, 100 );
+ }
+
+ function step12() {
+ input.calendar()
+ .val( "1/30/16" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+
+ setTimeout(function() {
+ $( ":focus" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ date = new Date( 2016, 2 - 1, 29 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date,
+ "Keystroke Page Down and leap years" );
+
+ input.calendar( "destroy" );
+ start();
+ }, 100 );
+ }
+
+ step1();
+});
+
+/*
+ // TODO: Re-add tests if we implement a stepMonths option
+ input.calendar( "option", { stepMonths: 2, gotoCurrent: false } )
+ .calendar( "close" ).val( "02/04/2008" ).calendar( "open" )
+ .late( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2007, 12 - 1, 4 ),
+ "Keystroke pgup step 2" );
+
+ input.val( "02/04/2008" ).calendar( "open" )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } )
+ .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2008, 4 - 1, 4 ),
+ "Keystroke pgdn step 2" );
+*/
+
+test( "mouse", function() {
+ expect( 13 );
+ var input = $( "#calendar" ).calendar(),
+ picker = input.calendar( "widget" ),
+ inline = $( "#inline" ).calendar,
+ date = new Date();
+
+ input.val( "" ).calendar( "open" );
+ $( ".ui-calendar-calendar tbody a:contains(10)", picker ).simulate( "mousedown", {} );
+ date.setDate( 10 );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date, "Mouse click" );
+
+ input.val( "2/4/08" ).calendar( "open" );
+ $( ".ui-calendar-calendar tbody a:contains(12)", picker ).simulate( "mousedown", {} );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2008, 2 - 1, 12 ),
+ "Mouse click - preset" ) ;
+
+ input.val( "" ).calendar( "open" );
+ $( "button.ui-calendar-close", picker ).simulate( "click", {} );
+ ok( input.calendar( "valueAsDate" ) == null, "Mouse click - close" );
+
+ input.val( "2/4/08" ).calendar( "open" );
+ $( "button.ui-calendar-close", picker ).simulate( "click", {} );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2008, 2 - 1, 4 ),
+ "Mouse click - close + preset" );
+
+ input.val( "2/4/08" ).calendar( "open" );
+ $( "a.ui-calendar-prev", picker ).simulate( "click", {} );
+ $( "button.ui-calendar-close", picker ).simulate( "click", {} );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2008, 2 - 1, 4 ),
+ "Mouse click - abandoned" );
+
+ // Current/previous/next
+ input.val( "" ).calendar( "open" );
+ $( ".ui-calendar-current", picker ).simulate( "click", {} );
+ date.setDate( new Date().getDate() );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), date, "Mouse click - current" );
+
+ input.val( "2/4/08" ).calendar( "open" );
+ $( ".ui-calendar-prev", picker ).simulate( "click" );
+ $( ".ui-calendar-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2008, 1 - 1, 16 ),
+ "Mouse click - previous" );
+
+ input.val( "2/4/08" ).calendar( "open" );
+ $( ".ui-calendar-next", picker ).simulate( "click" );
+ $( ".ui-calendar-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2008, 3 - 1, 18 ),
+ "Mouse click - next" );
+
+ /*
+ // TODO: Re-add when min and max options are introduced.
+ // Previous/next with minimum/maximum
+ input.calendar( "option", {
+ minDate: new Date( 2008, 2 - 1, 2 ),
+ maxDate: new Date( 2008, 2 - 1, 26 )
+ }).val( "2/4/08" ).calendar( "open" );
+ $( ".ui-calendar-prev", picker ).simulate( "click" );
+ $( ".ui-calendar-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ), new Date( 2008, 2 - 1, 16 ),
+ "Mouse click - previous + min/max" );
+
+ input.val( "2/4/08" ).calendar( "open" );
+ $( ".ui-calendar-next", picker ).simulate( "click" );
+ $( ".ui-calendar-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
+ TestHelpers.calendar.equalsDate(input.calendar( "valueAsDate" ), new Date( 2008, 2 - 1, 18 ),
+ "Mouse click - next + min/max" );
+ */
+
+ // Inline
+ inline = TestHelpers.calendar.init( "#inline" );
+ picker = $( ".ui-calendar-inline", inline );
+ date = new Date();
+ inline.calendar( "valueAsDate", date );
+ $( ".ui-calendar-calendar tbody a:contains(10)", picker ).simulate( "mousedown", {} );
+ date.setDate( 10 );
+ TestHelpers.calendar.equalsDate( inline.calendar( "valueAsDate" ), date, "Mouse click inline" );
+
+ inline.calendar( "option", { showButtonPanel: true } )
+ .calendar( "valueAsDate", new Date( 2008, 2 - 1, 4 ));
+ $( ".ui-calendar-calendar tbody a:contains(12)", picker ).simulate( "mousedown", {} );
+ TestHelpers.calendar.equalsDate( inline.calendar( "valueAsDate" ), new Date( 2008, 2 - 1, 12 ),
+ "Mouse click inline - preset" );
+
+ inline.calendar( "option", { showButtonPanel: true } );
+ $( ".ui-calendar-current", picker ).simulate( "click", {} );
+ $( ".ui-calendar-calendar tbody a:contains(14)", picker ).simulate( "mousedown", {} );
+ date.setDate( 14 );
+ TestHelpers.calendar.equalsDate( inline.calendar( "valueAsDate" ), date, "Mouse click inline - current" );
+
+ inline.calendar( "valueAsDate", new Date( 2008, 2 - 1, 4) );
+ $( ".ui-calendar-prev", picker ).simulate( "click" );
+ $( ".ui-calendar-calendar tbody a:contains(16)", picker ).simulate( "mousedown" );
+ TestHelpers.calendar.equalsDate( inline.calendar( "valueAsDate" ), new Date( 2008, 1 - 1, 16 ),
+ "Mouse click inline - previous" );
+
+ inline.calendar( "valueAsDate", new Date( 2008, 2 - 1, 4) );
+ $( ".ui-calendar-next", picker ).simulate( "click" );
+ $( ".ui-calendar-calendar tbody a:contains(18)", picker ).simulate( "mousedown" );
+ TestHelpers.calendar.equalsDate( inline.calendar( "valueAsDate" ), new Date( 2008, 3 - 1, 18 ),
+ "Mouse click inline - next" );
+
+ input.calendar( "destroy" );
+ inline.calendar( "destroy" );
+});
+
+})( jQuery );
diff --git a/tests/unit/calendar/calendar_events.js b/tests/unit/calendar/calendar_events.js
new file mode 100644
index 00000000000..2d03801fadb
--- /dev/null
+++ b/tests/unit/calendar/calendar_events.js
@@ -0,0 +1,150 @@
+// The implement of events is completely changing therefore these tests are no longer directly
+// relevant. Leaving them around commented out so we can ensure the functionality is replicated.
+// For example:
+// TODO: In the old implementation the Enter key select's today's date when the has
+// focus and is empty. Do we want to replicate this behavior in the rewrite?
+/*
+
+(function( $ ) {
+
+module( "calendar: events" );
+
+test( "beforeOpen", function() {
+ expect( 0 );
+});
+
+test( "close", function() {
+ expect( 0 );
+});
+
+test( "open", function() {
+ expect( 0 );
+});
+
+test( "select", function() {
+ expect( 0 );
+});
+
+var selectedThis = null,
+selectedDate = null,
+selectedInst = null;
+
+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() {
+ expect( 26 );
+ var dateStr, newMonthYear, inp2,
+ inp = TestHelpers.calendar.init( "#inp", {onSelect: callback}),
+ date = new Date();
+ // onSelect
+ inp.val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ equal(selectedThis, inp[0], "Callback selected this" );
+ equal(selectedInst, $.data(inp[0], TestHelpers.calendar.PROP_NAME), "Callback selected inst" );
+ equal(selectedDate, $.calendar.formatDate( "mm/dd/yy", date),
+ "Callback selected date" );
+ inp.val( "" ).calendar( "show" ).
+ simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.DOWN}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date.setDate(date.getDate() + 7);
+ equal(selectedDate, $.calendar.formatDate( "mm/dd/yy", date),
+ "Callback selected date - ctrl+down" );
+ inp.val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE});
+ equal(selectedDate, $.calendar.formatDate( "mm/dd/yy", date),
+ "Callback selected date - esc" );
+ dateStr = "02/04/2008";
+ inp.val(dateStr).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ equal(dateStr, selectedDate,
+ "onSelect is called after enter keydown" );
+ // onChangeMonthYear
+ inp.calendar( "option", {onChangeMonthYear: callback2, onSelect: null}).
+ val( "" ).calendar( "show" );
+ newMonthYear = function(date) {
+ return date.getFullYear() + "/" + (date.getMonth() + 1);
+ };
+ date = new Date();
+ date.setDate(1);
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_UP});
+ date.setMonth(date.getMonth() - 1);
+ equal(selectedThis, inp[0], "Callback change month/year this" );
+ equal(selectedInst, $.data(inp[0], TestHelpers.calendar.PROP_NAME), "Callback change month/year inst" );
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year date - pgup" );
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN});
+ date.setMonth(date.getMonth() + 1);
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year date - pgdn" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP});
+ date.setFullYear(date.getFullYear() - 1);
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year date - ctrl+pgup" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.HOME});
+ date.setFullYear(date.getFullYear() + 1);
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year date - ctrl+home" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN});
+ date.setFullYear(date.getFullYear() + 1);
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year date - ctrl+pgdn" );
+ inp.calendar( "setDate", new Date(2007, 1 - 1, 26));
+ equal(selectedDate, "2007/1", "Callback change month/year date - setDate" );
+ selectedDate = null;
+ inp.calendar( "setDate", new Date(2007, 1 - 1, 12));
+ ok(selectedDate == null, "Callback change month/year date - setDate no change" );
+ // onChangeMonthYear step by 2
+ inp.calendar( "option", {stepMonths: 2}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_UP});
+ date.setMonth(date.getMonth() - 14);
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year by 2 date - pgup" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP});
+ date.setMonth(date.getMonth() - 12);
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year by 2 date - ctrl+pgup" );
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN});
+ date.setMonth(date.getMonth() + 2);
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year by 2 date - pgdn" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN});
+ date.setMonth(date.getMonth() + 12);
+ equal(selectedDate, newMonthYear(date),
+ "Callback change month/year by 2 date - ctrl+pgdn" );
+ // onClose
+ inp.calendar( "option", {onClose: callback, onChangeMonthYear: null, stepMonths: 1}).
+ val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE});
+ equal(selectedThis, inp[0], "Callback close this" );
+ equal(selectedInst, $.data(inp[0], TestHelpers.calendar.PROP_NAME), "Callback close inst" );
+ equal(selectedDate, "", "Callback close date - esc" );
+ inp.val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ equal(selectedDate, $.calendar.formatDate( "mm/dd/yy", new Date()),
+ "Callback close date - enter" );
+ inp.val( "02/04/2008" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE});
+ equal(selectedDate, "02/04/2008", "Callback close date - preset" );
+ inp.val( "02/04/2008" ).calendar( "show" ).
+ simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END});
+ equal(selectedDate, "", "Callback close date - ctrl+end" );
+
+ inp2 = TestHelpers.calendar.init( "#inp2" );
+ inp2.calendar().calendar( "option", {onClose: callback}).calendar( "show" );
+ inp.calendar( "show" );
+ equal(selectedThis, inp2[0], "Callback close this" );
+});
+
+})( jQuery );
+ */
diff --git a/tests/unit/calendar/calendar_methods.js b/tests/unit/calendar/calendar_methods.js
new file mode 100644
index 00000000000..89547463cf8
--- /dev/null
+++ b/tests/unit/calendar/calendar_methods.js
@@ -0,0 +1,130 @@
+(function( $ ) {
+
+module( "calendar: methods" );
+
+test( "destroy", function() {
+ expect( 10 );
+ var input = $( "#calendar" ).calendar(),
+ inline = $( "#inline" ).calendar();
+
+ ok( input.calendar( "instance" ), "instance created" );
+ ok( input.attr( "aria-owns" ), "aria-owns attribute added" );
+ ok( input.attr( "aria-haspopup" ), "aria-haspopup attribute added" );
+ input.calendar( "destroy" );
+ ok( !input.calendar( "instance" ), "instance removed" );
+ ok( !input.attr( "aria-owns" ), "aria-owns attribute removed" );
+ ok( !input.attr( "aria-haspopup" ), "aria-haspopup attribute removed" );
+
+ ok( inline.calendar( "instance" ), "instance created" );
+ ok( inline.children().length > 0, "inline calendar has children" );
+ inline.calendar( "destroy" );
+ ok( !inline.calendar( "instance" ), "instance removed" );
+ ok( inline.children().length === 0, "inline picker no longer has children" );
+});
+
+test( "enable / disable", function() {
+ expect( 6 );
+ var inl,
+ inp = TestHelpers.calendar.init( "#calendar" ),
+ dp = inp.calendar( "widget" );
+
+ ok( !inp.calendar( "option", "disabled" ), "initially enabled" );
+ ok( !dp.hasClass( "ui-calendar-disabled" ), "does not have disabled class name" );
+
+ inp.calendar( "disable" );
+ ok( inp.calendar( "option", "disabled" ), "disabled option is set" );
+ ok( dp.hasClass( "ui-calendar-disabled" ), "calendar has disabled class name" );
+
+ inp.calendar( "enable" );
+ ok( !inp.calendar( "option", "disabled" ), "enabled after enable() call" );
+ ok( !dp.hasClass( "ui-calendar-disabled" ), "no longer has disabled class name" );
+
+ // Inline
+ inl = TestHelpers.calendar.init( "#inline" );
+ dp = inl.calendar( "instance" );
+
+ // TODO: Disabling inline pickers does not work.
+ // TODO: When changeMonth and changeYear options are implemented ensure their dropdowns
+ // are properly disabled when in an inline picker.
+});
+
+test( "widget", function() {
+ expect( 1 );
+ var actual = $( "#calendar" ).calendar().calendar( "widget" );
+ deepEqual( $( "body > .ui-front" )[ 0 ], actual[ 0 ] );
+ actual.remove();
+});
+
+test( "close", function() {
+ expect( 0 );
+});
+
+test( "open", function() {
+ expect( 0 );
+});
+
+test( "value", function() {
+ expect( 6 );
+ var input = $( "#calendar" ).calendar(),
+ picker = input.calendar( "widget" ),
+ inline = $( "#inline" ).calendar();
+
+ input.calendar( "value", "1/1/14" );
+ equal( input.val(), "1/1/14", "input's value set" );
+ ok( picker.find( "a[data-timestamp]:first" ).hasClass( "ui-state-focus" ),
+ "first day marked as selected" );
+ equal( input.calendar( "value" ), "1/1/14", "getter" );
+
+ input.val( "abc" );
+ equal( input.calendar( "value" ), "abc",
+ "Invalid values should be returned without formatting." );
+
+ inline.calendar( "value", "1/1/14" );
+ ok( inline.find( "a[data-timestamp]:first" ).hasClass( "ui-state-focus" ),
+ "first day marked as selected" );
+ equal( inline.calendar( "value" ), "1/1/14", "getter" );
+
+ input.calendar( "destroy" );
+ inline.calendar( "destroy" );
+});
+
+test( "valueAsDate", function() {
+ expect( 6 );
+ var input = $( "#calendar" ).calendar(),
+ picker = input.calendar( "widget" ),
+ inline = $( "#inline" ).calendar();
+
+ input.calendar( "valueAsDate", new Date( 2014, 0, 1 ) );
+ equal( input.val(), "1/1/14", "input's value set" );
+ ok( picker.find( "a[data-timestamp]:first" ).hasClass( "ui-state-focus" ),
+ "first day marked as selected" );
+ TestHelpers.calendar.equalsDate( input.calendar( "valueAsDate" ),
+ new Date( 2014, 0, 1 ), "getter" );
+
+ input.val( "a/b/c" );
+ equal( input.calendar( "valueAsDate" ), null, "Invalid dates return null" );
+
+ inline.calendar( "valueAsDate", new Date( 2014, 0, 1 ) );
+ ok( inline.find( "a[data-timestamp]:first" ).hasClass( "ui-state-focus" ),
+ "first day marked as selected" );
+ TestHelpers.calendar.equalsDate( inline.calendar( "valueAsDate" ),
+ new Date( 2014, 0, 1 ), "getter" );
+
+ input.calendar( "destroy" );
+ inline.calendar( "destroy" );
+});
+
+test( "isValid", function() {
+ expect( 2 );
+ var input = $( "#calendar" ).calendar();
+
+ input.val( "1/1/14" );
+ ok( input.calendar( "isValid" ) );
+
+ input.val( "1/1/abc" );
+ ok( !input.calendar( "isValid" ) );
+
+ input.calendar( "destroy" );
+});
+
+})( jQuery );
diff --git a/tests/unit/calendar/calendar_options.js b/tests/unit/calendar/calendar_options.js
new file mode 100644
index 00000000000..d45181e91cd
--- /dev/null
+++ b/tests/unit/calendar/calendar_options.js
@@ -0,0 +1,1273 @@
+(function( $ ) {
+
+module( "calendar: options" );
+
+test( "appendTo", function() {
+ expect( 6 );
+ var container,
+ detached = $( "" ),
+ input = $( "#calendar" );
+
+ input.calendar();
+ container = input.calendar( "widget" ).parent()[ 0 ];
+ equal( container, document.body, "defaults to body" );
+ input.calendar( "destroy" );
+
+ input.calendar({ appendTo: "#qunit-fixture" });
+ container = input.calendar( "widget" ).parent()[ 0 ];
+ equal( container, $( "#qunit-fixture" )[ 0 ], "child of specified element" );
+ input.calendar( "destroy" );
+
+ input.calendar({ appendTo: "#does-not-exist" });
+ container = input.calendar( "widget" ).parent()[ 0 ];
+ equal( container, document.body, "set to body if element does not exist" );
+ input.calendar( "destroy" );
+
+ input.calendar()
+ .calendar( "option", "appendTo", "#qunit-fixture" );
+ container = input.calendar( "widget" ).parent()[ 0 ];
+ equal( container, $( "#qunit-fixture" )[ 0 ], "modified after init" );
+ input.calendar( "destroy" );
+
+ input.calendar({ appendTo: detached });
+ container = input.calendar( "widget" ).parent()[ 0 ];
+ equal( container, detached[ 0 ], "detached jQuery object" );
+ input.calendar( "destroy" );
+
+ input.calendar({ appendTo: detached[ 0 ] });
+ container = input.calendar( "widget" ).parent()[ 0 ];
+ equal( container, detached[ 0 ], "detached DOM element" );
+ input.calendar( "destroy" );
+});
+
+test( "dateFormat", function() {
+ expect( 2 );
+ var input = $( "#calendar" ).val( "1/1/14" ).calendar(),
+ picker = input.calendar( "widget" ),
+ firstDayLink = picker.find( "td[id]:first a" );
+
+ input.calendar( "open" );
+ firstDayLink.trigger( "mousedown" );
+ equal( input.val(), "1/1/14", "default formatting" );
+
+ input.calendar( "option", "dateFormat", { date: "full" } );
+ equal( input.val(), "Wednesday, January 1, 2014", "updated formatting" );
+
+ input.calendar( "destroy" );
+});
+
+test( "eachDay", function() {
+ expect( 5 );
+ var timestamp,
+ input = $( "#calendar" ).calendar(),
+ picker = input.calendar( "widget" ),
+ 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.calendar( "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.calendar( "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.calendar( "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.calendar( "destroy" );
+});
+
+test( "numberOfMonths", function() {
+ expect( 0 );
+});
+
+asyncTest( "position", function() {
+ expect( 3 );
+ var input = $( "
" ).calendar().appendTo( "body" ).css({
+ position: "absolute",
+ top: 0,
+ left: 0
+ }),
+ container = input.calendar( "widget" );
+
+ input.calendar( "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,
+ "calendar directly under input by default" );
+
+ // Change the position option using option()
+ input.calendar( "option", "position", {
+ my: "left top",
+ at: "right bottom"
+ });
+ closeEnough( container.offset().left, input.offset().left + input.outerWidth(), 1,
+ "calendar on right hand side of input after position change" );
+
+ input.remove();
+ start();
+ });
+});
+
+test( "showWeek", function() {
+ expect( 7 );
+ var input = $( "#calendar" ).calendar(),
+ container = input.calendar( "widget" );
+
+ equal( container.find( "thead th" ).length, 7, "just 7 days, no column cell" );
+ equal( container.find( ".ui-calendar-week-col" ).length, 0,
+ "no week column cells present" );
+ input.calendar( "destroy" );
+
+ input = $( "#calendar" ).calendar({ showWeek: true });
+ container = input.calendar( "widget" );
+ equal( container.find( "thead th" ).length, 8, "7 days + a column cell" );
+ 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,
+ container.find( "tr" ).length, "one week cell for each week" );
+ input.calendar( "destroy" );
+
+ input = $( "#calendar" ).calendar();
+ container = input.calendar( "widget" );
+ equal( container.find( "thead th" ).length, 7, "no week column" );
+ input.calendar( "option", "showWeek", true );
+ equal( container.find( "thead th" ).length, 8, "supports changing option after init" );
+});
+
+/*
+test( "setDefaults", function() {
+ expect( 3 );
+ TestHelpers.calendar.init( "#inp" );
+ equal($.calendar._defaults.showOn, "focus", "Initial showOn" );
+ $.calendar.setDefaults({showOn: "button"});
+ equal($.calendar._defaults.showOn, "button", "Change default showOn" );
+ $.calendar.setDefaults({showOn: "focus"});
+ equal($.calendar._defaults.showOn, "focus", "Restore showOn" );
+});
+
+test( "option", function() {
+ expect( 17 );
+ var inp = TestHelpers.calendar.init( "#inp" ),
+ inst = $.data(inp[0], TestHelpers.calendar.PROP_NAME);
+ // Set option
+ equal(inst.settings.showOn, null, "Initial setting showOn" );
+ equal($.calendar._get(inst, "showOn" ), "focus", "Initial instance showOn" );
+ equal($.calendar._defaults.showOn, "focus", "Initial default showOn" );
+ inp.calendar( "option", "showOn", "button" );
+ equal(inst.settings.showOn, "button", "Change setting showOn" );
+ equal($.calendar._get(inst, "showOn" ), "button", "Change instance showOn" );
+ equal($.calendar._defaults.showOn, "focus", "Retain default showOn" );
+ inp.calendar( "option", {showOn: "both"});
+ equal(inst.settings.showOn, "both", "Change setting showOn" );
+ equal($.calendar._get(inst, "showOn" ), "both", "Change instance showOn" );
+ equal($.calendar._defaults.showOn, "focus", "Retain default showOn" );
+ inp.calendar( "option", "showOn", undefined);
+ equal(inst.settings.showOn, null, "Clear setting showOn" );
+ equal($.calendar._get(inst, "showOn" ), "focus", "Restore instance showOn" );
+ equal($.calendar._defaults.showOn, "focus", "Retain default showOn" );
+ // Get option
+ inp = TestHelpers.calendar.init( "#inp" );
+ equal(inp.calendar( "option", "showOn" ), "focus", "Initial setting showOn" );
+ inp.calendar( "option", "showOn", "button" );
+ equal(inp.calendar( "option", "showOn" ), "button", "Change instance showOn" );
+ inp.calendar( "option", "showOn", undefined);
+ equal(inp.calendar( "option", "showOn" ), "focus", "Reset instance showOn" );
+ deepEqual(inp.calendar( "option", "all" ), {showAnim: ""}, "Get instance settings" );
+ deepEqual(inp.calendar( "option", "defaults" ), $.calendar._defaults,
+ "Get default settings" );
+});
+
+test( "disabled", function() {
+ expect(8);
+ var inp = TestHelpers.calendar.init( "#inp" );
+ ok(!inp.calendar( "isDisabled" ), "Initially marked as enabled" );
+ ok(!inp[0].disabled, "Field initially enabled" );
+ inp.calendar( "option", "disabled", true);
+ ok(inp.calendar( "isDisabled" ), "Marked as disabled" );
+ ok(inp[0].disabled, "Field now disabled" );
+ inp.calendar( "option", "disabled", false);
+ ok(!inp.calendar( "isDisabled" ), "Marked as enabled" );
+ ok(!inp[0].disabled, "Field now enabled" );
+ inp.calendar( "destroy" );
+
+ inp = TestHelpers.calendar.init( "#inp", { disabled: true });
+ ok(inp.calendar( "isDisabled" ), "Initially marked as disabled" );
+ ok(inp[0].disabled, "Field initially disabled" );
+});
+
+test( "change", function() {
+ expect( 12 );
+ var inp = TestHelpers.calendar.init( "#inp" ),
+ inst = $.data(inp[0], TestHelpers.calendar.PROP_NAME);
+ equal(inst.settings.showOn, null, "Initial setting showOn" );
+ equal($.calendar._get(inst, "showOn" ), "focus", "Initial instance showOn" );
+ equal($.calendar._defaults.showOn, "focus", "Initial default showOn" );
+ inp.calendar( "change", "showOn", "button" );
+ equal(inst.settings.showOn, "button", "Change setting showOn" );
+ equal($.calendar._get(inst, "showOn" ), "button", "Change instance showOn" );
+ equal($.calendar._defaults.showOn, "focus", "Retain default showOn" );
+ inp.calendar( "change", {showOn: "both"});
+ equal(inst.settings.showOn, "both", "Change setting showOn" );
+ equal($.calendar._get(inst, "showOn" ), "both", "Change instance showOn" );
+ equal($.calendar._defaults.showOn, "focus", "Retain default showOn" );
+ inp.calendar( "change", "showOn", undefined);
+ equal(inst.settings.showOn, null, "Clear setting showOn" );
+ equal($.calendar._get(inst, "showOn" ), "focus", "Restore instance showOn" );
+ equal($.calendar._defaults.showOn, "focus", "Retain default showOn" );
+});
+
+(function() {
+ var url = window.location.search;
+ url = decodeURIComponent( url.slice( url.indexOf( "swarmURL=" ) + 9 ) );
+
+ // TODO: This test occassionally fails in IE in TestSwarm
+ if ( $.ui.ie && url && url.indexOf( "http" ) === 0 ) {
+ return;
+ }
+
+ asyncTest( "invocation", function() {
+ var button, image,
+ isOldIE = $.ui.ie && ( !document.documentMode || document.documentMode < 9 ),
+ body = $( "body" );
+
+ expect( isOldIE ? 25 : 29 );
+
+ function step0() {
+ var inp = TestHelpers.calendar.initNewInput(),
+ dp = $( "#ui-calendar-div" );
+
+ button = inp.siblings( "button" );
+ ok( button.length === 0, "Focus - button absent" );
+ image = inp.siblings( "img" );
+ ok( image.length === 0, "Focus - image absent" );
+
+ TestHelpers.calendar.onFocus( inp, function() {
+ ok( dp.is( ":visible" ), "Focus - rendered on focus" );
+ inp.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
+ ok( !dp.is( ":visible" ), "Focus - hidden on exit" );
+ step1();
+ });
+ }
+
+ function step1() {
+
+ var inp = TestHelpers.calendar.initNewInput(),
+ dp = $( "#ui-calendar-div" );
+
+ TestHelpers.calendar.onFocus( inp, function() {
+ ok( dp.is( ":visible" ), "Focus - rendered on focus" );
+ body.simulate( "mousedown", {} );
+ ok( !dp.is( ":visible" ), "Focus - hidden on external click" );
+ inp.calendar( "hide" ).calendar( "destroy" );
+
+ step2();
+ });
+ }
+
+ function step2() {
+ var inp = TestHelpers.calendar.initNewInput({
+ showOn: "button",
+ buttonText: "Popup"
+ }),
+ dp = $( "#ui-calendar-div" );
+
+ ok( !dp.is( ":visible" ), "Button - initially hidden" );
+ button = inp.siblings( "button" );
+ image = inp.siblings( "img" );
+ ok( button.length === 1, "Button - button present" );
+ ok( image.length === 0, "Button - image absent" );
+ equal( button.text(), "Popup", "Button - button text" );
+
+ TestHelpers.calendar.onFocus( inp, function() {
+ ok( !dp.is( ":visible" ), "Button - not rendered on focus" );
+ button.click();
+ ok( dp.is( ":visible" ), "Button - rendered on button click" );
+ button.click();
+ ok( !dp.is( ":visible" ), "Button - hidden on second button click" );
+ inp.calendar( "hide" ).calendar( "destroy" );
+
+ step3();
+ });
+ }
+
+ function step3() {
+ var inp = TestHelpers.calendar.initNewInput({
+ showOn: "button",
+ buttonImageOnly: true,
+ buttonImage: "images/calendar.gif",
+ buttonText: "Cal"
+ }),
+ dp = $( "#ui-calendar-div" );
+
+ ok( !dp.is( ":visible" ), "Image button - initially hidden" );
+ button = inp.siblings( "button" );
+ ok( button.length === 0, "Image button - button absent" );
+ image = inp.siblings( "img" );
+ ok( image.length === 1, "Image button - image present" );
+ ok( /images\/calendar\.gif$/.test( image.attr( "src" ) ), "Image button - image source" );
+ equal( image.attr( "title" ), "Cal", "Image button - image text" );
+
+ TestHelpers.calendar.onFocus( inp, function() {
+ ok( !dp.is( ":visible" ), "Image button - not rendered on focus" );
+ image.click();
+ ok( dp.is( ":visible" ), "Image button - rendered on image click" );
+ image.click();
+ ok( !dp.is( ":visible" ), "Image button - hidden on second image click" );
+ inp.calendar( "hide" ).calendar( "destroy" );
+
+ step4();
+ });
+ }
+
+ function step4() {
+ var inp = TestHelpers.calendar.initNewInput({
+ showOn: "both",
+ buttonImage: "images/calendar.gif"
+ }),
+ dp = $( "#ui-calendar-div" );
+
+ ok( !dp.is( ":visible" ), "Both - initially hidden" );
+ button = inp.siblings( "button" );
+ ok( button.length === 1, "Both - button present" );
+ image = inp.siblings( "img" );
+ ok( image.length === 0, "Both - image absent" );
+ image = button.children( "img" );
+ ok( image.length === 1, "Both - button image present" );
+
+ // TODO: This test occasionally fails to focus in IE8 in BrowserStack
+ if ( !isOldIE ) {
+ TestHelpers.calendar.onFocus( inp, function() {
+ ok( dp.is( ":visible" ), "Both - rendered on focus" );
+ body.simulate( "mousedown", {} );
+ ok( !dp.is( ":visible" ), "Both - hidden on external click" );
+ button.click();
+ ok( dp.is( ":visible" ), "Both - rendered on button click" );
+ button.click();
+ ok( !dp.is( ":visible" ), "Both - hidden on second button click" );
+ inp.calendar( "hide" ).calendar( "destroy" );
+
+ start();
+ });
+ } else {
+ start();
+ }
+ }
+
+ step0();
+ });
+})();
+
+test( "otherMonths", function() {
+ expect( 8 );
+ var inp = TestHelpers.calendar.init( "#inp" ),
+ pop = $( "#ui-calendar-div" );
+ inp.val( "06/01/2009" ).calendar( "show" );
+ equal(pop.find( "tbody" ).text(),
+ // support: IE <9, jQuery <1.8
+ // In IE7/8 with jQuery <1.8, encoded spaces behave in strange ways
+ $( "
\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0 " ).text(),
+ "Other months - none" );
+ ok(pop.find( "td:last *" ).length === 0, "Other months - no content" );
+ inp.calendar( "hide" ).calendar( "option", "showOtherMonths", true).calendar( "show" );
+ equal(pop.find( "tbody" ).text(), "311234567891011121314151617181920212223242526272829301234",
+ "Other months - show" );
+ ok(pop.find( "td:last span" ).length === 1, "Other months - span content" );
+ inp.calendar( "hide" ).calendar( "option", "selectOtherMonths", true).calendar( "show" );
+ equal(pop.find( "tbody" ).text(), "311234567891011121314151617181920212223242526272829301234",
+ "Other months - select" );
+ ok(pop.find( "td:last a" ).length === 1, "Other months - link content" );
+ inp.calendar( "hide" ).calendar( "option", "showOtherMonths", false).calendar( "show" );
+ equal(pop.find( "tbody" ).text(),
+ // support: IE <9, jQuery <1.8
+ // In IE7/8 with jQuery <1.8, encoded spaces behave in strange ways
+ $( "
\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0 " ).text(),
+ "Other months - none" );
+ ok(pop.find( "td:last *" ).length === 0, "Other months - no content" );
+});
+
+test( "defaultDate", function() {
+ expect( 16 );
+ var inp = TestHelpers.calendar.init( "#inp" ),
+ date = new Date();
+ inp.val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date null" );
+
+ // Numeric values
+ inp.calendar( "option", {defaultDate: -2}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date.setDate(date.getDate() - 2);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date -2" );
+
+ date = new Date();
+ inp.calendar( "option", {defaultDate: 3}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date.setDate(date.getDate() + 3);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date 3" );
+
+ date = new Date();
+ inp.calendar( "option", {defaultDate: 1 / "a"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date NaN" );
+
+ // String offset values
+ inp.calendar( "option", {defaultDate: "-1d"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date.setDate(date.getDate() - 1);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date -1d" );
+ inp.calendar( "option", {defaultDate: "+3D"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date.setDate(date.getDate() + 4);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date +3D" );
+ inp.calendar( "option", {defaultDate: " -2 w "}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date = new Date();
+ date.setDate(date.getDate() - 14);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date -2 w" );
+ inp.calendar( "option", {defaultDate: "+1 W"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date.setDate(date.getDate() + 21);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date +1 W" );
+ inp.calendar( "option", {defaultDate: " -1 m "}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date = TestHelpers.calendar.addMonths(new Date(), -1);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date -1 m" );
+ inp.calendar( "option", {defaultDate: "+2M"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date = TestHelpers.calendar.addMonths(new Date(), 2);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date +2M" );
+ inp.calendar( "option", {defaultDate: "-2y"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date = new Date();
+ date.setFullYear(date.getFullYear() - 2);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date -2y" );
+ inp.calendar( "option", {defaultDate: "+1 Y "}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date.setFullYear(date.getFullYear() + 3);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date +1 Y" );
+ inp.calendar( "option", {defaultDate: "+1M +10d"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date = TestHelpers.calendar.addMonths(new Date(), 1);
+ date.setDate(date.getDate() + 10);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date +1M +10d" );
+ // String date values
+ inp.calendar( "option", {defaultDate: "07/04/2007"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date = new Date(2007, 7 - 1, 4);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date 07/04/2007" );
+ inp.calendar( "option", {dateFormat: "yy-mm-dd", defaultDate: "2007-04-02"}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date = new Date(2007, 4 - 1, 2);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date 2007-04-02" );
+ // Date value
+ date = new Date(2007, 1 - 1, 26);
+ inp.calendar( "option", {dateFormat: "mm/dd/yy", defaultDate: date}).
+ calendar( "hide" ).val( "" ).calendar( "show" ).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date, "Default date 01/26/2007" );
+});
+
+test( "miscellaneous", function() {
+ expect( 19 );
+ var curYear, longNames, shortNames, date,
+ dp = $( "#ui-calendar-div" ),
+ inp = TestHelpers.calendar.init( "#inp" );
+ // Year range
+ function genRange(start, offset) {
+ var i = start,
+ range = "";
+ for (; i < start + offset; i++) {
+ range += i;
+ }
+ return range;
+ }
+ curYear = new Date().getFullYear();
+ inp.val( "02/04/2008" ).calendar( "show" );
+ equal(dp.find( ".ui-calendar-year" ).text(), "2008", "Year range - read-only default" );
+ inp.calendar( "hide" ).calendar( "option", {changeYear: true}).calendar( "show" );
+ equal(dp.find( ".ui-calendar-year" ).text(), genRange(2008 - 10, 21), "Year range - changeable default" );
+ inp.calendar( "hide" ).calendar( "option", {yearRange: "c-6:c+2", changeYear: true}).calendar( "show" );
+ equal(dp.find( ".ui-calendar-year" ).text(), genRange(2008 - 6, 9), "Year range - c-6:c+2" );
+ inp.calendar( "hide" ).calendar( "option", {yearRange: "2000:2010", changeYear: true}).calendar( "show" );
+ equal(dp.find( ".ui-calendar-year" ).text(), genRange(2000, 11), "Year range - 2000:2010" );
+ inp.calendar( "hide" ).calendar( "option", {yearRange: "-5:+3", changeYear: true}).calendar( "show" );
+ equal(dp.find( ".ui-calendar-year" ).text(), genRange(curYear - 5, 9), "Year range - -5:+3" );
+ inp.calendar( "hide" ).calendar( "option", {yearRange: "2000:-5", changeYear: true}).calendar( "show" );
+ equal(dp.find( ".ui-calendar-year" ).text(), genRange(2000, curYear - 2004), "Year range - 2000:-5" );
+ inp.calendar( "hide" ).calendar( "option", {yearRange: "", changeYear: true}).calendar( "show" );
+ equal(dp.find( ".ui-calendar-year" ).text(), genRange(curYear, 1), "Year range - -6:+2" );
+
+ // Navigation as date format
+ inp.calendar( "option", {showButtonPanel: true});
+ equal(dp.find( ".ui-calendar-prev" ).text(), "Prev", "Navigation prev - default" );
+ equal(dp.find( ".ui-calendar-current" ).text(), "Today", "Navigation current - default" );
+ equal(dp.find( ".ui-calendar-next" ).text(), "Next", "Navigation next - default" );
+ inp.calendar( "hide" ).calendar( "option", {navigationAsDateFormat: true, prevText: "< M", currentText: "MM", nextText: "M >"}).
+ val( "02/04/2008" ).calendar( "show" );
+ longNames = $.calendar.regional[""].monthNames;
+ shortNames = $.calendar.regional[""].monthNamesShort;
+ date = new Date();
+ equal(dp.find( ".ui-calendar-prev" ).text(), "< " + shortNames[0], "Navigation prev - as date format" );
+ equal(dp.find( ".ui-calendar-current" ).text(),
+ longNames[date.getMonth()], "Navigation current - as date format" );
+ equal(dp.find( ".ui-calendar-next" ).text(),
+ shortNames[2] + " >", "Navigation next - as date format" );
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN});
+ equal(dp.find( ".ui-calendar-prev" ).text(),
+ "< " + shortNames[1], "Navigation prev - as date format + pgdn" );
+ equal(dp.find( ".ui-calendar-current" ).text(),
+ longNames[date.getMonth()], "Navigation current - as date format + pgdn" );
+ equal(dp.find( ".ui-calendar-next" ).text(),
+ shortNames[3] + " >", "Navigation next - as date format + pgdn" );
+ inp.calendar( "hide" ).calendar( "option", {gotoCurrent: true}).
+ val( "02/04/2008" ).calendar( "show" );
+ equal(dp.find( ".ui-calendar-prev" ).text(),
+ "< " + shortNames[0], "Navigation prev - as date format + goto current" );
+ equal(dp.find( ".ui-calendar-current" ).text(),
+ longNames[1], "Navigation current - as date format + goto current" );
+ equal(dp.find( ".ui-calendar-next" ).text(),
+ shortNames[2] + " >", "Navigation next - as date format + goto current" );
+});
+
+test( "minMax", function() {
+ expect( 23 );
+ var date,
+ inp = TestHelpers.calendar.init( "#inp" ),
+ dp = $( "#ui-calendar-div" ),
+ lastYear = new Date(2007, 6 - 1, 4),
+ nextYear = new Date(2009, 6 - 1, 4),
+ minDate = new Date(2008, 2 - 1, 29),
+ maxDate = new Date(2008, 12 - 1, 7);
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), lastYear,
+ "Min/max - null, null - ctrl+pgup" );
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), nextYear,
+ "Min/max - null, null - ctrl+pgdn" );
+ inp.calendar( "option", {minDate: minDate}).
+ calendar( "hide" ).val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), minDate,
+ "Min/max - 02/29/2008, null - ctrl+pgup" );
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), nextYear,
+ "Min/max - 02/29/2008, null - ctrl+pgdn" );
+ inp.calendar( "option", {maxDate: maxDate}).
+ calendar( "hide" ).val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), minDate,
+ "Min/max - 02/29/2008, 12/07/2008 - ctrl+pgup" );
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), maxDate,
+ "Min/max - 02/29/2008, 12/07/2008 - ctrl+pgdn" );
+ inp.calendar( "option", {minDate: null}).
+ calendar( "hide" ).val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), lastYear,
+ "Min/max - null, 12/07/2008 - ctrl+pgup" );
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), maxDate,
+ "Min/max - null, 12/07/2008 - ctrl+pgdn" );
+ // Relative dates
+ date = new Date();
+ date.setDate(date.getDate() - 7);
+ inp.calendar( "option", {minDate: "-1w", maxDate: "+1 M +10 D "}).
+ calendar( "hide" ).val( "" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date,
+ "Min/max - -1w, +1 M +10 D - ctrl+pgup" );
+ date = TestHelpers.calendar.addMonths(new Date(), 1);
+ date.setDate(date.getDate() + 10);
+ inp.val( "" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.PAGE_DOWN}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date,
+ "Min/max - -1w, +1 M +10 D - ctrl+pgdn" );
+ // With existing date
+ inp = TestHelpers.calendar.init( "#inp" );
+ inp.val( "06/04/2008" ).calendar( "option", {minDate: minDate});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), new Date(2008, 6 - 1, 4), "Min/max - setDate > min" );
+ inp.calendar( "option", {minDate: null}).val( "01/04/2008" ).calendar( "option", {minDate: minDate});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), minDate, "Min/max - setDate < min" );
+ inp.calendar( "option", {minDate: null}).val( "06/04/2008" ).calendar( "option", {maxDate: maxDate});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), new Date(2008, 6 - 1, 4), "Min/max - setDate < max" );
+ inp.calendar( "option", {maxDate: null}).val( "01/04/2009" ).calendar( "option", {maxDate: maxDate});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), maxDate, "Min/max - setDate > max" );
+ inp.calendar( "option", {maxDate: null}).val( "01/04/2008" ).calendar( "option", {minDate: minDate, maxDate: maxDate});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), minDate, "Min/max - setDate < min" );
+ inp.calendar( "option", {maxDate: null}).val( "06/04/2008" ).calendar( "option", {minDate: minDate, maxDate: maxDate});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), new Date(2008, 6 - 1, 4), "Min/max - setDate > min, < max" );
+ inp.calendar( "option", {maxDate: null}).val( "01/04/2009" ).calendar( "option", {minDate: minDate, maxDate: maxDate});
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), maxDate, "Min/max - setDate > max" );
+
+ inp.calendar( "option", {yearRange: "-0:+1"}).val( "01/01/" + new Date().getFullYear());
+ ok(dp.find( ".ui-calendar-prev" ).hasClass( "ui-state-disabled" ), "Year Range Test - previous button disabled at 1/1/minYear" );
+ inp.calendar( "setDate", "12/30/" + new Date().getFullYear());
+ ok(dp.find( ".ui-calendar-next" ).hasClass( "ui-state-disabled" ), "Year Range Test - next button disabled at 12/30/maxYear" );
+
+ inp.calendar( "option", {
+ minDate: new Date(1900, 0, 1),
+ maxDate: "-6Y",
+ yearRange: "1900:-6"
+ }).val( "" );
+ ok(dp.find( ".ui-calendar-next" ).hasClass( "ui-state-disabled" ), "Year Range Test - next button disabled" );
+ ok(!dp.find( ".ui-calendar-prev" ).hasClass( "ui-state-disabled" ), "Year Range Test - prev button enabled" );
+
+ inp.calendar( "option", {
+ minDate: new Date(1900, 0, 1),
+ maxDate: "1/25/2007",
+ yearRange: "1900:2007"
+ }).val( "" );
+ ok(dp.find( ".ui-calendar-next" ).hasClass( "ui-state-disabled" ), "Year Range Test - next button disabled" );
+ ok(!dp.find( ".ui-calendar-prev" ).hasClass( "ui-state-disabled" ), "Year Range Test - prev button enabled" );
+});
+
+test( "setDate", function() {
+ expect( 24 );
+ var inl, alt, minDate, maxDate, dateAndTimeToSet, dateAndTimeClone,
+ inp = TestHelpers.calendar.init( "#inp" ),
+ date1 = new Date(2008, 6 - 1, 4),
+ date2 = new Date();
+ ok(inp.calendar( "getDate" ) == null, "Set date - default" );
+ inp.calendar( "setDate", date1);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date1, "Set date - 2008-06-04" );
+ date1 = new Date();
+ date1.setDate(date1.getDate() + 7);
+ inp.calendar( "setDate", +7);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date1, "Set date - +7" );
+ date2.setFullYear(date2.getFullYear() + 2);
+ inp.calendar( "setDate", "+2y" );
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date2, "Set date - +2y" );
+ inp.calendar( "setDate", date1, date2);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date1, "Set date - two dates" );
+ inp.calendar( "setDate" );
+ ok(inp.calendar( "getDate" ) == null, "Set date - null" );
+ // Relative to current date
+ date1 = new Date();
+ date1.setDate(date1.getDate() + 7);
+ inp.calendar( "setDate", "c +7" );
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date1, "Set date - c +7" );
+ date1.setDate(date1.getDate() + 7);
+ inp.calendar( "setDate", "c+7" );
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date1, "Set date - c+7" );
+ date1.setDate(date1.getDate() - 21);
+ inp.calendar( "setDate", "c -3 w" );
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date1, "Set date - c -3 w" );
+ // Inline
+ inl = TestHelpers.calendar.init( "#inl" );
+ date1 = new Date(2008, 6 - 1, 4);
+ date2 = new Date();
+ TestHelpers.calendar.equalsDate(inl.calendar( "getDate" ), date2, "Set date inline - default" );
+ inl.calendar( "setDate", date1);
+ TestHelpers.calendar.equalsDate(inl.calendar( "getDate" ), date1, "Set date inline - 2008-06-04" );
+ date1 = new Date();
+ date1.setDate(date1.getDate() + 7);
+ inl.calendar( "setDate", +7);
+ TestHelpers.calendar.equalsDate(inl.calendar( "getDate" ), date1, "Set date inline - +7" );
+ date2.setFullYear(date2.getFullYear() + 2);
+ inl.calendar( "setDate", "+2y" );
+ TestHelpers.calendar.equalsDate(inl.calendar( "getDate" ), date2, "Set date inline - +2y" );
+ inl.calendar( "setDate", date1, date2);
+ TestHelpers.calendar.equalsDate(inl.calendar( "getDate" ), date1, "Set date inline - two dates" );
+ inl.calendar( "setDate" );
+ ok(inl.calendar( "getDate" ) == null, "Set date inline - null" );
+ // Alternate field
+ alt = $( "#alt" );
+ inp.calendar( "option", {altField: "#alt", altFormat: "yy-mm-dd"});
+ date1 = new Date(2008, 6 - 1, 4);
+ inp.calendar( "setDate", date1);
+ equal(inp.val(), "06/04/2008", "Set date alternate - 06/04/2008" );
+ equal(alt.val(), "2008-06-04", "Set date alternate - 2008-06-04" );
+ // With minimum/maximum
+ inp = TestHelpers.calendar.init( "#inp" );
+ date1 = new Date(2008, 1 - 1, 4);
+ date2 = new Date(2008, 6 - 1, 4);
+ minDate = new Date(2008, 2 - 1, 29);
+ maxDate = new Date(2008, 3 - 1, 28);
+ inp.val( "" ).calendar( "option", {minDate: minDate}).calendar( "setDate", date2);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date2, "Set date min/max - setDate > min" );
+ inp.calendar( "setDate", date1);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), minDate, "Set date min/max - setDate < min" );
+ inp.val( "" ).calendar( "option", {maxDate: maxDate, minDate: null}).calendar( "setDate", date1);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), date1, "Set date min/max - setDate < max" );
+ inp.calendar( "setDate", date2);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), maxDate, "Set date min/max - setDate > max" );
+ inp.val( "" ).calendar( "option", {minDate: minDate}).calendar( "setDate", date1);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), minDate, "Set date min/max - setDate < min" );
+ inp.calendar( "setDate", date2);
+ TestHelpers.calendar.equalsDate(inp.calendar( "getDate" ), maxDate, "Set date min/max - setDate > max" );
+ dateAndTimeToSet = new Date(2008, 3 - 1, 28, 1, 11, 0);
+ dateAndTimeClone = new Date(2008, 3 - 1, 28, 1, 11, 0);
+ inp.calendar( "setDate", dateAndTimeToSet);
+ equal(dateAndTimeToSet.getTime(), dateAndTimeClone.getTime(), "Date object passed should not be changed by setDate" );
+});
+
+test( "altField", function() {
+ expect( 10 );
+ var inp = TestHelpers.calendar.init( "#inp" ),
+ alt = $( "#alt" );
+ // No alternate field set
+ alt.val( "" );
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ equal(inp.val(), "06/04/2008", "Alt field - dp - enter" );
+ equal(alt.val(), "", "Alt field - alt not set" );
+ // Alternate field set
+ alt.val( "" );
+ inp.calendar( "option", {altField: "#alt", altFormat: "yy-mm-dd"}).
+ val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ equal(inp.val(), "06/04/2008", "Alt field - dp - enter" );
+ equal(alt.val(), "2008-06-04", "Alt field - alt - enter" );
+ // Move from initial date
+ alt.val( "" );
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ equal(inp.val(), "07/04/2008", "Alt field - dp - pgdn" );
+ equal(alt.val(), "2008-07-04", "Alt field - alt - pgdn" );
+ // Alternate field set - closed
+ alt.val( "" );
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.PAGE_DOWN}).
+ simulate( "keydown", {keyCode: $.ui.keyCode.ESCAPE});
+ equal(inp.val(), "06/04/2008", "Alt field - dp - pgdn/esc" );
+ equal(alt.val(), "", "Alt field - alt - pgdn/esc" );
+ // Clear date and alternate
+ alt.val( "" );
+ inp.val( "06/04/2008" ).calendar( "show" );
+ inp.simulate( "keydown", {ctrlKey: true, keyCode: $.ui.keyCode.END});
+ equal(inp.val(), "", "Alt field - dp - ctrl+end" );
+ equal(alt.val(), "", "Alt field - alt - ctrl+end" );
+});
+
+test( "autoSize", function() {
+ expect( 15 );
+ var inp = TestHelpers.calendar.init( "#inp" );
+ equal(inp.prop( "size" ), 20, "Auto size - default" );
+ inp.calendar( "option", "autoSize", true);
+ equal(inp.prop( "size" ), 10, "Auto size - mm/dd/yy" );
+ inp.calendar( "option", "dateFormat", "m/d/yy" );
+ equal(inp.prop( "size" ), 10, "Auto size - m/d/yy" );
+ inp.calendar( "option", "dateFormat", "D M d yy" );
+ equal(inp.prop( "size" ), 15, "Auto size - D M d yy" );
+ inp.calendar( "option", "dateFormat", "DD, MM dd, yy" );
+ equal(inp.prop( "size" ), 29, "Auto size - DD, MM dd, yy" );
+
+ // French
+ inp.calendar( "option", $.extend({autoSize: false}, $.calendar.regional.fr));
+ equal(inp.prop( "size" ), 29, "Auto size - fr - default" );
+ inp.calendar( "option", "autoSize", true);
+ equal(inp.prop( "size" ), 10, "Auto size - fr - dd/mm/yy" );
+ inp.calendar( "option", "dateFormat", "m/d/yy" );
+ equal(inp.prop( "size" ), 10, "Auto size - fr - m/d/yy" );
+ inp.calendar( "option", "dateFormat", "D M d yy" );
+ equal(inp.prop( "size" ), 18, "Auto size - fr - D M d yy" );
+ inp.calendar( "option", "dateFormat", "DD, MM dd, yy" );
+ equal(inp.prop( "size" ), 28, "Auto size - fr - DD, MM dd, yy" );
+
+ // Hebrew
+ inp.calendar( "option", $.extend({autoSize: false}, $.calendar.regional.he));
+ equal(inp.prop( "size" ), 28, "Auto size - he - default" );
+ inp.calendar( "option", "autoSize", true);
+ equal(inp.prop( "size" ), 10, "Auto size - he - dd/mm/yy" );
+ inp.calendar( "option", "dateFormat", "m/d/yy" );
+ equal(inp.prop( "size" ), 10, "Auto size - he - m/d/yy" );
+ inp.calendar( "option", "dateFormat", "D M d yy" );
+ equal(inp.prop( "size" ), 16, "Auto size - he - D M d yy" );
+ inp.calendar( "option", "dateFormat", "DD, MM dd, yy" );
+ equal(inp.prop( "size" ), 23, "Auto size - he - DD, MM dd, yy" );
+});
+
+test( "daylightSaving", function() {
+ expect( 25 );
+ var inp = TestHelpers.calendar.init( "#inp" ),
+ dp = $( "#ui-calendar-div" );
+ ok(true, "Daylight saving - " + new Date());
+ // Australia, Sydney - AM change, southern hemisphere
+ inp.val( "04/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(6) a", dp).simulate( "click" );
+ equal(inp.val(), "04/05/2008", "Daylight saving - Australia 04/05/2008" );
+ inp.val( "04/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(7) a", dp).simulate( "click" );
+ equal(inp.val(), "04/06/2008", "Daylight saving - Australia 04/06/2008" );
+ inp.val( "04/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(8) a", dp).simulate( "click" );
+ equal(inp.val(), "04/07/2008", "Daylight saving - Australia 04/07/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(6) a", dp).simulate( "click" );
+ equal(inp.val(), "10/04/2008", "Daylight saving - Australia 10/04/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(7) a", dp).simulate( "click" );
+ equal(inp.val(), "10/05/2008", "Daylight saving - Australia 10/05/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(8) a", dp).simulate( "click" );
+ equal(inp.val(), "10/06/2008", "Daylight saving - Australia 10/06/2008" );
+ // Brasil, Brasilia - midnight change, southern hemisphere
+ inp.val( "02/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(20) a", dp).simulate( "click" );
+ equal(inp.val(), "02/16/2008", "Daylight saving - Brasil 02/16/2008" );
+ inp.val( "02/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(21) a", dp).simulate( "click" );
+ equal(inp.val(), "02/17/2008", "Daylight saving - Brasil 02/17/2008" );
+ inp.val( "02/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(22) a", dp).simulate( "click" );
+ equal(inp.val(), "02/18/2008", "Daylight saving - Brasil 02/18/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(13) a", dp).simulate( "click" );
+ equal(inp.val(), "10/11/2008", "Daylight saving - Brasil 10/11/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(14) a", dp).simulate( "click" );
+ equal(inp.val(), "10/12/2008", "Daylight saving - Brasil 10/12/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(15) a", dp).simulate( "click" );
+ equal(inp.val(), "10/13/2008", "Daylight saving - Brasil 10/13/2008" );
+ // Lebanon, Beirut - midnight change, northern hemisphere
+ inp.val( "03/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(34) a", dp).simulate( "click" );
+ equal(inp.val(), "03/29/2008", "Daylight saving - Lebanon 03/29/2008" );
+ inp.val( "03/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(35) a", dp).simulate( "click" );
+ equal(inp.val(), "03/30/2008", "Daylight saving - Lebanon 03/30/2008" );
+ inp.val( "03/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(36) a", dp).simulate( "click" );
+ equal(inp.val(), "03/31/2008", "Daylight saving - Lebanon 03/31/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(27) a", dp).simulate( "click" );
+ equal(inp.val(), "10/25/2008", "Daylight saving - Lebanon 10/25/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(28) a", dp).simulate( "click" );
+ equal(inp.val(), "10/26/2008", "Daylight saving - Lebanon 10/26/2008" );
+ inp.val( "10/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(29) a", dp).simulate( "click" );
+ equal(inp.val(), "10/27/2008", "Daylight saving - Lebanon 10/27/2008" );
+ // US, Eastern - AM change, northern hemisphere
+ inp.val( "03/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(13) a", dp).simulate( "click" );
+ equal(inp.val(), "03/08/2008", "Daylight saving - US 03/08/2008" );
+ inp.val( "03/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(14) a", dp).simulate( "click" );
+ equal(inp.val(), "03/09/2008", "Daylight saving - US 03/09/2008" );
+ inp.val( "03/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(15) a", dp).simulate( "click" );
+ equal(inp.val(), "03/10/2008", "Daylight saving - US 03/10/2008" );
+ inp.val( "11/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(6) a", dp).simulate( "click" );
+ equal(inp.val(), "11/01/2008", "Daylight saving - US 11/01/2008" );
+ inp.val( "11/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(7) a", dp).simulate( "click" );
+ equal(inp.val(), "11/02/2008", "Daylight saving - US 11/02/2008" );
+ inp.val( "11/01/2008" ).calendar( "show" );
+ $( ".ui-calendar-calendar td:eq(8) a", dp).simulate( "click" );
+ equal(inp.val(), "11/03/2008", "Daylight saving - US 11/03/2008" );
+});
+
+var beforeShowThis = null,
+ beforeShowInput = null,
+ beforeShowInst = null,
+ beforeShowDayThis = null,
+ beforeShowDayOK = true;
+
+
+function beforeAll(input, inst) {
+ beforeShowThis = this;
+ beforeShowInput = input;
+ beforeShowInst = inst;
+ return {currentText: "Current"};
+}
+
+function beforeDay(date) {
+ beforeShowDayThis = this;
+ beforeShowDayOK &= (date > new Date(2008, 1 - 1, 26) &&
+ date < new Date(2008, 3 - 1, 6));
+ return [(date.getDate() % 2 === 0), (date.getDate() % 10 === 0 ? "day10" : "" ),
+ (date.getDate() % 3 === 0 ? "Divisble by 3" : "" )];
+}
+
+test( "callbacks", function() {
+ expect( 13 );
+ // Before show
+ var dp, day20, day21,
+ inp = TestHelpers.calendar.init( "#inp", {beforeShow: beforeAll}),
+ inst = $.data(inp[0], "calendar" );
+ equal($.calendar._get(inst, "currentText" ), "Today", "Before show - initial" );
+ inp.val( "02/04/2008" ).calendar( "show" );
+ equal($.calendar._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" );
+ deepEqual(beforeShowInst, inst, "Before show - inst OK" );
+ inp.calendar( "hide" ).calendar( "destroy" );
+ // Before show day
+ inp = TestHelpers.calendar.init( "#inp", {beforeShowDay: beforeDay});
+ dp = $( "#ui-calendar-div" );
+ inp.val( "02/04/2008" ).calendar( "show" );
+ ok(beforeShowDayThis.id === inp[0].id, "Before show day - this OK" );
+ ok(beforeShowDayOK, "Before show day - dates OK" );
+ day20 = dp.find( ".ui-calendar-calendar td:contains('20')" );
+ day21 = dp.find( ".ui-calendar-calendar td:contains('21')" );
+ ok(!day20.is( ".ui-calendar-unselectable" ), "Before show day - unselectable 20" );
+ ok(day21.is( ".ui-calendar-unselectable" ), "Before show day - unselectable 21" );
+ ok(day20.is( ".day10" ), "Before show day - CSS 20" );
+ ok(!day21.is( ".day10" ), "Before show day - CSS 21" );
+ ok(!day20.attr( "title" ), "Before show day - title 20" );
+ ok(day21.attr( "title" ) === "Divisble by 3", "Before show day - title 21" );
+ inp.calendar( "hide" ).calendar( "destroy" );
+});
+
+test( "beforeShowDay - tooltips with quotes", function() {
+ expect( 1 );
+ var inp, dp;
+ inp = TestHelpers.calendar.init( "#inp", {
+ beforeShowDay: function() {
+ return [ true, "", "'" ];
+ }
+ });
+ dp = $( "#ui-calendar-div" );
+
+ inp.calendar( "show" );
+ equal( dp.find( ".ui-calendar-calendar td:contains('9')" ).attr( "title" ), "'" );
+ inp.calendar( "hide" ).calendar( "destroy" );
+});
+
+test( "localisation", function() {
+ expect( 24 );
+ var dp, month, day, date,
+ inp = TestHelpers.calendar.init( "#inp", $.calendar.regional.fr);
+ inp.calendar( "option", {dateFormat: "DD, d MM yy", showButtonPanel:true, changeMonth:true, changeYear:true}).val( "" ).calendar( "show" );
+ dp = $( "#ui-calendar-div" );
+ equal($( ".ui-calendar-close", dp).text(), "Fermer", "Localisation - close" );
+ $( ".ui-calendar-close", dp).simulate( "mouseover" );
+ equal($( ".ui-calendar-prev", dp).text(), "Précédent", "Localisation - previous" );
+ equal($( ".ui-calendar-current", dp).text(), "Aujourd'hui", "Localisation - current" );
+ equal($( ".ui-calendar-next", dp).text(), "Suivant", "Localisation - next" );
+ month = 0;
+ $( ".ui-calendar-month option", dp).each(function() {
+ equal($(this).text(), $.calendar.regional.fr.monthNamesShort[month],
+ "Localisation - month " + month);
+ month++;
+ });
+ day = 1;
+ $( ".ui-calendar-calendar th", dp).each(function() {
+ equal($(this).text(), $.calendar.regional.fr.dayNamesMin[day],
+ "Localisation - day " + day);
+ day = (day + 1) % 7;
+ });
+ inp.simulate( "keydown", {keyCode: $.ui.keyCode.ENTER});
+ date = new Date();
+ equal(inp.val(), $.calendar.regional.fr.dayNames[date.getDay()] + ", " +
+ date.getDate() + " " + $.calendar.regional.fr.monthNames[date.getMonth()] +
+ " " + date.getFullYear(), "Localisation - formatting" );
+});
+
+test( "noWeekends", function() {
+ expect( 31 );
+ var i, date;
+ for (i = 1; i <= 31; i++) {
+ date = new Date(2001, 1 - 1, i);
+ deepEqual($.calendar.noWeekends(date), [(i + 1) % 7 >= 2, ""],
+ "No weekends " + date);
+ }
+});
+
+test( "iso8601Week", function() {
+ expect( 12 );
+ var date = new Date(2000, 12 - 1, 31);
+ equal($.calendar.iso8601Week(date), 52, "ISO 8601 week " + date);
+ date = new Date(2001, 1 - 1, 1);
+ equal($.calendar.iso8601Week(date), 1, "ISO 8601 week " + date);
+ date = new Date(2001, 1 - 1, 7);
+ equal($.calendar.iso8601Week(date), 1, "ISO 8601 week " + date);
+ date = new Date(2001, 1 - 1, 8);
+ equal($.calendar.iso8601Week(date), 2, "ISO 8601 week " + date);
+ date = new Date(2003, 12 - 1, 28);
+ equal($.calendar.iso8601Week(date), 52, "ISO 8601 week " + date);
+ date = new Date(2003, 12 - 1, 29);
+ equal($.calendar.iso8601Week(date), 1, "ISO 8601 week " + date);
+ date = new Date(2004, 1 - 1, 4);
+ equal($.calendar.iso8601Week(date), 1, "ISO 8601 week " + date);
+ date = new Date(2004, 1 - 1, 5);
+ equal($.calendar.iso8601Week(date), 2, "ISO 8601 week " + date);
+ date = new Date(2009, 12 - 1, 28);
+ equal($.calendar.iso8601Week(date), 53, "ISO 8601 week " + date);
+ date = new Date(2010, 1 - 1, 3);
+ equal($.calendar.iso8601Week(date), 53, "ISO 8601 week " + date);
+ date = new Date(2010, 1 - 1, 4);
+ equal($.calendar.iso8601Week(date), 1, "ISO 8601 week " + date);
+ date = new Date(2010, 1 - 1, 10);
+ equal($.calendar.iso8601Week(date), 1, "ISO 8601 week " + date);
+});
+
+test( "parseDate", function() {
+ expect( 26 );
+ TestHelpers.calendar.init( "#inp" );
+ var currentYear, gmtDate, fr, settings, zh;
+ ok($.calendar.parseDate( "d m y", "" ) == null, "Parse date empty" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "d m y", "3 2 01" ),
+ new Date(2001, 2 - 1, 3), "Parse date d m y" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "dd mm yy", "03 02 2001" ),
+ new Date(2001, 2 - 1, 3), "Parse date dd mm yy" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "d m y", "13 12 01" ),
+ new Date(2001, 12 - 1, 13), "Parse date d m y" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "dd mm yy", "13 12 2001" ),
+ new Date(2001, 12 - 1, 13), "Parse date dd mm yy" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "y-o", "01-34" ),
+ new Date(2001, 2 - 1, 3), "Parse date y-o" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "yy-oo", "2001-347" ),
+ new Date(2001, 12 - 1, 13), "Parse date yy-oo" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "oo yy", "348 2004" ),
+ new Date(2004, 12 - 1, 13), "Parse date oo yy" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "D d M y", "Sat 3 Feb 01" ),
+ new Date(2001, 2 - 1, 3), "Parse date D d M y" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "d MM DD yy", "3 February Saturday 2001" ),
+ new Date(2001, 2 - 1, 3), "Parse date dd MM DD yy" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "DD, MM d, yy", "Saturday, February 3, 2001" ),
+ new Date(2001, 2 - 1, 3), "Parse date DD, MM d, yy" );
+ TestHelpers.calendar.equalsDate($.calendar.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" );
+ currentYear = new Date().getFullYear();
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "y-m-d", (currentYear - 2000) + "-02-03" ),
+ new Date(currentYear, 2 - 1, 3), "Parse date y-m-d - default cutuff" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "y-m-d", (currentYear - 2000 + 10) + "-02-03" ),
+ new Date(currentYear+10, 2 - 1, 3), "Parse date y-m-d - default cutuff" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "y-m-d", (currentYear - 2000 + 11) + "-02-03" ),
+ new Date(currentYear-89, 2 - 1, 3), "Parse date y-m-d - default cutuff" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "y-m-d", "80-02-03", {shortYearCutoff: 80}),
+ new Date(2080, 2 - 1, 3), "Parse date y-m-d - cutoff 80" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "y-m-d", "81-02-03", {shortYearCutoff: 80}),
+ new Date(1981, 2 - 1, 3), "Parse date y-m-d - cutoff 80" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "y-m-d", (currentYear - 2000 + 60) + "-02-03", {shortYearCutoff: "+60"}),
+ new Date(currentYear + 60, 2 - 1, 3), "Parse date y-m-d - cutoff +60" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "y-m-d", (currentYear - 2000 + 61) + "-02-03", {shortYearCutoff: "+60"}),
+ new Date(currentYear - 39, 2 - 1, 3), "Parse date y-m-d - cutoff +60" );
+ gmtDate = new Date(2001, 2 - 1, 3);
+ gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset());
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "@", "981158400000" ), gmtDate, "Parse date @" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "!", "631167552000000000" ), gmtDate, "Parse date !" );
+
+ fr = $.calendar.regional.fr;
+ settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
+ monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "D d M y", "Lun. 9 Avril 01", settings),
+ new Date(2001, 4 - 1, 9), "Parse date D M y with settings" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "d MM DD yy", "9 Avril Lundi 2001", settings),
+ new Date(2001, 4 - 1, 9), "Parse date d MM DD yy with settings" );
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "DD, MM d, yy", "Lundi, Avril 9, 2001", settings),
+ new Date(2001, 4 - 1, 9), "Parse date DD, MM d, yy with settings" );
+ TestHelpers.calendar.equalsDate($.calendar.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" );
+
+ zh = $.calendar.regional["zh-CN"];
+ TestHelpers.calendar.equalsDate($.calendar.parseDate( "yy M d", "2011 十一月 22", zh),
+ new Date(2011, 11 - 1, 22), "Parse date yy M d with zh-CN" );
+});
+
+test( "parseDateErrors", function() {
+ expect( 17 );
+ TestHelpers.calendar.init( "#inp" );
+ var fr, settings;
+ function expectError(expr, value, error) {
+ try {
+ expr();
+ ok(false, "Parsed error " + value);
+ }
+ catch (e) {
+ equal(e, error, "Parsed error " + value);
+ }
+ }
+ expectError(function() { $.calendar.parseDate(null, "Sat 2 01" ); },
+ "Sat 2 01", "Invalid arguments" );
+ expectError(function() { $.calendar.parseDate( "d m y", null); },
+ "null", "Invalid arguments" );
+ expectError(function() { $.calendar.parseDate( "d m y", "Sat 2 01" ); },
+ "Sat 2 01 - d m y", "Missing number at position 0" );
+ expectError(function() { $.calendar.parseDate( "dd mm yy", "Sat 2 01" ); },
+ "Sat 2 01 - dd mm yy", "Missing number at position 0" );
+ expectError(function() { $.calendar.parseDate( "d m y", "3 Feb 01" ); },
+ "3 Feb 01 - d m y", "Missing number at position 2" );
+ expectError(function() { $.calendar.parseDate( "dd mm yy", "3 Feb 01" ); },
+ "3 Feb 01 - dd mm yy", "Missing number at position 2" );
+ expectError(function() { $.calendar.parseDate( "d m y", "3 2 AD01" ); },
+ "3 2 AD01 - d m y", "Missing number at position 4" );
+ expectError(function() { $.calendar.parseDate( "d m yy", "3 2 AD01" ); },
+ "3 2 AD01 - dd mm yy", "Missing number at position 4" );
+ expectError(function() { $.calendar.parseDate( "y-o", "01-D01" ); },
+ "2001-D01 - y-o", "Missing number at position 3" );
+ expectError(function() { $.calendar.parseDate( "yy-oo", "2001-D01" ); },
+ "2001-D01 - yy-oo", "Missing number at position 5" );
+ expectError(function() { $.calendar.parseDate( "D d M y", "D7 3 Feb 01" ); },
+ "D7 3 Feb 01 - D d M y", "Unknown name at position 0" );
+ expectError(function() { $.calendar.parseDate( "D d M y", "Sat 3 M2 01" ); },
+ "Sat 3 M2 01 - D d M y", "Unknown name at position 6" );
+ expectError(function() { $.calendar.parseDate( "DD, MM d, yy", "Saturday- Feb 3, 2001" ); },
+ "Saturday- Feb 3, 2001 - DD, MM d, yy", "Unexpected literal at position 8" );
+ expectError(function() { $.calendar.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() { $.calendar.parseDate( "d m y", "29 2 01" ); },
+ "29 2 01 - d m y", "Invalid date" );
+ fr = $.calendar.regional.fr;
+ settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
+ monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
+ expectError(function() { $.calendar.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() { $.calendar.parseDate( "D d M y", "Lun. 9 Apr 01", settings); },
+ "Lun. 9 Apr 01 - D d M y", "Unknown name at position 7" );
+});
+
+test( "Ticket #7244: date parser does not fail when too many numbers are passed into the date function", function() {
+ expect( 4 );
+ var date;
+ try{
+ date = $.calendar.parseDate( "dd/mm/yy", "18/04/19881" );
+ ok(false, "Did not properly detect an invalid date" );
+ }catch(e){
+ ok( "invalid date detected" );
+ }
+
+ try {
+ date = $.calendar.parseDate( "dd/mm/yy", "18/04/1988 @ 2:43 pm" );
+ equal(date.getDate(), 18);
+ equal(date.getMonth(), 3);
+ equal(date.getFullYear(), 1988);
+ } catch(e) {
+ ok(false, "Did not properly parse date with extra text separated by whitespace" );
+ }
+});
+
+test( "formatDate", function() {
+ expect( 16 );
+ TestHelpers.calendar.init( "#inp" );
+ var gmtDate, fr, settings;
+ equal($.calendar.formatDate( "d m y", new Date(2001, 2 - 1, 3)),
+ "3 2 01", "Format date d m y" );
+ equal($.calendar.formatDate( "dd mm yy", new Date(2001, 2 - 1, 3)),
+ "03 02 2001", "Format date dd mm yy" );
+ equal($.calendar.formatDate( "d m y", new Date(2001, 12 - 1, 13)),
+ "13 12 01", "Format date d m y" );
+ equal($.calendar.formatDate( "dd mm yy", new Date(2001, 12 - 1, 13)),
+ "13 12 2001", "Format date dd mm yy" );
+ equal($.calendar.formatDate( "yy-o", new Date(2001, 2 - 1, 3)),
+ "2001-34", "Format date yy-o" );
+ equal($.calendar.formatDate( "yy-oo", new Date(2001, 2 - 1, 3)),
+ "2001-034", "Format date yy-oo" );
+ equal($.calendar.formatDate( "D M y", new Date(2001, 2 - 1, 3)),
+ "Sat Feb 01", "Format date D M y" );
+ equal($.calendar.formatDate( "DD MM yy", new Date(2001, 2 - 1, 3)),
+ "Saturday February 2001", "Format date DD MM yy" );
+ equal($.calendar.formatDate( "DD, MM d, yy", new Date(2001, 2 - 1, 3)),
+ "Saturday, February 3, 2001", "Format date DD, MM d, yy" );
+ equal($.calendar.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" );
+ gmtDate = new Date(2001, 2 - 1, 3);
+ gmtDate.setMinutes( gmtDate.getMinutes() - gmtDate.getTimezoneOffset() );
+ equal($.calendar.formatDate( "@", gmtDate), "981158400000", "Format date @" );
+ equal($.calendar.formatDate( "!", gmtDate), "631167552000000000", "Format date !" );
+ fr = $.calendar.regional.fr;
+ settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames,
+ monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames};
+ equal($.calendar.formatDate( "D M y", new Date(2001, 4 - 1, 9), settings),
+ "lun. avril 01", "Format date D M y with settings" );
+ equal($.calendar.formatDate( "DD MM yy", new Date(2001, 4 - 1, 9), settings),
+ "lundi avril 2001", "Format date DD MM yy with settings" );
+ equal($.calendar.formatDate( "DD, MM d, yy", new Date(2001, 4 - 1, 9), settings),
+ "lundi, avril 9, 2001", "Format date DD, MM d, yy with settings" );
+ equal($.calendar.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" );
+});
+
+// TODO: Fix this test so it isn't mysteriously flaky in Browserstack on certain OS/Browser combos
+// test( "Ticket 6827: formatDate day of year calculation is wrong during day lights savings time", function(){
+// expect( 1 );
+// var time = $.calendar.formatDate( "oo", new Date( "2010/03/30 12:00:00 CDT" ));
+// equal(time, "089" );
+// });
+
+test( "Ticket 7602: Stop calendar from appearing with beforeShow event handler", function() {
+ expect( 3 );
+
+ var inp, dp;
+
+ inp = TestHelpers.calendar.init( "#inp", {
+ beforeShow: function() {
+ }
+ });
+ dp = $( "#ui-calendar-div" );
+ inp.calendar( "show" );
+ equal( dp.css( "display" ), "block", "beforeShow returns nothing" );
+ inp.calendar( "hide" ).calendar( "destroy" );
+
+ inp = TestHelpers.calendar.init( "#inp", {
+ beforeShow: function() {
+ return true;
+ }
+ });
+ dp = $( "#ui-calendar-div" );
+ inp.calendar( "show" );
+ equal( dp.css( "display" ), "block", "beforeShow returns true" );
+ inp.calendar( "hide" );
+ inp.calendar( "destroy" );
+
+ inp = TestHelpers.calendar.init( "#inp", {
+ beforeShow: function() {
+ return false;
+ }
+ });
+ dp = $( "#ui-calendar-div" );
+ inp.calendar( "show" );
+ equal( dp.css( "display" ), "none", "beforeShow returns false" );
+ inp.calendar( "destroy" );
+});
+*/
+
+})(jQuery);
diff --git a/tests/unit/calendar/calendar_test_helpers.js b/tests/unit/calendar/calendar_test_helpers.js
new file mode 100644
index 00000000000..fa53c408fb6
--- /dev/null
+++ b/tests/unit/calendar/calendar_test_helpers.js
@@ -0,0 +1,28 @@
+TestHelpers.calendar = {
+ addMonths: function( date, offset ) {
+ var maxDay = 32 - new Date( date.getFullYear(), date.getMonth() + offset, 32 ).getDate();
+ date.setDate( Math.min( date.getDate(), maxDay ) );
+ date.setMonth( date.getMonth() + offset );
+ return date;
+ },
+ equalsDate: function( d1, d2, message ) {
+ if ( !d1 || !d2 ) {
+ ok( false, message + " - missing date" );
+ return;
+ }
+ d1 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate() );
+ d2 = new Date( d2.getFullYear(), d2.getMonth(), d2.getDate() );
+ equal( d1.toString(), d2.toString(), message );
+ },
+ init: function( id, options ) {
+ options = $.extend( { show: false }, options || {} );
+ return $( id ).calendar( options );
+ },
+ initNewInput: function( options ) {
+ options = $.extend( { show: false }, options || {} );
+ return $( "
" ).calendar( options )
+ .appendTo( "#qunit-fixture" );
+ },
+ onFocus: TestHelpers.onFocus,
+ PROP_NAME: "calendar"
+};
\ No newline at end of file
diff --git a/tests/unit/index.html b/tests/unit/index.html
index bd48590ec37..842ba7e6a8d 100644
--- a/tests/unit/index.html
+++ b/tests/unit/index.html
@@ -39,6 +39,7 @@
Widgets
Accordion
Autocomplete
+ Calendar
Button
Datepicker
Dialog
diff --git a/themes/base/base.css b/themes/base/base.css
index 479c3279d9b..b9adae8899c 100644
--- a/themes/base/base.css
+++ b/themes/base/base.css
@@ -13,6 +13,7 @@
@import url("accordion.css");
@import url("autocomplete.css");
@import url("button.css");
+@import url("calendar.css");
@import url("datepicker.css");
@import url("dialog.css");
@import url("draggable.css");
diff --git a/themes/base/calendar.css b/themes/base/calendar.css
new file mode 100644
index 00000000000..38dc8897170
--- /dev/null
+++ b/themes/base/calendar.css
@@ -0,0 +1,179 @@
+/*!
+ * jQuery UI Calendar @VERSION
+ * http://jqueryui.com
+ *
+ * Copyright 2014 jQuery Foundation and other contributors
+ * Released under the MIT license.
+ * http://jquery.org/license
+ *
+ * http://api.jqueryui.com/calendar/#theming
+ */
+.ui-calendar {
+ width: 17em;
+ padding: .2em .2em 0;
+ display: none;
+}
+.ui-calendar .ui-calendar-header {
+ position: relative;
+ padding: .2em 0;
+}
+.ui-calendar .ui-calendar-prev,
+.ui-calendar .ui-calendar-next {
+ position: absolute;
+ top: 2px;
+ width: 19px;
+ height: 18px;
+}
+.ui-calendar .ui-calendar-prev:not(.ui-state-hover):not(.ui-state-focus),
+.ui-calendar .ui-calendar-next:not(.ui-state-hover):not(.ui-state-focus) {
+ background: none;
+ border: none;
+}
+.ui-calendar .ui-calendar-prev-hover,
+.ui-calendar .ui-calendar-next-hover {
+ top: 1px;
+}
+.ui-calendar .ui-calendar-prev {
+ left: 2px;
+}
+.ui-calendar .ui-calendar-next {
+ right: 2px;
+}
+.ui-calendar .ui-calendar-prev-hover {
+ left: 1px;
+}
+.ui-calendar .ui-calendar-next-hover {
+ right: 1px;
+}
+.ui-calendar .ui-calendar-prev .ui-icon,
+.ui-calendar .ui-calendar-next .ui-icon {
+ display: block;
+ position: absolute;
+ left: 50%;
+ margin-left: -8px;
+ top: 50%;
+ margin-top: -8px;
+}
+.ui-calendar .ui-calendar-title {
+ line-height: 1.8em;
+ text-align: center;
+}
+.ui-calendar .ui-calendar-title select {
+ font-size: 1em;
+ margin: 1px 0;
+}
+.ui-calendar select.ui-calendar-month,
+.ui-calendar select.ui-calendar-year {
+ width: 49%;
+}
+.ui-calendar table {
+ width: 100%;
+ font-size: .9em;
+ border-collapse: collapse;
+ margin: 0 0 .4em;
+}
+.ui-calendar th {
+ padding: .7em .3em;
+ text-align: center;
+ font-weight: bold;
+ border: 0;
+}
+.ui-calendar td {
+ border: 0;
+ padding: 1px;
+}
+.ui-calendar td span,
+.ui-calendar td a {
+ display: block;
+ padding: .2em;
+ text-align: right;
+ text-decoration: none;
+}
+.ui-calendar .ui-calendar-buttonpane {
+ background-image: none;
+ margin: .7em 0 0 0;
+ padding: 0 .2em;
+ border-left: 0;
+ border-right: 0;
+ border-bottom: 0;
+}
+.ui-calendar .ui-calendar-buttonpane button {
+ float: right;
+ margin: .5em .2em .4em;
+ cursor: pointer;
+ padding: .2em .6em .3em .6em;
+ width: auto;
+ overflow: visible;
+}
+.ui-calendar .ui-calendar-buttonpane button.ui-calendar-current {
+ float: left;
+}
+
+/* with multiple calendars */
+.ui-calendar.ui-calendar-multi {
+ width: 100%;
+}
+.ui-calendar-multi .ui-calendar-group {
+ float: left;
+}
+.ui-calendar-multi .ui-calendar-group table {
+ width: 95%;
+ margin: 0 auto .4em;
+}
+.ui-calendar-multi-2 .ui-calendar-group {
+ width: 50%;
+}
+.ui-calendar-multi-3 .ui-calendar-group {
+ width: 33.3%;
+}
+.ui-calendar-multi-4 .ui-calendar-group {
+ width: 25%;
+}
+.ui-calendar-multi .ui-calendar-group-last .ui-calendar-header,
+.ui-calendar-multi .ui-calendar-group-middle .ui-calendar-header {
+ border-left-width: 0;
+}
+.ui-calendar-multi .ui-calendar-buttonpane {
+ clear: left;
+}
+.ui-calendar-row-break {
+ clear: both;
+ width: 100%;
+ font-size: 0;
+}
+
+/* RTL support */
+.ui-calendar-rtl {
+ direction: rtl;
+}
+.ui-calendar-rtl .ui-calendar-prev {
+ right: 2px;
+ left: auto;
+}
+.ui-calendar-rtl .ui-calendar-next {
+ left: 2px;
+ right: auto;
+}
+.ui-calendar-rtl .ui-calendar-prev:hover {
+ right: 1px;
+ left: auto;
+}
+.ui-calendar-rtl .ui-calendar-next:hover {
+ left: 1px;
+ right: auto;
+}
+.ui-calendar-rtl .ui-calendar-buttonpane {
+ clear: right;
+}
+.ui-calendar-rtl .ui-calendar-buttonpane button {
+ float: left;
+}
+.ui-calendar-rtl .ui-calendar-buttonpane button.ui-calendar-current,
+.ui-calendar-rtl .ui-calendar-group {
+ float: right;
+}
+.ui-calendar-rtl .ui-calendar-group-last .ui-calendar-header,
+.ui-calendar-rtl .ui-calendar-group-middle .ui-calendar-header {
+ border-right-width: 0;
+ border-left-width: 1px;
+}
diff --git a/ui/calendar.js b/ui/calendar.js
new file mode 100644
index 00000000000..14093b50b21
--- /dev/null
+++ b/ui/calendar.js
@@ -0,0 +1,766 @@
+/*!
+ * jQuery UI Calendar @VERSION
+ * http://jqueryui.com
+ *
+ * Copyright 2014 jQuery Foundation and other contributors
+ * Released under the MIT license.
+ * http://jquery.org/license
+ *
+ * http://api.jqueryui.com/calendar/
+ */
+(function( factory ) {
+ if ( typeof define === "function" && define.amd ) {
+
+ // AMD. Register as an anonymous module.
+ define([
+ "jquery",
+ "./core",
+ "./widget",
+ "./button"
+ ], factory );
+ } else {
+
+ // Browser globals
+ factory( jQuery );
+ }
+}(function( $ ) {
+
+// TODO use uniqueId, if possible
+var idIncrement = 0,
+ // TODO move this to the instance
+ suppressExpandOnFocus = false;
+
+return $.widget( "ui.calendar", {
+ options: {
+ appendTo: null,
+ dateFormat: { date: "short" },
+ // TODO review
+ eachDay: $.noop,
+ numberOfMonths: 1,
+ position: {
+ my: "left top",
+ at: "left bottom"
+ },
+ showWeek: false,
+ show: true,
+ hide: true,
+ value: null,
+
+ // callbacks
+ beforeOpen: null,
+ close: null,
+ open: null,
+ select: null
+ },
+
+ _create: function() {
+ this.id = "ui-calendar-" + idIncrement;
+ idIncrement++;
+
+ if ( this.element.is( "input" ) ) {
+ if ( !this.options.value && this.isValid() ) {
+ this.options.value = this._getParsedValue();
+ }
+ this._createPicker();
+ } else {
+ this.inline = true;
+ this.picker = this.element;
+ }
+
+ this.date = $.date( this.options.value, this.options.dateFormat ).select();
+ this.date.eachDay = this.options.eachDay;
+
+ this._on( this.picker, {
+ "click .ui-calendar-prev": function( event ) {
+ event.preventDefault();
+ this.date.adjust( "M", -this.options.numberOfMonths );
+ this.refresh();
+ },
+ "click .ui-calendar-next": function( event ) {
+ event.preventDefault();
+ this.date.adjust( "M", this.options.numberOfMonths );
+ this.refresh();
+ },
+ "click .ui-calendar-current": function( event ) {
+ event.preventDefault();
+ this._select( event, new Date().getTime() );
+ },
+ "click .ui-calendar-close": function( event ) {
+ event.preventDefault();
+ this.close( event );
+ },
+ "mousedown .ui-calendar-calendar a": function( event ) {
+ event.preventDefault();
+ // TODO exclude clicks on lead days or handle them correctly
+ // TODO store/read more then just date, also required for multi month picker
+ this._select( event, $( event.currentTarget ).data( "timestamp" ) );
+ if ( this.inline ) {
+ this.grid.focus( 1 );
+ }
+ },
+ "keydown .ui-calendar-calendar": "_handleKeydown"
+ });
+
+ // TODO use hoverable (no delegation support)? convert to _on?
+ this.picker.delegate( ".ui-calendar-header a, .ui-calendar-calendar a", "mouseenter.calendar mouseleave.calendar", function() {
+ $( this ).toggleClass( "ui-state-hover" );
+ });
+
+ this._createTmpl();
+ },
+
+ _handleKeydown: function( event ) {
+ if ( jQuery.inArray( event.keyCode, [ 13, 33, 34, 35, 36, 37, 38, 39, 40 ] ) === -1 ) {
+ // only interested navigation keys
+ return;
+ }
+ event.preventDefault();
+
+ var newId, newCell,
+ activeCell = $( "#" + this.grid.attr( "aria-activedescendant" ) ),
+ oldMonth = this.date.month(),
+ oldYear = this.date.year();
+
+ // TODO: Handle for pickers with multiple months
+ switch ( event.keyCode ) {
+ case $.ui.keyCode.ENTER:
+ activeCell.children( "a:first" ).mousedown();
+ return;
+ case $.ui.keyCode.PAGE_UP:
+ this.date.adjust( event.altKey ? "Y" : "M", -1 );
+ break;
+ case $.ui.keyCode.PAGE_DOWN:
+ this.date.adjust( event.altKey ? "Y" : "M", 1 );
+ break;
+ case $.ui.keyCode.END:
+ this.date.setDay( this.date.daysInMonth() );
+ break;
+ case $.ui.keyCode.HOME:
+ this.date.setDay( 1 );
+ break;
+ case $.ui.keyCode.LEFT:
+ this.date.adjust( "D", -1 );
+ break;
+ case $.ui.keyCode.UP:
+ this.date.adjust( "D", -7 );
+ break;
+ case $.ui.keyCode.RIGHT:
+ this.date.adjust( "D", 1 );
+ break;
+ case $.ui.keyCode.DOWN:
+ this.date.adjust( "D", 7 );
+ break;
+ default:
+ return;
+ }
+
+ if ( this.date.month() !== oldMonth || this.date.year() !== oldYear ) {
+ this.refresh();
+ this.grid.focus( 1 );
+ }
+ else {
+ newId = this.id + "-" + this.date.day();
+ newCell = $( "#" + newId );
+
+ // TODO unnecessary optimization? is it really needed?
+ if ( !newCell.length ) {
+ return;
+ }
+ this.grid.attr("aria-activedescendant", newId);
+
+ this.grid.find( ".ui-state-focus" ).removeClass( "ui-state-focus" );
+ newCell.children( "a" ).addClass( "ui-state-focus" );
+ }
+ },
+
+ _createPicker: function() {
+ this.picker = $( "" )
+ .addClass( "ui-front" )
+ // TODO add a ui-calendar-popup class, move position:absolute to that
+ .css( "position", "absolute" )
+ .uniqueId()
+ .hide();
+ this._setHiddenPicker();
+ this.picker.appendTo( this._appendTo() );
+
+ this.element
+ .attr( "aria-haspopup", "true" )
+ .attr( "aria-owns", this.picker.attr( "id" ) );
+
+ this._on({
+ keydown: function( event ) {
+ switch ( event.keyCode ) {
+ case $.ui.keyCode.TAB:
+ // Waiting for close() will make popup hide too late, which breaks tab key behavior
+ this.picker.hide();
+ this.close( event );
+ break;
+ case $.ui.keyCode.ESCAPE:
+ if ( this.isOpen ) {
+ this.close( event );
+ }
+ break;
+ case $.ui.keyCode.ENTER:
+ this._handleKeydown( event );
+ break;
+ case $.ui.keyCode.DOWN:
+ case $.ui.keyCode.UP:
+ clearTimeout( this.closeTimer );
+ this._delay( function() {
+ this.open( event );
+ this.grid.focus( 1 );
+ }, 1 );
+ break;
+ case $.ui.keyCode.HOME:
+ if ( event.ctrlKey ) {
+ this.date.setTime( new Date() );
+ event.preventDefault();
+ if ( this.isOpen ) {
+ this.refresh();
+ } else {
+ this.open( event );
+ }
+ }
+ break;
+ // TODO this is not in specs, keep?
+ case $.ui.keyCode.END:
+ if ( event.ctrlKey ) {
+ this.element.val( "" );
+ event.preventDefault();
+ if ( this.isOpen ) {
+ this.close( event );
+ }
+ }
+ break;
+ }
+ },
+ keyup: function() {
+ if ( this.isValid() && !this.inline ) {
+ this.date.setTime( this._getParsedValue() ).select();
+ this.refresh();
+ }
+ },
+ mousedown: function( event ) {
+ if ( this.isOpen ) {
+ suppressExpandOnFocus = true;
+ this.close();
+ return;
+ }
+ this.open( event );
+ clearTimeout( this.closeTimer );
+ },
+ focus: function( event ) {
+ if ( !suppressExpandOnFocus ) {
+ this._delay( function() {
+ if ( !this.isOpen ) {
+ this.open( event );
+ }
+ }, 1);
+ }
+ this._delay( function() {
+ suppressExpandOnFocus = false;
+ }, 100 );
+ },
+ blur: function() {
+ suppressExpandOnFocus = false;
+ }
+ });
+
+ this._on( this.picker, {
+ focusout: function( event ) {
+ // use a timer to allow click to clear it and letting that
+ // handle the closing instead of opening again
+ // also allows tabbing inside the calendar without it closing
+ this.closeTimer = this._delay( function() {
+ this.close( event );
+ }, 150 );
+ },
+ focusin: function() {
+ clearTimeout( this.closeTimer );
+ },
+ mouseup: function() {
+ clearTimeout( this.closeTimer );
+ },
+ // TODO on TAB (or shift TAB), make sure it ends up on something useful in DOM order
+ keyup: function( event ) {
+ if ( event.keyCode === $.ui.keyCode.ESCAPE && this.picker.is( ":visible" ) ) {
+ this.close( event );
+ this._focusTrigger();
+ }
+ }
+ });
+
+ this._on( this.document, {
+ click: function( event ) {
+ if ( this.isOpen && !$( event.target ).closest( this.element.add( this.picker ) ).length ) {
+ this.close( event );
+ }
+ }
+ });
+ },
+
+ _appendTo: function() {
+ var element = this.options.appendTo;
+
+ if ( element ) {
+ element = element.jquery || element.nodeType ?
+ $( element ) :
+ this.document.find( element ).eq( 0 );
+ }
+
+ if ( !element ) {
+ element = this.element.closest( ".ui-front" );
+ }
+
+ if ( !element.length ) {
+ element = this.document[ 0 ].body;
+ }
+
+ return element;
+ },
+
+ _createTmpl: function() {
+ this._createDatepicker();
+ this.picker.find( "button" ).button();
+
+ if ( this.inline ) {
+ this.picker.children().addClass( "ui-calendar-inline" );
+ }
+ // against display:none in calendar.css
+ this.picker.find( ".ui-calendar" ).css( "display", "block" );
+ this.grid = this.picker.find( ".ui-calendar-calendar" );
+ },
+
+ _createDatepicker: function() {
+ var multiClasses = [],
+ pickerHtml = "";
+
+ if (this.options.numberOfMonths === 1 ) {
+ pickerHtml = this._buildHeader() + this._buildGrid() + this._buildButtons();
+ } else {
+ pickerHtml = this._buildMultiplePicker();
+ multiClasses.push( "ui-calendar-multi" );
+ multiClasses.push( "ui-calendar-multi-" + this.options.numberOfMonths );
+ }
+
+ $( "
" )
+ .addClass( "ui-calendar ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
+ .addClass( multiClasses.join( " " ) )
+ .attr({
+ role: "region",
+ "aria-labelledby": this.id + "-title"
+ })
+ .html( pickerHtml )
+ .appendTo( this.picker );
+ },
+
+ _buildMultiplePicker: function() {
+ var headerClass,
+ html = "",
+ currentDate = this.date,
+ months = this.date.months( this.options.numberOfMonths - 1 ),
+ i = 0;
+
+ for ( i; i < months.length; i++ ) {
+ // TODO Shouldn't we pass date as a parameter to build* fns instead of setting this.date?
+ this.date = months[ i ];
+ headerClass = months[ i ].first ? "ui-corner-left" :
+ months[ i ].last ? "ui-corner-right" : "";
+
+ html += "
" +
+ "";
+ html += this._buildGrid();
+ html += "
";
+ }
+
+ html += "
";
+ html += this._buildButtons();
+
+ this.date = currentDate;
+
+ return html;
+ },
+
+ _buildHeader: function() {
+ return "";
+ },
+
+ _buildPreviousLink: function() {
+ var labels = Globalize.translate( "calendar" );
+
+ return "
" +
+ "" +
+ labels.prevText +
+ " " +
+ " ";
+ },
+
+ _buildNextLink: function() {
+ var labels = Globalize.translate( "calendar" );
+
+ return "
" +
+ "" +
+ labels.nextText +
+ " " +
+ " ";
+ },
+
+ _buildTitlebar: function() {
+ var labels = Globalize.translate( "calendar" );
+
+ return "
" +
+ "
" +
+ this._buildTitle() +
+ "
" +
+ "
, " + labels.datePickerRole + " " +
+ "
";
+ },
+
+ _buildTitle: function() {
+ return "
" +
+ this.date.monthName() +
+ " " +
+ "
" +
+ this.date.year() +
+ " ";
+ },
+
+ _buildGrid: function() {
+ return "
" +
+ this._buildGridHeading() +
+ this._buildGridBody() +
+ "
";
+ },
+
+ _buildGridHeading: function() {
+ var cells = "",
+ i = 0,
+ labels = Globalize.translate( "calendar" );
+
+ if ( this.options.showWeek ) {
+ cells += "
" + labels.weekHeader + " ";
+ }
+ for ( i; i < this.date.weekdays().length; i++ ) {
+ cells += this._buildGridHeaderCell( this.date.weekdays()[i] );
+ }
+
+ return "
" +
+ "" + cells + " " +
+ " ";
+ },
+
+ _buildGridHeaderCell: function( day ) {
+ return "
" +
+ "" +
+ day.shortname +
+ " " +
+ " ";
+ },
+
+ _buildGridBody: function() {
+ // this.date.days() is not cached, and it has O(n^2) complexity. It is run O(n) times. So, it equals O(n^3). Not good at all. Caching.
+ var days = this.date.days(),
+ i = 0,
+ rows = "";
+
+ for ( i; i < days.length; i++ ) {
+ rows += this._buildWeekRow( days[ i ] );
+ }
+
+ return "
" + rows + " ";
+ },
+
+ _buildWeekRow: function( week ) {
+ var cells = "",
+ i = 0;
+
+ if ( this.options.showWeek ) {
+ cells += "
" + week.number + " ";
+ }
+ for ( i; i < week.days.length; i++ ) {
+ cells += this._buildDayCell( week.days[i] );
+ }
+ return "
" + cells + " ";
+ },
+
+ _buildDayCell: function( day ) {
+ var contents = "",
+ idAttribute = day.render ? ( "id=" + this.id + "-" + day.date ) : "",
+ ariaSelectedAttribute = "aria-selected=" + ( day.current ? "true" : "false" ),
+ ariaDisabledAttribute = day.selectable ? "" : "aria-disabled=true";
+
+ if ( day.render ) {
+ if ( day.selectable ) {
+ contents = this._buildDayLink( day );
+ } else {
+ contents = this._buildDayDisplay( day );
+ }
+ }
+
+ return "
" +
+ contents +
+ " ";
+ },
+
+ _buildDayLink: function( day ) {
+ var link,
+ classes = [ "ui-state-default" ],
+ labels = Globalize.translate( "calendar" );
+
+ if ( day.date === this.date.day() ) {
+ classes.push( "ui-state-focus" );
+ }
+ if ( day.current ) {
+ classes.push( "ui-state-active" );
+ }
+ if ( day.today ) {
+ classes.push( "ui-state-highlight" );
+ }
+ if ( day.extraClasses ) {
+ classes.push( day.extraClasses.split( " " ) );
+ }
+
+ link = "
" +
+ day.date + " ";
+ if ( day.today ) {
+ link += "
, " + labels.currentText + " ";
+ }
+
+ return link;
+ },
+
+ _buildDayDisplay: function( day ) {
+ var classes = [];
+
+ if ( day.current ) {
+ classes.push( "ui-state-active" );
+ }
+ if ( day.today ) {
+ classes.push( "ui-state-highlight" );
+ }
+ if ( day.extraClasses ) {
+ classes.push( day.extraClasses.split( " " ) );
+ }
+
+ return "
" + day.date + " ";
+ },
+
+ _buildButtons: function() {
+ var labels = Globalize.translate( "calendar" );
+
+ return "
" +
+ "" + labels.currentText + " " +
+ "" + labels.closeText + " " +
+ "
";
+ },
+
+ _focusTrigger: function() {
+ suppressExpandOnFocus = true;
+ this.element.focus();
+ },
+
+ // Refreshing the entire calendar during interaction confuses screen readers, specifically
+ // because the grid heading is marked up as a live region and will often not update if it's
+ // destroyed and recreated instead of just having its text change. Additionally, interacting
+ // with the prev and next links would cause loss of focus issues because the links being
+ // interacted with will disappear while focused.
+ refresh: function() {
+ // determine which day gridcell to focus after refresh
+ // TODO: Prevent disabled cells from being focused
+ if ( this.options.numberOfMonths === 1 ) {
+ this.grid = $( this._buildGrid() );
+ $( ".ui-calendar-title", this.picker ).html( this._buildTitle() );
+ $( ".ui-calendar-calendar", this.picker ).replaceWith( this.grid );
+ } else {
+ this._refreshMultiplePicker();
+ }
+ },
+
+ _refreshMultiplePicker: function() {
+ var i = 0;
+
+ for ( ; i < this.options.numberOfMonths; i++ ) {
+ $( ".ui-calendar-title", this.picker ).eq( i ).html( this._buildTitle() );
+ $( ".ui-calendar-calendar", this.picker ).eq( i ).html( this._buildGrid() );
+ this.date.adjust( "M", 1 );
+ }
+ this.date.adjust( "M", -this.options.numberOfMonths );
+
+ // TODO: This assumes focus is on the first grid. For multi pickers, the widget needs
+ // to maintain the currently focused grid and base queries like this off of it.
+ $( this.picker ).find( ".ui-state-focus" ).not( ":first" ).removeClass( "ui-state-focus" );
+ },
+
+ open: function( event ) {
+ if ( this.inline || this.isOpen ) {
+ return;
+ }
+ if ( this._trigger( "beforeOpen", event ) === false ) {
+ return;
+ }
+
+ this.refresh();
+
+ this.picker
+ .attr( "aria-hidden", "false" )
+ .attr( "aria-expanded", "true" )
+ .show()
+ .position( this._buildPosition() )
+ .hide();
+
+ this._show( this.picker, this.options.show );
+
+ // take trigger out of tab order to allow shift-tab to skip trigger
+ // TODO does this really make sense? related bug: tab-shift moves focus to last element on page
+ this.element.attr( "tabindex", -1 );
+ this.isOpen = true;
+
+ this._trigger( "open", event );
+ },
+
+ close: function( event ) {
+ if ( this.inline ) {
+ return;
+ }
+
+ this._setHiddenPicker();
+ this._hide( this.picker, this.options.hide );
+
+ this.element.attr( "tabindex" , 0 );
+
+ this.isOpen = false;
+ this._trigger( "close", event );
+ },
+
+ _setHiddenPicker: function() {
+ this.picker
+ .attr( "aria-hidden", "true" )
+ .attr( "aria-expanded", "false" );
+ },
+
+ _buildPosition: function() {
+ return $.extend( {}, { of: this.element }, this.options.position );
+ },
+
+ _select: function( event, time ) {
+ this._setOption( "value", new Date( time ) );
+ if ( !this.inline ) {
+ this.close();
+ this._focusTrigger();
+ }
+ this._trigger( "select", event, {
+ // TODO replace with value option to initialise and read
+ date: this.value()
+ });
+ },
+
+ value: function( value ) {
+ if ( arguments.length ) {
+ this._setOption( "value", Globalize.parseDate( value, this.options.dateFormat ) );
+ } else {
+ if ( this.inline ) {
+ return Globalize.format( this.date.selected(), this.options.dateFormat );
+ } else {
+ return this.element.val();
+ }
+ }
+ },
+
+ valueAsDate: function( value ) {
+ if ( arguments.length ) {
+ this._setOption( "value", value );
+ } else {
+ return this.option( "value" );
+ }
+ },
+
+ isValid: function() {
+ if ( this.inline ) {
+ return true;
+ }
+
+ return this._getParsedValue() !== null;
+ },
+
+ _destroy: function() {
+ if ( this.inline ) {
+ this.picker.empty();
+ } else {
+ this.picker.remove();
+ this.element
+ .removeAttr( "aria-haspopup" )
+ .removeAttr( "aria-owns" );
+ }
+ },
+
+ widget: function() {
+ return this.picker;
+ },
+
+ _getParsedValue: function() {
+ return Globalize.parseDate( this.element.val(), this.options.dateFormat );
+ },
+
+ option: function( key ) {
+ if ( arguments.length === 0 || ( arguments.length === 1 && key === "value" ) ) {
+ this.options.value = this.inline ? this.date.selected() : this._getParsedValue();
+ }
+ return this._superApply( arguments );
+ },
+
+ _setOption: function( key, value ) {
+ if ( key === "value" ) {
+ if ( value instanceof Date ) {
+ this.date.setTime( value.getTime() ).select();
+ this.refresh();
+ if ( !this.inline ) {
+ this.element.val( this.date.format() );
+ }
+ }
+ }
+
+ this._super( key, value );
+
+ if ( key === "appendTo" ) {
+ this.picker.appendTo( this._appendTo() );
+ }
+
+ if ( key === "eachDay" ) {
+ this.date.eachDay = this.options.eachDay;
+ this.refresh();
+ }
+
+ if ( key === "dateFormat" ) {
+ this.date.setFormat( this.options.dateFormat );
+ if ( !this.inline ) {
+ this.element.val( this.date.format() );
+ }
+ }
+
+ if ( key === "showWeek" ) {
+ this.refresh();
+ }
+
+ if ( key === "position" ) {
+ this.picker.position( this._buildPosition() );
+ }
+ }
+});
+
+}));
From 3d52c371e6dd4b4ca771cfccf5ee9400fa1a0edf Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Thu, 5 Jun 2014 01:19:34 +0200
Subject: [PATCH 03/94] Calendar: Add missing AMD dependency todo comment
---
ui/calendar.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/ui/calendar.js b/ui/calendar.js
index 14093b50b21..5d29c930816 100644
--- a/ui/calendar.js
+++ b/ui/calendar.js
@@ -12,6 +12,7 @@
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
+ // ToDo Add globalize and $.date?
define([
"jquery",
"./core",
From 4a6d8203d5940299bcd44567b3ee6658cf66832d Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Wed, 4 Jun 2014 00:08:03 +0200
Subject: [PATCH 04/94] Calendar: remove datepicker functionality, options and
methods
---
demos/calendar/default.html | 2 +-
ui/calendar.js | 328 +++---------------------------------
2 files changed, 29 insertions(+), 301 deletions(-)
diff --git a/demos/calendar/default.html b/demos/calendar/default.html
index 26c4c2eb3d5..b35e9e769bd 100644
--- a/demos/calendar/default.html
+++ b/demos/calendar/default.html
@@ -22,7 +22,7 @@
-Date:
+
The calendar is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.
diff --git a/ui/calendar.js b/ui/calendar.js
index 5d29c930816..dac8964d6c6 100644
--- a/ui/calendar.js
+++ b/ui/calendar.js
@@ -27,30 +27,18 @@
}(function( $ ) {
// TODO use uniqueId, if possible
-var idIncrement = 0,
- // TODO move this to the instance
- suppressExpandOnFocus = false;
+var idIncrement = 0;
return $.widget( "ui.calendar", {
options: {
- appendTo: null,
dateFormat: { date: "short" },
// TODO review
eachDay: $.noop,
numberOfMonths: 1,
- position: {
- my: "left top",
- at: "left bottom"
- },
showWeek: false,
- show: true,
- hide: true,
value: null,
// callbacks
- beforeOpen: null,
- close: null,
- open: null,
select: null
},
@@ -58,20 +46,10 @@ return $.widget( "ui.calendar", {
this.id = "ui-calendar-" + idIncrement;
idIncrement++;
- if ( this.element.is( "input" ) ) {
- if ( !this.options.value && this.isValid() ) {
- this.options.value = this._getParsedValue();
- }
- this._createPicker();
- } else {
- this.inline = true;
- this.picker = this.element;
- }
-
this.date = $.date( this.options.value, this.options.dateFormat ).select();
this.date.eachDay = this.options.eachDay;
- this._on( this.picker, {
+ this._on( this.element, {
"click .ui-calendar-prev": function( event ) {
event.preventDefault();
this.date.adjust( "M", -this.options.numberOfMonths );
@@ -86,24 +64,18 @@ return $.widget( "ui.calendar", {
event.preventDefault();
this._select( event, new Date().getTime() );
},
- "click .ui-calendar-close": function( event ) {
- event.preventDefault();
- this.close( event );
- },
"mousedown .ui-calendar-calendar a": function( event ) {
event.preventDefault();
// TODO exclude clicks on lead days or handle them correctly
// TODO store/read more then just date, also required for multi month picker
this._select( event, $( event.currentTarget ).data( "timestamp" ) );
- if ( this.inline ) {
- this.grid.focus( 1 );
- }
+ this.grid.focus( 1 );
},
"keydown .ui-calendar-calendar": "_handleKeydown"
});
// TODO use hoverable (no delegation support)? convert to _on?
- this.picker.delegate( ".ui-calendar-header a, .ui-calendar-calendar a", "mouseenter.calendar mouseleave.calendar", function() {
+ this.element.delegate( ".ui-calendar-header a, .ui-calendar-calendar a", "mouseenter.calendar mouseleave.calendar", function() {
$( this ).toggleClass( "ui-state-hover" );
});
@@ -174,162 +146,13 @@ return $.widget( "ui.calendar", {
}
},
- _createPicker: function() {
- this.picker = $( "
" )
- .addClass( "ui-front" )
- // TODO add a ui-calendar-popup class, move position:absolute to that
- .css( "position", "absolute" )
- .uniqueId()
- .hide();
- this._setHiddenPicker();
- this.picker.appendTo( this._appendTo() );
-
- this.element
- .attr( "aria-haspopup", "true" )
- .attr( "aria-owns", this.picker.attr( "id" ) );
-
- this._on({
- keydown: function( event ) {
- switch ( event.keyCode ) {
- case $.ui.keyCode.TAB:
- // Waiting for close() will make popup hide too late, which breaks tab key behavior
- this.picker.hide();
- this.close( event );
- break;
- case $.ui.keyCode.ESCAPE:
- if ( this.isOpen ) {
- this.close( event );
- }
- break;
- case $.ui.keyCode.ENTER:
- this._handleKeydown( event );
- break;
- case $.ui.keyCode.DOWN:
- case $.ui.keyCode.UP:
- clearTimeout( this.closeTimer );
- this._delay( function() {
- this.open( event );
- this.grid.focus( 1 );
- }, 1 );
- break;
- case $.ui.keyCode.HOME:
- if ( event.ctrlKey ) {
- this.date.setTime( new Date() );
- event.preventDefault();
- if ( this.isOpen ) {
- this.refresh();
- } else {
- this.open( event );
- }
- }
- break;
- // TODO this is not in specs, keep?
- case $.ui.keyCode.END:
- if ( event.ctrlKey ) {
- this.element.val( "" );
- event.preventDefault();
- if ( this.isOpen ) {
- this.close( event );
- }
- }
- break;
- }
- },
- keyup: function() {
- if ( this.isValid() && !this.inline ) {
- this.date.setTime( this._getParsedValue() ).select();
- this.refresh();
- }
- },
- mousedown: function( event ) {
- if ( this.isOpen ) {
- suppressExpandOnFocus = true;
- this.close();
- return;
- }
- this.open( event );
- clearTimeout( this.closeTimer );
- },
- focus: function( event ) {
- if ( !suppressExpandOnFocus ) {
- this._delay( function() {
- if ( !this.isOpen ) {
- this.open( event );
- }
- }, 1);
- }
- this._delay( function() {
- suppressExpandOnFocus = false;
- }, 100 );
- },
- blur: function() {
- suppressExpandOnFocus = false;
- }
- });
-
- this._on( this.picker, {
- focusout: function( event ) {
- // use a timer to allow click to clear it and letting that
- // handle the closing instead of opening again
- // also allows tabbing inside the calendar without it closing
- this.closeTimer = this._delay( function() {
- this.close( event );
- }, 150 );
- },
- focusin: function() {
- clearTimeout( this.closeTimer );
- },
- mouseup: function() {
- clearTimeout( this.closeTimer );
- },
- // TODO on TAB (or shift TAB), make sure it ends up on something useful in DOM order
- keyup: function( event ) {
- if ( event.keyCode === $.ui.keyCode.ESCAPE && this.picker.is( ":visible" ) ) {
- this.close( event );
- this._focusTrigger();
- }
- }
- });
-
- this._on( this.document, {
- click: function( event ) {
- if ( this.isOpen && !$( event.target ).closest( this.element.add( this.picker ) ).length ) {
- this.close( event );
- }
- }
- });
- },
-
- _appendTo: function() {
- var element = this.options.appendTo;
-
- if ( element ) {
- element = element.jquery || element.nodeType ?
- $( element ) :
- this.document.find( element ).eq( 0 );
- }
-
- if ( !element ) {
- element = this.element.closest( ".ui-front" );
- }
-
- if ( !element.length ) {
- element = this.document[ 0 ].body;
- }
-
- return element;
- },
-
_createTmpl: function() {
this._createDatepicker();
- this.picker.find( "button" ).button();
+ this.element.find( "button" ).button();
- if ( this.inline ) {
- this.picker.children().addClass( "ui-calendar-inline" );
- }
// against display:none in calendar.css
- this.picker.find( ".ui-calendar" ).css( "display", "block" );
- this.grid = this.picker.find( ".ui-calendar-calendar" );
+ this.element.find( ".ui-calendar" ).css( "display", "block" );
+ this.grid = this.element.find( ".ui-calendar-calendar" );
},
_createDatepicker: function() {
@@ -352,7 +175,7 @@ return $.widget( "ui.calendar", {
"aria-labelledby": this.id + "-title"
})
.html( pickerHtml )
- .appendTo( this.picker );
+ .appendTo( this.element );
},
_buildMultiplePicker: function() {
@@ -400,10 +223,9 @@ return $.widget( "ui.calendar", {
},
_buildPreviousLink: function() {
- var labels = Globalize.translate( "calendar" );
+ var labels = Globalize.translate( "datepicker" );
- return "
" +
+ return "" +
"" +
labels.prevText +
" " +
@@ -411,10 +233,9 @@ return $.widget( "ui.calendar", {
},
_buildNextLink: function() {
- var labels = Globalize.translate( "calendar" );
+ var labels = Globalize.translate( "datepicker" );
- return "" +
+ return "" +
"" +
labels.nextText +
" " +
@@ -422,7 +243,7 @@ return $.widget( "ui.calendar", {
},
_buildTitlebar: function() {
- var labels = Globalize.translate( "calendar" );
+ var labels = Globalize.translate( "datepicker" );
return "" +
"
" +
@@ -452,7 +273,7 @@ return $.widget( "ui.calendar", {
_buildGridHeading: function() {
var cells = "",
i = 0,
- labels = Globalize.translate( "calendar" );
+ labels = Globalize.translate( "datepicker" );
if ( this.options.showWeek ) {
cells += "
" + labels.weekHeader + " ";
@@ -522,7 +343,7 @@ return $.widget( "ui.calendar", {
_buildDayLink: function( day ) {
var link,
classes = [ "ui-state-default" ],
- labels = Globalize.translate( "calendar" );
+ labels = Globalize.translate( "datepicker" );
if ( day.date === this.date.day() ) {
classes.push( "ui-state-focus" );
@@ -563,19 +384,13 @@ return $.widget( "ui.calendar", {
},
_buildButtons: function() {
- var labels = Globalize.translate( "calendar" );
+ var labels = Globalize.translate( "datepicker" );
return "
" +
"" + labels.currentText + " " +
- "" + labels.closeText + " " +
"
";
},
- _focusTrigger: function() {
- suppressExpandOnFocus = true;
- this.element.focus();
- },
-
// Refreshing the entire calendar during interaction confuses screen readers, specifically
// because the grid heading is marked up as a live region and will often not update if it's
// destroyed and recreated instead of just having its text change. Additionally, interacting
@@ -586,8 +401,8 @@ return $.widget( "ui.calendar", {
// TODO: Prevent disabled cells from being focused
if ( this.options.numberOfMonths === 1 ) {
this.grid = $( this._buildGrid() );
- $( ".ui-calendar-title", this.picker ).html( this._buildTitle() );
- $( ".ui-calendar-calendar", this.picker ).replaceWith( this.grid );
+ $( ".ui-calendar-title", this.element ).html( this._buildTitle() );
+ $( ".ui-calendar-calendar", this.element ).replaceWith( this.grid );
} else {
this._refreshMultiplePicker();
}
@@ -597,74 +412,25 @@ return $.widget( "ui.calendar", {
var i = 0;
for ( ; i < this.options.numberOfMonths; i++ ) {
- $( ".ui-calendar-title", this.picker ).eq( i ).html( this._buildTitle() );
- $( ".ui-calendar-calendar", this.picker ).eq( i ).html( this._buildGrid() );
+ $( ".ui-calendar-title", this.element ).eq( i ).html( this._buildTitle() );
+ $( ".ui-calendar-calendar", this.element ).eq( i ).html( this._buildGrid() );
this.date.adjust( "M", 1 );
}
this.date.adjust( "M", -this.options.numberOfMonths );
// TODO: This assumes focus is on the first grid. For multi pickers, the widget needs
// to maintain the currently focused grid and base queries like this off of it.
- $( this.picker ).find( ".ui-state-focus" ).not( ":first" ).removeClass( "ui-state-focus" );
- },
-
- open: function( event ) {
- if ( this.inline || this.isOpen ) {
- return;
- }
- if ( this._trigger( "beforeOpen", event ) === false ) {
- return;
- }
-
- this.refresh();
-
- this.picker
- .attr( "aria-hidden", "false" )
- .attr( "aria-expanded", "true" )
- .show()
- .position( this._buildPosition() )
- .hide();
-
- this._show( this.picker, this.options.show );
-
- // take trigger out of tab order to allow shift-tab to skip trigger
- // TODO does this really make sense? related bug: tab-shift moves focus to last element on page
- this.element.attr( "tabindex", -1 );
- this.isOpen = true;
-
- this._trigger( "open", event );
- },
-
- close: function( event ) {
- if ( this.inline ) {
- return;
- }
-
- this._setHiddenPicker();
- this._hide( this.picker, this.options.hide );
-
- this.element.attr( "tabindex" , 0 );
-
- this.isOpen = false;
- this._trigger( "close", event );
+ $( this.element ).find( ".ui-state-focus" ).not( ":first" ).removeClass( "ui-state-focus" );
},
_setHiddenPicker: function() {
- this.picker
+ this.element
.attr( "aria-hidden", "true" )
.attr( "aria-expanded", "false" );
},
- _buildPosition: function() {
- return $.extend( {}, { of: this.element }, this.options.position );
- },
-
_select: function( event, time ) {
this._setOption( "value", new Date( time ) );
- if ( !this.inline ) {
- this.close();
- this._focusTrigger();
- }
this._trigger( "select", event, {
// TODO replace with value option to initialise and read
date: this.value()
@@ -675,11 +441,7 @@ return $.widget( "ui.calendar", {
if ( arguments.length ) {
this._setOption( "value", Globalize.parseDate( value, this.options.dateFormat ) );
} else {
- if ( this.inline ) {
- return Globalize.format( this.date.selected(), this.options.dateFormat );
- } else {
- return this.element.val();
- }
+ return Globalize.format( this.option( "value" ), this.options.dateFormat );
}
},
@@ -691,36 +453,16 @@ return $.widget( "ui.calendar", {
}
},
- isValid: function() {
- if ( this.inline ) {
- return true;
- }
-
- return this._getParsedValue() !== null;
- },
-
_destroy: function() {
- if ( this.inline ) {
- this.picker.empty();
- } else {
- this.picker.remove();
- this.element
- .removeAttr( "aria-haspopup" )
- .removeAttr( "aria-owns" );
- }
- },
-
- widget: function() {
- return this.picker;
- },
-
- _getParsedValue: function() {
- return Globalize.parseDate( this.element.val(), this.options.dateFormat );
+ this.element
+ .empty()
+ .removeAttr( "aria-haspopup" )
+ .removeAttr( "aria-owns" );
},
option: function( key ) {
if ( arguments.length === 0 || ( arguments.length === 1 && key === "value" ) ) {
- this.options.value = this.inline ? this.date.selected() : this._getParsedValue();
+ this.options.value = this.date.selectedDate();
}
return this._superApply( arguments );
},
@@ -730,18 +472,11 @@ return $.widget( "ui.calendar", {
if ( value instanceof Date ) {
this.date.setTime( value.getTime() ).select();
this.refresh();
- if ( !this.inline ) {
- this.element.val( this.date.format() );
- }
}
}
this._super( key, value );
- if ( key === "appendTo" ) {
- this.picker.appendTo( this._appendTo() );
- }
-
if ( key === "eachDay" ) {
this.date.eachDay = this.options.eachDay;
this.refresh();
@@ -749,18 +484,11 @@ return $.widget( "ui.calendar", {
if ( key === "dateFormat" ) {
this.date.setFormat( this.options.dateFormat );
- if ( !this.inline ) {
- this.element.val( this.date.format() );
- }
}
if ( key === "showWeek" ) {
this.refresh();
}
-
- if ( key === "position" ) {
- this.picker.position( this._buildPosition() );
- }
}
});
From b3831f2be0ed609bf8f309aa13556628ec9f7b1d Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Wed, 4 Jun 2014 00:30:40 +0200
Subject: [PATCH 05/94] Calendar: Fix focus highlighting when month is changed
---
ui/calendar.js | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/ui/calendar.js b/ui/calendar.js
index dac8964d6c6..d41b65bd92e 100644
--- a/ui/calendar.js
+++ b/ui/calendar.js
@@ -89,8 +89,7 @@ return $.widget( "ui.calendar", {
}
event.preventDefault();
- var newId, newCell,
- activeCell = $( "#" + this.grid.attr( "aria-activedescendant" ) ),
+ var activeCell = $( "#" + this.grid.attr( "aria-activedescendant" ) ),
oldMonth = this.date.month(),
oldYear = this.date.year();
@@ -131,19 +130,17 @@ return $.widget( "ui.calendar", {
this.refresh();
this.grid.focus( 1 );
}
- else {
- newId = this.id + "-" + this.date.day();
- newCell = $( "#" + newId );
- // TODO unnecessary optimization? is it really needed?
- if ( !newCell.length ) {
- return;
- }
- this.grid.attr("aria-activedescendant", newId);
+ this._setActiveDescendant();
+ },
- this.grid.find( ".ui-state-focus" ).removeClass( "ui-state-focus" );
- newCell.children( "a" ).addClass( "ui-state-focus" );
- }
+ _setActiveDescendant: function() {
+ var newId = this.id + "-" + this.date.day(),
+ newCell = $( "#" + newId );
+
+ this.grid.attr( "aria-activedescendant", newId );
+ this.grid.find( ".ui-state-focus" ).removeClass( "ui-state-focus" );
+ newCell.children( "a" ).addClass( "ui-state-focus" );
},
_createTmpl: function() {
@@ -345,7 +342,7 @@ return $.widget( "ui.calendar", {
classes = [ "ui-state-default" ],
labels = Globalize.translate( "datepicker" );
- if ( day.date === this.date.day() ) {
+ if ( day === this.date ) {
classes.push( "ui-state-focus" );
}
if ( day.current ) {
From cb13f3ed249309b603e69df1c1fca686b3abcabb Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Wed, 4 Jun 2014 00:59:16 +0200
Subject: [PATCH 06/94] Calendar: Make use of uniqueId method
---
ui/calendar.js | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/ui/calendar.js b/ui/calendar.js
index d41b65bd92e..2790eaac99b 100644
--- a/ui/calendar.js
+++ b/ui/calendar.js
@@ -26,9 +26,6 @@
}
}(function( $ ) {
-// TODO use uniqueId, if possible
-var idIncrement = 0;
-
return $.widget( "ui.calendar", {
options: {
dateFormat: { date: "short" },
@@ -43,8 +40,7 @@ return $.widget( "ui.calendar", {
},
_create: function() {
- this.id = "ui-calendar-" + idIncrement;
- idIncrement++;
+ this.id = this.element.uniqueId().attr( "id" );
this.date = $.date( this.options.value, this.options.dateFormat ).select();
this.date.eachDay = this.options.eachDay;
@@ -453,8 +449,7 @@ return $.widget( "ui.calendar", {
_destroy: function() {
this.element
.empty()
- .removeAttr( "aria-haspopup" )
- .removeAttr( "aria-owns" );
+ .removeUniqueId();
},
option: function( key ) {
From 8bf93c27c14fd0acb09e5c88d98b48ebf5974f7a Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Wed, 4 Jun 2014 19:07:23 +0200
Subject: [PATCH 07/94] Calendar: Add _isValid method
Add a basic _isValid method for both widgets to check for valid dates.
---
ui/calendar.js | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/ui/calendar.js b/ui/calendar.js
index 2790eaac99b..decef2ba08a 100644
--- a/ui/calendar.js
+++ b/ui/calendar.js
@@ -425,7 +425,6 @@ return $.widget( "ui.calendar", {
_select: function( event, time ) {
this._setOption( "value", new Date( time ) );
this._trigger( "select", event, {
- // TODO replace with value option to initialise and read
date: this.value()
});
},
@@ -446,6 +445,11 @@ return $.widget( "ui.calendar", {
}
},
+ _isValid: function( value ) {
+ // ToDo implement min / max option
+ return ( value instanceof Date );
+ },
+
_destroy: function() {
this.element
.empty()
@@ -461,7 +465,7 @@ return $.widget( "ui.calendar", {
_setOption: function( key, value ) {
if ( key === "value" ) {
- if ( value instanceof Date ) {
+ if ( this._isValid( value ) ) {
this.date.setTime( value.getTime() ).select();
this.refresh();
}
From ac0fc77ee4b9bfaa79fd6b9a304e3ff4c63260fe Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Wed, 4 Jun 2014 19:09:16 +0200
Subject: [PATCH 08/94] Datepicker: $.date.selected() should return the actual
date object
The method should return the actual date object instead of the copied $.date
object
---
external/date.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/external/date.js b/external/date.js
index 71963981129..1bc5b836038 100644
--- a/external/date.js
+++ b/external/date.js
@@ -184,7 +184,7 @@ $.date.prototype = {
return this;
},
selectedDate: function() {
- return this.selected;
+ return this.selected.date();
},
clone: function() {
var date = this.dateObject;
From afd7e79caa83afd5a461d4af03cce1e3a19719a2 Mon Sep 17 00:00:00 2001
From: Felix Nagel
Date: Wed, 4 Jun 2014 19:13:32 +0200
Subject: [PATCH 09/94] Datepicker: Remove calendar functionality, options and
methods
---
demos/datepicker/default.html | 1 +
themes/base/datepicker.css | 172 +----------
ui/datepicker.js | 552 ++++------------------------------
3 files changed, 68 insertions(+), 657 deletions(-)
diff --git a/demos/datepicker/default.html b/demos/datepicker/default.html
index be0c453c2b3..b2439b29ab3 100644
--- a/demos/datepicker/default.html
+++ b/demos/datepicker/default.html
@@ -12,6 +12,7 @@
+
-Date:
+
-
Restrict the range of selectable dates with the minDate
and maxDate
options. Set the beginning and end dates as actual dates (new Date(2009, 1 - 1, 26)), as a numeric offset from today (-20), or as a string of periods and units ('+1M +10D'). For the last, use 'D' for days, 'W' for weeks, 'M' for months, or 'Y' for years.
+
Restrict the range of selectable dates with the min
and max
options. Set the beginning and end dates as actual dates (new Date(2009, 1 - 1, 26)).