Skip to content

Commit 8732ff7

Browse files
committed
Datepicker: Use Globalize 1.0.0
- Fix merge conflict in value method - Fix common unit tests - Fix calendar localization tests - Fix rebase regression: labels update on refresh - Add new pass through options - lint fixes
1 parent e0acb2d commit 8732ff7

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

tests/unit/calendar/common.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
define( [
2-
"lib/common",
3-
"ui/calendar",
4-
"globalize-locales"
5-
], function( common ) {
6-
7-
common.testWidget( "calendar", {
1+
TestHelpers.commonWidgetTests( "calendar", {
82
defaults: {
93
buttons: [],
10-
classes: {},
11-
dateFormat: { date: "short" },
124
disabled: false,
135
eachDay: $.noop,
6+
labels: {
7+
"datePickerRole": "date picker",
8+
"nextText": "Next",
9+
"prevText": "Prev",
10+
"weekHeader": "Wk"
11+
},
12+
locale: "en",
1413
max: null,
1514
min: null,
1615
numberOfMonths: 1,
@@ -22,5 +21,3 @@ common.testWidget( "calendar", {
2221
select: null
2322
}
2423
});
25-
26-
} );

tests/unit/calendar/core.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,18 @@ test( "base structure", function() {
8585
test( "Localization", function() {
8686
expect( 10 );
8787

88-
var defaultLocale = Globalize.locale(),
89-
element = $( "#calendar" ),
88+
var element = $( "#calendar" ),
9089
date = new Date( 2014, 0, 1 ),
91-
initCalendar = function() {
90+
optionsDe = {
91+
locale: "de",
92+
labels: {
93+
"nextText": "Vor",
94+
"prevText": "Zurück"
95+
}
96+
},
97+
initCalendar = function( options ) {
9298
element
93-
.calendar()
99+
.calendar( options )
94100
.calendar( "valueAsDate", date );
95101
},
96102
testLocalization = function( message ) {
@@ -108,26 +114,23 @@ test( "Localization", function() {
108114
);
109115
equal(
110116
element.find( ".ui-calendar-prev" ).text(),
111-
"<Zurück", message + "header prev"
117+
"Zurück", message + "header prev"
112118
);
113119
equal(
114120
element.find( ".ui-calendar-next" ).text(),
115-
"Vor>", message + "header next"
121+
"Vor", message + "header next"
116122
);
117123
};
118124

119-
Globalize.locale( "de" );
120-
initCalendar();
125+
initCalendar( optionsDe );
121126
testLocalization( "Init: " );
122127
element.calendar( "destroy" );
123128

124-
Globalize.locale( defaultLocale.locale );
125-
initCalendar();
126-
Globalize.locale( "de" );
127-
element.calendar( "refresh" );
129+
initCalendar( {} );
130+
element
131+
.calendar( "option", optionsDe )
132+
.calendar( "refresh" );
128133
testLocalization( "After init: " );
129-
130-
Globalize.locale( defaultLocale.locale );
131134
});
132135

133136
asyncTest( "keyboard handling", function() {

tests/unit/datepicker/common.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
define( [
2-
"lib/common",
3-
"ui/datepicker",
4-
"globalize-locales"
5-
], function( common ) {
6-
7-
common.testWidget( "datepicker", {
1+
TestHelpers.commonWidgetTests( "datepicker", {
82
defaults: {
93
appendTo: null,
104
buttons: [],
11-
classes: {},
12-
dateFormat: { date: "short" },
135
disabled: false,
146
eachDay: $.noop,
7+
labels: {
8+
"datePickerRole": "date picker",
9+
"nextText": "Next",
10+
"prevText": "Prev",
11+
"weekHeader": "Wk"
12+
},
13+
locale: "en",
1514
max: null,
1615
min: null,
1716
numberOfMonths: 1,
@@ -31,5 +30,3 @@ common.testWidget( "datepicker", {
3130
select: null
3231
}
3332
});
34-
35-
} );

ui/calendar.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,18 @@ return $.widget( "ui.calendar", {
180180
var globalize = new Globalize( locale ),
181181
weekdayShortFormatter = globalize.dateFormatter({ pattern: "EEEEEE" }),
182182
weekdayNarrowFormatter = globalize.dateFormatter({ pattern: "EEEEE" });
183+
183184
this._format = globalize.dateFormatter({ date: "short" });
184185
this._parse = globalize.dateParser({ date: "short" });
185186
this._calendarDateOptions = {
186-
firstDay: globalize.cldr.supplemental.weekData.firstDay(),
187-
formatWeekdayShort: function( date ) {
187+
firstDay: globalize.cldr.supplemental.weekData.firstDay(),
188+
formatWeekdayShort: function( date ) {
188189

189-
// Return the short weekday if its length is < 3. Otherwise, its narrow form.
190+
// Return the short weekday if its length is < 3. Otherwise, its narrow form.
190191
var shortWeekday = weekdayShortFormatter( date );
192+
191193
return shortWeekday.length > 3 ? weekdayNarrowFormatter( date ) : shortWeekday;
192-
},
194+
},
193195
formatWeekdayFull: globalize.dateFormatter({ pattern: "EEEE" }),
194196
formatMonth: globalize.dateFormatter({ pattern: "MMMM" }),
195197
formatWeekOfYear: globalize.dateFormatter({ pattern: "w" }),
@@ -325,7 +327,7 @@ return $.widget( "ui.calendar", {
325327
if ( this.options.showWeek ) {
326328
cells += "<th class='ui-calendar-week-col'>" + this._getTranslation( "weekHeader" ) + "</th>";
327329
}
328-
for ( i; i < weekDayLength; i++ ) {
330+
for ( ; i < weekDayLength; i++ ) {
329331
cells += this._buildGridHeaderCell( weekdays[ i ] );
330332
}
331333

@@ -492,6 +494,7 @@ return $.widget( "ui.calendar", {
492494
// with the prev and next links would cause loss of focus issues because the links being
493495
// interacted with will disappear while focused.
494496
refresh: function() {
497+
this.labels = this.options.labels;
495498

496499
// Determine which day gridcell to focus after refresh
497500
// TODO: Prevent disabled cells from being focused
@@ -541,7 +544,7 @@ return $.widget( "ui.calendar", {
541544

542545
value: function( value ) {
543546
if ( arguments.length ) {
544-
this.valueAsDate( locale.parse( value ) );
547+
this.valueAsDate( this._parse( value ) );
545548
} else {
546549
return this._format( this.option( "value" ) );
547550
}

ui/datepicker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var widget = $.widget( "ui.datepicker", {
3737
version: "@VERSION",
3838
options: {
3939
appendTo: null,
40-
locale: "en",
4140
position: {
4241
my: "left top",
4342
at: "left bottom"
@@ -52,8 +51,8 @@ var widget = $.widget( "ui.datepicker", {
5251
select: null
5352
},
5453

55-
calendarOptions: [ "buttons", "dateFormat", "disabled", "eachDay", "max",
56-
"min", "numberOfMonths", "showWeek" ],
54+
calendarOptions: [ "buttons", "disabled", "eachDay", "labels", "locale",
55+
"max", "min", "numberOfMonths", "showWeek" ],
5756

5857
_create: function() {
5958
this.suppressExpandOnFocus = false;
@@ -283,6 +282,7 @@ var widget = $.widget( "ui.datepicker", {
283282

284283
_setLocale: function( locale ) {
285284
var globalize = new Globalize( locale );
285+
286286
this._format = globalize.dateFormatter({ date: "short" });
287287
this._parse = globalize.dateParser({ date: "short" });
288288
this._parseYMD = globalize.dateParser({ pattern: "yyyy-MM-dd" });

0 commit comments

Comments
 (0)