@@ -45,6 +45,13 @@ return $.widget( "ui.calendar", {
45
45
version : "@VERSION" ,
46
46
options : {
47
47
buttons : [ ] ,
48
+ classes : {
49
+ "ui-calendar" : "ui-corner-all" ,
50
+ "ui-calendar-header-first" : "ui-corner-left" ,
51
+ "ui-calendar-header-last" : "ui-corner-right" ,
52
+ "ui-calendar-prev" : "ui-corner-all" ,
53
+ "ui-calendar-next" : "ui-corner-all"
54
+ } ,
48
55
dateFormat : { date : "short" } ,
49
56
eachDay : $ . noop ,
50
57
labels : {
@@ -119,7 +126,7 @@ return $.widget( "ui.calendar", {
119
126
} ,
120
127
121
128
_hover : function ( event ) {
122
- $ ( event . currentTarget ) . toggleClass ( "ui-state-hover" ) ;
129
+ this . _addClass ( $ ( event . currentTarget ) , null , "ui-state-hover" ) ;
123
130
} ,
124
131
125
132
_handleKeydown : function ( event ) {
@@ -193,14 +200,15 @@ return $.widget( "ui.calendar", {
193
200
} ,
194
201
195
202
_updateDayElement : function ( state ) {
196
- var id = this . _getDayId ( this . date ) ;
203
+ var id = this . _getDayId ( this . date ) ,
204
+ button = this . _getDateElement ( id ) . children ( "button" ) ;
205
+
206
+ this . grid . attr ( "aria-activedescendant" , id ) ;
197
207
198
- this . grid
199
- . attr ( "aria-activedescendant" , id )
200
- . find ( "button." + state )
201
- . removeClass ( state ) ;
208
+ this . _removeClass ( this . grid . find ( "button." + state ) , null , state ) ;
209
+ this . _addClass ( button , null , state ) ;
202
210
203
- return this . _getDateElement ( id ) . children ( " button" ) . addClass ( state ) ;
211
+ return button ;
204
212
} ,
205
213
206
214
_getDateElement : function ( id ) {
@@ -232,146 +240,161 @@ return $.widget( "ui.calendar", {
232
240
} ,
233
241
234
242
_createCalendar : function ( ) {
235
- var classes = "ui-calendar ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ,
236
- pickerHtml = this . _buildHeaderButtons ( ) ;
243
+ this . element
244
+ . attr ( "role" , "region" )
245
+ . append ( this . _buildHeaderButtons ( ) ) ;
237
246
238
247
if ( this . options . numberOfMonths === 1 ) {
239
- pickerHtml += this . _buildHeader ( ) + this . _buildGrid ( ) ;
240
- this . element . attr ( "aria-labelledby" , this . gridId + "-title" ) ;
248
+ this . _buildSinglePicker ( ) ;
241
249
} else {
242
- pickerHtml += this . _buildMultiplePicker ( ) ;
243
- classes += " ui-calendar-multi" ;
250
+ this . _buildMultiplePicker ( ) ;
244
251
}
245
252
246
- this . element
247
- . addClass ( classes )
248
- . attr ( "role" , "region" )
249
- . html ( pickerHtml ) ;
253
+ this . _addClass ( this . element , "ui-calendar" , "ui-widget ui-widget-content ui-helper-clearfix" ) ;
250
254
251
- this . prevButton = this . element . find ( ".ui-calendar-prev" ) ;
252
- this . nextButton = this . element . find ( ".ui-calendar-next" ) ;
253
255
this . _refreshHeaderButtons ( ) ;
254
-
255
256
this . _createButtonPane ( ) ;
256
257
257
258
this . grid = this . element . find ( ".ui-calendar-calendar" ) ;
258
259
} ,
259
260
261
+ _buildSinglePicker : function ( ) {
262
+ var header = this . _buildHeader ( ) ;
263
+
264
+ this . _addClass ( header , "ui-calendar-header-first ui-calendar-header-last" ) ;
265
+ this . element
266
+ . attr ( "aria-labelledby" , this . gridId + "-title" )
267
+ . append ( header )
268
+ . append ( this . _buildGrid ( ) ) ;
269
+ } ,
270
+
260
271
_buildMultiplePicker : function ( ) {
261
- var headerClass ,
262
- html = "" ,
272
+ var element , header ,
273
+ rowBreak = $ ( "<div>" ) ,
263
274
currentDate = this . viewDate ,
264
275
months = this . viewDate . months ( this . options . numberOfMonths - 1 ) ,
265
- labelledby = [ ] ,
276
+ labelledBy = [ ] ,
266
277
i = 0 ;
267
278
268
279
for ( ; i < months . length ; i ++ ) {
269
280
270
281
// TODO: Shouldn't we pass date as a parameter to build* fns instead of setting this.date?
271
282
this . viewDate = months [ i ] ;
272
283
this . gridId = this . id + "-" + i ;
284
+ labelledBy . push ( this . gridId + "-title" ) ;
273
285
274
- labelledby . push ( this . gridId + "-title" ) ;
275
- headerClass = "ui-calendar-header ui-widget-header ui-helper-clearfix" ;
276
- if ( months [ i ] . first ) {
277
- headerClass += " ui-corner-left" ;
278
- } else if ( months [ i ] . last ) {
279
- headerClass += " ui-corner-right" ;
280
- }
286
+ element = $ ( "<div>" ) ;
287
+ this . _addClass ( element , "ui-calendar-group" ) ;
281
288
282
- html += "<div class='ui-calendar-group'>" ;
283
- html += "<div class='" + headerClass + "'>" +
284
- this . _buildTitlebar ( ) + "</div>" ;
285
- html += this . _buildGrid ( ) + "</div>" ;
289
+ header = this . _buildHeader ( ) ;
290
+ this . _addClass ( header , "ui-calendar-header-" +
291
+ ( ( months [ i ] . first ) ? "first" : ( months [ i ] . last ) ? "last" : "middle" )
292
+ ) ;
293
+
294
+ element . appendTo ( this . element )
295
+ . append ( header )
296
+ . append ( this . _buildGrid ( ) ) ;
286
297
}
287
298
288
- html += "<div class='ui-calendar-row-break'></div>" ;
299
+ this . _addClass ( this . element , "ui-calendar-multi" )
300
+ . _addClass ( rowBreak , "ui-calendar-row-break" ) ;
289
301
290
- this . element . attr ( "aria-labelledby" , labelledby . join ( " " ) ) ;
302
+ this . element
303
+ . attr ( "aria-labelledby" , labelledBy . join ( " " ) )
304
+ . append ( rowBreak ) ;
291
305
292
306
this . viewDate = currentDate ;
293
-
294
- return html ;
295
- } ,
296
-
297
- _buildHeader : function ( ) {
298
- return "<div class='ui-calendar-header ui-widget-header ui-helper-clearfix ui-corner-all'>" +
299
- this . _buildTitlebar ( ) +
300
- "</div>" ;
301
307
} ,
302
308
303
309
_buildHeaderButtons : function ( ) {
304
- return "<div class='ui-calendar-header-buttons'>" +
305
- this . _buildPreviousLink ( ) +
306
- this . _buildNextLink ( ) +
307
- "</div>" ;
308
- } ,
310
+ var buttons = $ ( "<div>" ) ;
309
311
310
- _buildPreviousLink : function ( ) {
311
- return "<button class='ui-calendar-prev ui-corner-all'>" +
312
- "<span class='ui-icon ui-icon-circle-triangle-w'></span>" +
313
- "</button>" ;
314
- } ,
312
+ this . prevButton = $ ( "<button>" , {
313
+ html : "<span class='ui-icon ui-icon-circle-triangle-w'></span>"
314
+ } ) ;
315
+ this . nextButton = $ ( "<button>" , {
316
+ html : "<span class='ui-icon ui-icon-circle-triangle-e'></span>"
317
+ } ) ;
318
+
319
+ this . _addClass ( buttons , "ui-calendar-header-buttons" )
320
+ . _addClass ( this . prevButton , "ui-calendar-prev" )
321
+ . _addClass ( this . nextButton , "ui-calendar-next" ) ;
315
322
316
- _buildNextLink : function ( ) {
317
- return "<button class='ui-calendar-next ui-corner-all'>" +
318
- "<span class='ui-icon ui-icon-circle-triangle-e'></span>" +
319
- "</button>" ;
323
+ return buttons
324
+ . append ( this . prevButton )
325
+ . append ( this . nextButton ) ;
320
326
} ,
321
327
322
- _buildTitlebar : function ( ) {
323
- return "<div role='header' id='" + this . gridId + "-title'>" +
324
- "<div id='" + this . gridId + "-month-label' role='alert' class='ui-calendar-title'>" +
325
- this . _buildTitle ( ) +
326
- "</div>" +
327
- "<span class='ui-helper-hidden-accessible'>, " +
328
- this . _getTranslation ( "datePickerRole" ) +
329
- "</span>" +
330
- "</div>" ;
328
+ _buildHeader : function ( ) {
329
+ var header = $ ( "<div>" ) ,
330
+ title = $ ( "<div>" , { role : "header" , id : this . gridId + "-title" } ) ,
331
+ notice = $ ( "<span>" ) . text ( ", " + this . _getTranslation ( "datePickerRole" ) ) ;
332
+
333
+ this . _addClass ( header , "ui-calendar-header" , "ui-widget-header ui-helper-clearfix" )
334
+ . _addClass ( notice , null , "ui-helper-hidden-accessible" ) ;
335
+
336
+ return header . append (
337
+ title
338
+ . append ( this . _buildTitle ( ) )
339
+ . append ( notice )
340
+ ) ;
331
341
} ,
332
342
333
343
_buildTitle : function ( ) {
334
- return "<span class='ui-calendar-month'>" +
335
- this . viewDate . monthName ( ) +
336
- "</span> " +
337
- "<span class='ui-calendar-year'>" +
338
- this . viewDate . year ( ) +
339
- "</span>" ;
344
+ var title = $ ( "<div>" , { role : "alert" , id : this . gridId + "-month-label" } ) ,
345
+ month = $ ( "<span>" ) . text ( this . viewDate . monthName ( ) ) ,
346
+ year = $ ( "<span>" ) . text ( this . viewDate . year ( ) ) ;
347
+
348
+ this . _addClass ( title , "ui-calendar-title" )
349
+ . _addClass ( month , "ui-calendar-month" )
350
+ . _addClass ( year , "ui-calendar-year" ) ;
351
+
352
+ return title
353
+ . append ( month )
354
+ . append ( " " )
355
+ . append ( year ) ;
340
356
} ,
341
357
342
358
_buildGrid : function ( ) {
343
- return "<table class='ui-calendar-calendar' role='grid' aria-readonly='true' " +
344
- "aria-labelledby='" + this . gridId + "-month-label' tabindex='0' " +
345
- "aria-activedescendant='" + this . _getDayId ( this . date ) + "'>" +
346
- this . _buildGridHeading ( ) +
347
- this . _buildGridBody ( ) +
348
- "</table>" ;
359
+ var table = $ ( "<table>" , {
360
+ role : "grid" ,
361
+ tabindex : 0 ,
362
+ "aria-readonly" : true ,
363
+ "aria-labelledby" : this . gridId + "-month-label" ,
364
+ "aria-activedescendant" : this . _getDayId ( this . date )
365
+ } ) ;
366
+
367
+ this . _addClass ( table , "ui-calendar-calendar" ) ;
368
+
369
+ return table
370
+ . append ( this . _buildGridHeading ( ) )
371
+ . append ( this . _buildGridBody ( ) ) ;
349
372
} ,
350
373
351
374
_buildGridHeading : function ( ) {
352
- var cells = "" ,
375
+ var head = $ ( "<thead role='presentation'>" ) ,
376
+ week = $ ( "<th>" ) ,
377
+ row = $ ( "<tr role='row'>" ) ,
353
378
i = 0 ,
354
379
weekDayLength = this . viewDate . weekdays ( ) . length ,
355
380
weekdays = this . viewDate . weekdays ( ) ;
356
381
357
382
if ( this . options . showWeek ) {
358
- cells += "<th class='ui-calendar-week-col'>" + this . _getTranslation ( "weekHeader" ) + "</th>" ;
383
+ this . _addClass ( week , "ui-calendar-week-col" ) ;
384
+ row . append ( week . text ( this . _getTranslation ( "weekHeader" ) ) ) ;
359
385
}
386
+
360
387
for ( ; i < weekDayLength ; i ++ ) {
361
- cells += this . _buildGridHeaderCell ( weekdays [ i ] ) ;
388
+ row . append ( this . _buildGridHeaderCell ( weekdays [ i ] ) ) ;
362
389
}
363
390
364
- return "<thead role='presentation'>" +
365
- "<tr role='row'>" + cells + "</tr>" +
366
- "</thead>" ;
391
+ return head . append ( row ) ;
367
392
} ,
368
393
369
394
_buildGridHeaderCell : function ( day ) {
370
- return "<th role='columnheader' abbr='" + day . fullname + "' aria-label='" + day . fullname + "'>" +
371
- "<span title='" + day . fullname + "'>" +
372
- day . shortname +
373
- "</span>" +
374
- "</th>" ;
395
+ return $ ( "<th role='columnheader' abbr='" + day . fullname + "' aria-label='" + day . fullname + "'>" +
396
+ "<span title='" + day . fullname + "'>" + day . shortname + "</span>" +
397
+ "</th>" ) ;
375
398
} ,
376
399
377
400
_buildGridBody : function ( ) {
@@ -468,12 +491,11 @@ return $.widget( "ui.calendar", {
468
491
} ,
469
492
470
493
_createButtonPane : function ( ) {
471
- this . buttonPane = $ ( "<div>" )
472
- . addClass ( "ui-calendar-buttonpane ui-widget-content ui-helper-clearfix" ) ;
494
+ this . buttonPane = $ ( "<div>" ) ;
495
+ this . buttonSet = $ ( "<div>" ) . appendTo ( this . buttonPane ) ;
473
496
474
- this . buttonSet = $ ( "<div>" )
475
- . addClass ( "ui-calendar-buttonset" )
476
- . appendTo ( this . buttonPane ) ;
497
+ this . _addClass ( this . buttonPane , "ui-calendar-buttonpane" , "ui-widget-content ui-helper-clearfix" )
498
+ . _addClass ( this . buttonSet , "ui-calendar-buttonset" ) ;
477
499
478
500
this . _createButtons ( ) ;
479
501
} ,
@@ -486,7 +508,7 @@ return $.widget( "ui.calendar", {
486
508
this . buttonSet . empty ( ) ;
487
509
488
510
if ( $ . isEmptyObject ( buttons ) || ( $ . isArray ( buttons ) && ! buttons . length ) ) {
489
- this . element . removeClass ( "ui-calendar-buttons" ) ;
511
+ this . _removeClass ( this . element , "ui-calendar-buttons" ) ;
490
512
return ;
491
513
}
492
514
@@ -519,7 +541,8 @@ return $.widget( "ui.calendar", {
519
541
click . apply ( that . buttonClickContext , arguments ) ;
520
542
} ) ;
521
543
} ) ;
522
- this . element . addClass ( "ui-calendar-buttons" ) ;
544
+
545
+ this . _addClass ( this . element , "ui-calendar-buttons" ) ;
523
546
this . buttonPane . appendTo ( this . element ) ;
524
547
} ,
525
548
@@ -532,15 +555,15 @@ return $.widget( "ui.calendar", {
532
555
// Determine which day grid cell to focus after refresh
533
556
// TODO: Prevent disabled cells from being focused
534
557
if ( this . options . numberOfMonths === 1 ) {
535
- this . element . find ( ".ui-calendar-title" ) . html ( this . _buildTitle ( ) ) ;
558
+ this . element . find ( ".ui-calendar-title" ) . replaceWith ( this . _buildTitle ( ) ) ;
536
559
this . element . find ( ".ui-calendar-calendar" ) . replaceWith ( this . _buildGrid ( ) ) ;
537
560
} else {
538
561
this . _refreshMultiplePicker ( ) ;
539
562
}
540
563
541
564
this . grid = this . element . find ( ".ui-calendar-calendar" ) ;
542
- this . _setActiveDescendant ( ) ;
543
565
566
+ this . _setActiveDescendant ( ) ;
544
567
this . _refreshHeaderButtons ( ) ;
545
568
this . _createButtons ( ) ;
546
569
} ,
@@ -577,17 +600,16 @@ return $.widget( "ui.calendar", {
577
600
} ,
578
601
579
602
_disableElement : function ( element , state ) {
580
- element
581
- . attr ( "aria-disabled" , state )
582
- . toggleClass ( "ui-state-disabled" , state ) ;
603
+ element . attr ( "aria-disabled" , state ) ;
604
+ this . _toggleClass ( element , null , "ui-state-disabled" , state ) ;
583
605
} ,
584
606
585
607
_refreshMultiplePicker : function ( ) {
586
608
var i = 0 ;
587
609
588
610
for ( ; i < this . options . numberOfMonths ; i ++ ) {
589
- this . element . find ( ".ui-calendar-title" ) . eq ( i ) . html ( this . _buildTitle ( ) ) ;
590
- this . element . find ( ".ui-calendar-calendar" ) . eq ( i ) . html ( this . _buildGrid ( ) ) ;
611
+ this . element . find ( ".ui-calendar-title" ) . eq ( i ) . replaceWith ( this . _buildTitle ( ) ) ;
612
+ this . element . find ( ".ui-calendar-calendar" ) . eq ( i ) . replaceWith ( this . _buildGrid ( ) ) ;
591
613
this . viewDate . adjust ( "M" , 1 ) ;
592
614
}
593
615
this . viewDate . adjust ( "M" , - this . options . numberOfMonths ) ;
@@ -642,8 +664,6 @@ return $.widget( "ui.calendar", {
642
664
643
665
_destroy : function ( ) {
644
666
this . element
645
- . off ( ".calendar" )
646
- . removeClass ( "ui-calendar ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-calendar-multi" )
647
667
. removeAttr ( "role aria-labelledby" )
648
668
. removeUniqueId ( )
649
669
. empty ( ) ;
0 commit comments