@@ -95,19 +95,19 @@ return $.widget( "ui.calendar", {
95
95
96
96
this . _setLocale ( this . options . locale , this . options . dateFormat ) ;
97
97
98
- this . date = new $ . ui . date ( this . options . value , this . _calendarDateOptions ) ;
99
- this . viewDate = this . date . clone ( ) ;
100
- this . viewDate . eachDay = this . options . eachDay ;
98
+ this . _setDate ( new $ . ui . date ( this . options . value , this . _calendarDateOptions ) ) ;
99
+ this . _setViewDate ( this . _getDate ( ) . clone ( ) ) ;
100
+ this . _getViewDate ( ) . eachDay = this . options . eachDay ;
101
101
102
102
this . _on ( this . element , {
103
103
"click .ui-calendar-prev" : function ( event ) {
104
104
event . preventDefault ( ) ;
105
- this . date . adjust ( "M" , - this . options . numberOfMonths ) ;
105
+ this . _getDate ( ) . adjust ( "M" , - this . options . numberOfMonths ) ;
106
106
this . _updateView ( ) ;
107
107
} ,
108
108
"click .ui-calendar-next" : function ( event ) {
109
109
event . preventDefault ( ) ;
110
- this . date . adjust ( "M" , this . options . numberOfMonths ) ;
110
+ this . _getDate ( ) . adjust ( "M" , this . options . numberOfMonths ) ;
111
111
this . _updateView ( ) ;
112
112
} ,
113
113
"mousedown .ui-calendar-calendar button" : "_select" ,
@@ -155,28 +155,28 @@ return $.widget( "ui.calendar", {
155
155
) ;
156
156
return ;
157
157
case $ . ui . keyCode . PAGE_UP :
158
- this . date . adjust ( pageAltKey ? "Y" : "M" , - 1 ) ;
158
+ this . _getDate ( ) . adjust ( pageAltKey ? "Y" : "M" , - 1 ) ;
159
159
break ;
160
160
case $ . ui . keyCode . PAGE_DOWN :
161
- this . date . adjust ( pageAltKey ? "Y" : "M" , 1 ) ;
161
+ this . _getDate ( ) . adjust ( pageAltKey ? "Y" : "M" , 1 ) ;
162
162
break ;
163
163
case $ . ui . keyCode . END :
164
- this . date . setDay ( this . date . daysInMonth ( ) ) ;
164
+ this . _getDate ( ) . setDay ( this . _getDate ( ) . daysInMonth ( ) ) ;
165
165
break ;
166
166
case $ . ui . keyCode . HOME :
167
- this . date . setDay ( 1 ) ;
167
+ this . _getDate ( ) . setDay ( 1 ) ;
168
168
break ;
169
169
case $ . ui . keyCode . LEFT :
170
- this . date . adjust ( "D" , - 1 ) ;
170
+ this . _getDate ( ) . adjust ( "D" , - 1 ) ;
171
171
break ;
172
172
case $ . ui . keyCode . UP :
173
- this . date . adjust ( "D" , - 7 ) ;
173
+ this . _getDate ( ) . adjust ( "D" , - 7 ) ;
174
174
break ;
175
175
case $ . ui . keyCode . RIGHT :
176
- this . date . adjust ( "D" , 1 ) ;
176
+ this . _getDate ( ) . adjust ( "D" , 1 ) ;
177
177
break ;
178
178
case $ . ui . keyCode . DOWN :
179
- this . date . adjust ( "D" , 7 ) ;
179
+ this . _getDate ( ) . adjust ( "D" , 7 ) ;
180
180
break ;
181
181
default :
182
182
return ;
@@ -191,25 +191,27 @@ return $.widget( "ui.calendar", {
191
191
} ,
192
192
193
193
_updateView : function ( ) {
194
- if ( this . options . numberOfMonths > 1 && this . date . year ( ) === this . viewDate . year ( ) ) {
195
- this . viewDate . adjust ( "M" , this . options . numberOfMonths *
196
- ( this . date . month ( ) > this . viewDate . month ( ) ? 1 : - 1 )
194
+ if ( this . options . numberOfMonths > 1 &&
195
+ this . _getDate ( ) . year ( ) === this . _getViewDate ( ) . year ( )
196
+ ) {
197
+ this . _getViewDate ( ) . adjust ( "M" , this . options . numberOfMonths *
198
+ ( this . _getDate ( ) . month ( ) > this . _getViewDate ( ) . month ( ) ? 1 : - 1 )
197
199
) ;
198
200
} else {
199
- this . viewDate . setTimestamp ( this . date . timestamp ( ) ) ;
201
+ this . _getViewDate ( ) . setTimestamp ( this . _getDate ( ) . timestamp ( ) ) ;
200
202
}
201
203
202
204
this . refresh ( ) ;
203
205
} ,
204
206
205
207
_needsRefresh : function ( ) {
206
- if ( this . date . month ( ) !== this . viewDate . month ( ) ||
207
- this . date . year ( ) !== this . viewDate . year ( )
208
+ if ( this . _getDate ( ) . month ( ) !== this . _getViewDate ( ) . month ( ) ||
209
+ this . _getDate ( ) . year ( ) !== this . _getViewDate ( ) . year ( )
208
210
) {
209
211
210
212
// Check if the needed day is already present in our grid due
211
213
// to eachDay option changes (eg. other-months demo)
212
- return ! this . _getDateElement ( this . _getDayId ( this . date ) ) . length ;
214
+ return ! this . _getDateElement ( this . _getDayId ( this . _getDate ( ) ) ) . length ;
213
215
}
214
216
215
217
return false ;
@@ -220,7 +222,7 @@ return $.widget( "ui.calendar", {
220
222
} ,
221
223
222
224
_updateDayElement : function ( state ) {
223
- var id = this . _getDayId ( this . date ) ,
225
+ var id = this . _getDayId ( this . _getDate ( ) ) ,
224
226
button = this . _getDateElement ( id ) . children ( "button" ) ;
225
227
226
228
this . grid . attr ( "aria-activedescendant" , id ) ;
@@ -293,16 +295,16 @@ return $.widget( "ui.calendar", {
293
295
_buildMultiplePicker : function ( ) {
294
296
var element , header ,
295
297
rowBreak = $ ( "<div>" ) ,
296
- currentDate = this . viewDate ,
297
- months = this . viewDate . months ( this . options . numberOfMonths - 1 ) ,
298
+ currentDate = this . _getViewDate ( ) ,
299
+ months = this . _getViewDate ( ) . months ( this . options . numberOfMonths - 1 ) ,
298
300
labelledBy = [ ] ,
299
301
i = 0 ;
300
302
301
303
for ( ; i < months . length ; i ++ ) {
302
304
303
305
// TODO: Shouldn't we pass date as a parameter to build* fns
304
- // instead of setting this.date ?
305
- this . viewDate = months [ i ] ;
306
+ // instead of setting this.viewDate ?
307
+ this . _setViewDate ( months [ i ] ) ;
306
308
this . gridId = this . id + "-" + i ;
307
309
labelledBy . push ( this . gridId + "-title" ) ;
308
310
@@ -326,7 +328,7 @@ return $.widget( "ui.calendar", {
326
328
. attr ( "aria-labelledby" , labelledBy . join ( " " ) )
327
329
. append ( rowBreak ) ;
328
330
329
- this . viewDate = currentDate ;
331
+ this . _setViewDate ( currentDate ) ;
330
332
} ,
331
333
332
334
_buildHeaderButtons : function ( ) {
@@ -380,11 +382,11 @@ return $.widget( "ui.calendar", {
380
382
} ,
381
383
382
384
_buildTitleMonth : function ( ) {
383
- return $ ( "<span>" ) . text ( this . viewDate . monthName ( ) ) ;
385
+ return $ ( "<span>" ) . text ( this . _getViewDate ( ) . monthName ( ) ) ;
384
386
} ,
385
387
386
388
_buildTitleYear : function ( ) {
387
- return $ ( "<span>" ) . text ( this . viewDate . year ( ) ) ;
389
+ return $ ( "<span>" ) . text ( this . _getViewDate ( ) . year ( ) ) ;
388
390
} ,
389
391
390
392
_buildGrid : function ( ) {
@@ -393,7 +395,7 @@ return $.widget( "ui.calendar", {
393
395
tabindex : 0 ,
394
396
"aria-readonly" : true ,
395
397
"aria-labelledby" : this . gridId + "-month-label" ,
396
- "aria-activedescendant" : this . _getDayId ( this . date )
398
+ "aria-activedescendant" : this . _getDayId ( this . _getDate ( ) )
397
399
} ) ;
398
400
399
401
this . _addClass ( table , "ui-calendar-calendar" ) ;
@@ -408,8 +410,8 @@ return $.widget( "ui.calendar", {
408
410
week = $ ( "<th>" ) ,
409
411
row = $ ( "<tr role='row'>" ) ,
410
412
i = 0 ,
411
- weekDayLength = this . viewDate . weekdays ( ) . length ,
412
- weekdays = this . viewDate . weekdays ( ) ;
413
+ weekDayLength = this . _getViewDate ( ) . weekdays ( ) . length ,
414
+ weekdays = this . _getViewDate ( ) . weekdays ( ) ;
413
415
414
416
if ( this . options . showWeek ) {
415
417
this . _addClass ( week , "ui-calendar-week-col" ) ;
@@ -431,7 +433,7 @@ return $.widget( "ui.calendar", {
431
433
} ,
432
434
433
435
_buildGridBody : function ( ) {
434
- var days = this . viewDate . days ( ) ,
436
+ var days = this . _getViewDate ( ) . days ( ) ,
435
437
i = 0 ,
436
438
rows = "" ;
437
439
@@ -492,7 +494,7 @@ return $.widget( "ui.calendar", {
492
494
var attributes , content ,
493
495
classes = [ "ui-state-default" ] ;
494
496
495
- if ( day === this . date && selectable ) {
497
+ if ( day === this . _getDate ( ) && selectable ) {
496
498
classes . push ( "ui-state-focus" ) ;
497
499
}
498
500
if ( this . _isCurrent ( day ) ) {
@@ -616,7 +618,7 @@ return $.widget( "ui.calendar", {
616
618
} ,
617
619
618
620
_headerButtonsState : function ( ) {
619
- var months = this . viewDate . months ( this . options . numberOfMonths - 1 ) ,
621
+ var months = this . _getViewDate ( ) . months ( this . options . numberOfMonths - 1 ) ,
620
622
i = 0 ;
621
623
622
624
for ( ; i < months . length ; i ++ ) {
@@ -648,9 +650,9 @@ return $.widget( "ui.calendar", {
648
650
for ( ; i < this . options . numberOfMonths ; i ++ ) {
649
651
this . element . find ( ".ui-calendar-title" ) . eq ( i ) . replaceWith ( this . _buildTitle ( ) ) ;
650
652
this . element . find ( ".ui-calendar-calendar" ) . eq ( i ) . replaceWith ( this . _buildGrid ( ) ) ;
651
- this . viewDate . adjust ( "M" , 1 ) ;
653
+ this . _getViewDate ( ) . adjust ( "M" , 1 ) ;
652
654
}
653
- this . viewDate . adjust ( "M" , - this . options . numberOfMonths ) ;
655
+ this . _getViewDate ( ) . adjust ( "M" , - this . options . numberOfMonths ) ;
654
656
} ,
655
657
656
658
_getTranslation : function ( key ) {
@@ -664,6 +666,22 @@ return $.widget( "ui.calendar", {
664
666
} ) ;
665
667
} ,
666
668
669
+ _getDate : function ( ) {
670
+ return this . date ;
671
+ } ,
672
+
673
+ _setDate : function ( date ) {
674
+ this . date = date ;
675
+ } ,
676
+
677
+ _getViewDate : function ( ) {
678
+ return this . viewDate ;
679
+ } ,
680
+
681
+ _setViewDate : function ( date ) {
682
+ this . viewDate = date ;
683
+ } ,
684
+
667
685
value : function ( value ) {
668
686
if ( arguments . length ) {
669
687
this . valueAsDate ( this . _parse ( value ) ) ;
@@ -730,11 +748,11 @@ return $.widget( "ui.calendar", {
730
748
731
749
if ( dateAttributes ) {
732
750
this . _setLocale ( this . options . locale , this . options . dateFormat ) ;
733
- this . date . setAttributes ( this . _calendarDateOptions ) ;
734
- this . viewDate . setAttributes ( this . _calendarDateOptions ) ;
751
+ this . _getDate ( ) . setAttributes ( this . _calendarDateOptions ) ;
752
+ this . _getViewDate ( ) . setAttributes ( this . _calendarDateOptions ) ;
735
753
}
736
754
if ( create || refresh ) {
737
- this . viewDate . setTimestamp ( this . date . timestamp ( ) ) ;
755
+ this . _getViewDate ( ) . setTimestamp ( this . _getDate ( ) . timestamp ( ) ) ;
738
756
}
739
757
if ( create ) {
740
758
this . element . empty ( ) ;
@@ -750,7 +768,7 @@ return $.widget( "ui.calendar", {
750
768
_setOption : function ( key , value ) {
751
769
if ( key === "value" ) {
752
770
if ( this . _isValid ( value ) ) {
753
- this . date . setTimestamp ( value . getTime ( ) ) ;
771
+ this . _getDate ( ) . setTimestamp ( value . getTime ( ) ) ;
754
772
} else {
755
773
value = null ;
756
774
}
@@ -778,7 +796,7 @@ return $.widget( "ui.calendar", {
778
796
}
779
797
780
798
if ( key === "eachDay" ) {
781
- this . viewDate . eachDay = value ;
799
+ this . _getViewDate ( ) . eachDay = value ;
782
800
}
783
801
}
784
802
} ) ;
0 commit comments