@@ -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,25 @@ 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 && this . _getDate ( ) . year ( ) === this . _getViewDate ( ) . year ( ) ) {
195
+ this . _getViewDate ( ) . adjust ( "M" , this . options . numberOfMonths *
196
+ ( this . _getDate ( ) . month ( ) > this . _getViewDate ( ) . month ( ) ? 1 : - 1 )
197
197
) ;
198
198
} else {
199
- this . viewDate . setTimestamp ( this . date . timestamp ( ) ) ;
199
+ this . _getViewDate ( ) . setTimestamp ( this . _getDate ( ) . timestamp ( ) ) ;
200
200
}
201
201
202
202
this . refresh ( ) ;
203
203
} ,
204
204
205
205
_needsRefresh : function ( ) {
206
- if ( this . date . month ( ) !== this . viewDate . month ( ) ||
207
- this . date . year ( ) !== this . viewDate . year ( )
206
+ if ( this . _getDate ( ) . month ( ) !== this . _getViewDate ( ) . month ( ) ||
207
+ this . _getDate ( ) . year ( ) !== this . _getViewDate ( ) . year ( )
208
208
) {
209
209
210
210
// Check if the needed day is already present in our grid due
211
211
// to eachDay option changes (eg. other-months demo)
212
- return ! this . _getDateElement ( this . _getDayId ( this . date ) ) . length ;
212
+ return ! this . _getDateElement ( this . _getDayId ( this . _getDate ( ) ) ) . length ;
213
213
}
214
214
215
215
return false ;
@@ -220,7 +220,7 @@ return $.widget( "ui.calendar", {
220
220
} ,
221
221
222
222
_updateDayElement : function ( state ) {
223
- var id = this . _getDayId ( this . date ) ,
223
+ var id = this . _getDayId ( this . _getDate ( ) ) ,
224
224
button = this . _getDateElement ( id ) . children ( "button" ) ;
225
225
226
226
this . grid . attr ( "aria-activedescendant" , id ) ;
@@ -293,16 +293,16 @@ return $.widget( "ui.calendar", {
293
293
_buildMultiplePicker : function ( ) {
294
294
var element , header ,
295
295
rowBreak = $ ( "<div>" ) ,
296
- currentDate = this . viewDate ,
297
- months = this . viewDate . months ( this . options . numberOfMonths - 1 ) ,
296
+ currentDate = this . _getViewDate ( ) ,
297
+ months = this . _getViewDate ( ) . months ( this . options . numberOfMonths - 1 ) ,
298
298
labelledBy = [ ] ,
299
299
i = 0 ;
300
300
301
301
for ( ; i < months . length ; i ++ ) {
302
302
303
303
// TODO: Shouldn't we pass date as a parameter to build* fns
304
- // instead of setting this.date ?
305
- this . viewDate = months [ i ] ;
304
+ // instead of setting this.viewDate ?
305
+ this . _setViewDate ( months [ i ] ) ;
306
306
this . gridId = this . id + "-" + i ;
307
307
labelledBy . push ( this . gridId + "-title" ) ;
308
308
@@ -326,7 +326,7 @@ return $.widget( "ui.calendar", {
326
326
. attr ( "aria-labelledby" , labelledBy . join ( " " ) )
327
327
. append ( rowBreak ) ;
328
328
329
- this . viewDate = currentDate ;
329
+ this . _setViewDate ( currentDate ) ;
330
330
} ,
331
331
332
332
_buildHeaderButtons : function ( ) {
@@ -380,11 +380,11 @@ return $.widget( "ui.calendar", {
380
380
} ,
381
381
382
382
_buildTitleMonth : function ( ) {
383
- return $ ( "<span>" ) . text ( this . viewDate . monthName ( ) ) ;
383
+ return $ ( "<span>" ) . text ( this . _getViewDate ( ) . monthName ( ) ) ;
384
384
} ,
385
385
386
386
_buildTitleYear : function ( ) {
387
- return $ ( "<span>" ) . text ( this . viewDate . year ( ) ) ;
387
+ return $ ( "<span>" ) . text ( this . _getViewDate ( ) . year ( ) ) ;
388
388
} ,
389
389
390
390
_buildGrid : function ( ) {
@@ -393,7 +393,7 @@ return $.widget( "ui.calendar", {
393
393
tabindex : 0 ,
394
394
"aria-readonly" : true ,
395
395
"aria-labelledby" : this . gridId + "-month-label" ,
396
- "aria-activedescendant" : this . _getDayId ( this . date )
396
+ "aria-activedescendant" : this . _getDayId ( this . _getDate ( ) )
397
397
} ) ;
398
398
399
399
this . _addClass ( table , "ui-calendar-calendar" ) ;
@@ -408,8 +408,8 @@ return $.widget( "ui.calendar", {
408
408
week = $ ( "<th>" ) ,
409
409
row = $ ( "<tr role='row'>" ) ,
410
410
i = 0 ,
411
- weekDayLength = this . viewDate . weekdays ( ) . length ,
412
- weekdays = this . viewDate . weekdays ( ) ;
411
+ weekDayLength = this . _getViewDate ( ) . weekdays ( ) . length ,
412
+ weekdays = this . _getViewDate ( ) . weekdays ( ) ;
413
413
414
414
if ( this . options . showWeek ) {
415
415
this . _addClass ( week , "ui-calendar-week-col" ) ;
@@ -431,7 +431,7 @@ return $.widget( "ui.calendar", {
431
431
} ,
432
432
433
433
_buildGridBody : function ( ) {
434
- var days = this . viewDate . days ( ) ,
434
+ var days = this . _getViewDate ( ) . days ( ) ,
435
435
i = 0 ,
436
436
rows = "" ;
437
437
@@ -492,7 +492,7 @@ return $.widget( "ui.calendar", {
492
492
var attributes , content ,
493
493
classes = [ "ui-state-default" ] ;
494
494
495
- if ( day === this . date && selectable ) {
495
+ if ( day === this . _getDate ( ) && selectable ) {
496
496
classes . push ( "ui-state-focus" ) ;
497
497
}
498
498
if ( this . _isCurrent ( day ) ) {
@@ -616,7 +616,7 @@ return $.widget( "ui.calendar", {
616
616
} ,
617
617
618
618
_headerButtonsState : function ( ) {
619
- var months = this . viewDate . months ( this . options . numberOfMonths - 1 ) ,
619
+ var months = this . _getViewDate ( ) . months ( this . options . numberOfMonths - 1 ) ,
620
620
i = 0 ;
621
621
622
622
for ( ; i < months . length ; i ++ ) {
@@ -648,9 +648,9 @@ return $.widget( "ui.calendar", {
648
648
for ( ; i < this . options . numberOfMonths ; i ++ ) {
649
649
this . element . find ( ".ui-calendar-title" ) . eq ( i ) . replaceWith ( this . _buildTitle ( ) ) ;
650
650
this . element . find ( ".ui-calendar-calendar" ) . eq ( i ) . replaceWith ( this . _buildGrid ( ) ) ;
651
- this . viewDate . adjust ( "M" , 1 ) ;
651
+ this . _getViewDate ( ) . adjust ( "M" , 1 ) ;
652
652
}
653
- this . viewDate . adjust ( "M" , - this . options . numberOfMonths ) ;
653
+ this . _getViewDate ( ) . adjust ( "M" , - this . options . numberOfMonths ) ;
654
654
} ,
655
655
656
656
_getTranslation : function ( key ) {
@@ -664,6 +664,22 @@ return $.widget( "ui.calendar", {
664
664
} ) ;
665
665
} ,
666
666
667
+ _getDate : function ( ) {
668
+ return this . date ;
669
+ } ,
670
+
671
+ _setDate : function ( date ) {
672
+ this . date = date ;
673
+ } ,
674
+
675
+ _getViewDate : function ( ) {
676
+ return this . viewDate ;
677
+ } ,
678
+
679
+ _setViewDate : function ( date ) {
680
+ this . viewDate = date ;
681
+ } ,
682
+
667
683
value : function ( value ) {
668
684
if ( arguments . length ) {
669
685
this . valueAsDate ( this . _parse ( value ) ) ;
@@ -730,11 +746,11 @@ return $.widget( "ui.calendar", {
730
746
731
747
if ( dateAttributes ) {
732
748
this . _setLocale ( this . options . locale , this . options . dateFormat ) ;
733
- this . date . setAttributes ( this . _calendarDateOptions ) ;
734
- this . viewDate . setAttributes ( this . _calendarDateOptions ) ;
749
+ this . _getDate ( ) . setAttributes ( this . _calendarDateOptions ) ;
750
+ this . _getViewDate ( ) . setAttributes ( this . _calendarDateOptions ) ;
735
751
}
736
752
if ( create || refresh ) {
737
- this . viewDate . setTimestamp ( this . date . timestamp ( ) ) ;
753
+ this . _getViewDate ( ) . setTimestamp ( this . _getDate ( ) . timestamp ( ) ) ;
738
754
}
739
755
if ( create ) {
740
756
this . element . empty ( ) ;
@@ -750,7 +766,7 @@ return $.widget( "ui.calendar", {
750
766
_setOption : function ( key , value ) {
751
767
if ( key === "value" ) {
752
768
if ( this . _isValid ( value ) ) {
753
- this . date . setTimestamp ( value . getTime ( ) ) ;
769
+ this . _getDate ( ) . setTimestamp ( value . getTime ( ) ) ;
754
770
} else {
755
771
value = null ;
756
772
}
@@ -778,7 +794,7 @@ return $.widget( "ui.calendar", {
778
794
}
779
795
780
796
if ( key === "eachDay" ) {
781
- this . viewDate . eachDay = value ;
797
+ this . _getViewDate ( ) . eachDay = value ;
782
798
}
783
799
}
784
800
} ) ;
0 commit comments