@@ -49,14 +49,17 @@ export default {
49
49
let past = this .daily .pastBreakPoints ;
50
50
let future = this .daily .monthBreakPoints ;
51
51
let off = Math .abs (this .daily .realOffset ) + this .$refs .monthly .parentNode .clientWidth / 2 ;
52
+ if (this .daily .realOffset === 0 ) off = 1 ;
53
+ let changed = false ;
52
54
while (off <= past[past .length - 1 ].offset ) {
53
55
future .unshift (past .pop ());
54
- this . toggleSelectMonth ( null , past[ past . length - 1 ]) ;
56
+ changed = true ;
55
57
}
56
58
while (future .length > 0 && off >= future[0 ].offset ) {
57
- this .toggleSelectMonth (null , future[0 ]);
58
59
past .push (future .shift ());
60
+ changed = true ;
59
61
}
62
+ if (changed) this .toggleSelectMonth (null , past[past .length - 1 ]);
60
63
return past[past .length - 1 ];
61
64
},
62
65
},
@@ -86,8 +89,8 @@ export default {
86
89
pastBreakPoints: [
87
90
{
88
91
offset: 0 ,
89
- monthNumber: new Date ().getMonth (),
90
- fullYear: new Date ().getFullYear (),
92
+ monthNumber: ` ${ new Date ().getMonth ()} ` ,
93
+ fullYear: ` ${ new Date ().getFullYear ()} ` ,
91
94
},
92
95
],
93
96
phase: ' sleep' ,
@@ -108,7 +111,6 @@ export default {
108
111
this [state].realOffset + Math .floor (elem .clientWidth / cell .clientWidth ) * cell .clientWidth ;
109
112
if (this [state].realOffset > 0 ) this [state].realOffset = 0 ;
110
113
this .$refs [state].style .left = ` ${ this [state].realOffset } px` ;
111
- this .currentMonth ;
112
114
},
113
115
goRight (e , state ) {
114
116
let elem = e .target .parentNode .querySelector (' .ui-draggable' );
@@ -118,7 +120,6 @@ export default {
118
120
if (this [state].realOffset < this [state].maxOffset )
119
121
this [state].realOffset = this [state].maxOffset ;
120
122
this .$refs [state].style .left = ` ${ this [state].realOffset } px` ;
121
- this .currentMonth ;
122
123
},
123
124
handleDrag (e ) {
124
125
let state;
@@ -169,6 +170,7 @@ export default {
169
170
const id = ` [year="${ month .fullYear } "][month="${ month .monthNumber } "].cal-cell` ;
170
171
this .scrollIntoView (this .$refs .daily .querySelector (id));
171
172
}
173
+ this .checkMonthIsInView ();
172
174
},
173
175
toggleSelect (e , day ) {
174
176
let exist = this .$refs .daily .querySelector (' .cal-cell[selected="true"]' );
@@ -216,6 +218,23 @@ export default {
216
218
if (d .style .left .slice (0 , - 2 ) < d .maxOffset ) d .style .left = ` ${ d .maxOffset } px` ;
217
219
if (m .style .left .slice (0 , - 2 ) < m .maxOffset ) m .style .left = ` ${ m .maxOffset } px` ;
218
220
},
221
+ checkMonthIsInView () {
222
+ const sel = this .$refs .monthly .querySelector (' [selected="true"]' );
223
+ if (sel) {
224
+ const cw = sel .parentNode .parentNode .clientWidth ;
225
+ const m = this .monthly ;
226
+ if (sel .offsetLeft > - m .realOffset - sel .clientWidth + cw) {
227
+ m .realOffset = - sel .offsetLeft - sel .clientWidth / 2 + cw / 2 ;
228
+ if (m .realOffset < m .maxOffset ) m .realOffset = m .maxOffset ;
229
+ m .style .left = ` ${ m .realOffset } px` ;
230
+ }
231
+ if (- sel .offsetLeft > m .realOffset ) {
232
+ m .realOffset = - sel .offsetLeft - sel .clientWidth / 2 + cw / 2 ;
233
+ if (m .realOffset > 0 ) m .realOffset = 0 ;
234
+ m .style .left = ` ${ m .realOffset } px` ;
235
+ }
236
+ }
237
+ },
219
238
},
220
239
created () {
221
240
this .calendar = buildCalendar (
@@ -250,6 +269,9 @@ export default {
250
269
this .monthly .style = this .$refs .monthly .style ;
251
270
this .maxOffsets ();
252
271
},
272
+ updated () {
273
+ this .currentMonth ;
274
+ },
253
275
beforeDestroy () {
254
276
document .body .removeEventListener (' mouseup' , e => this .handleDrag (e), false );
255
277
document .body .removeEventListener (' mouseleave' , e => this .handleDrag (e), false );
0 commit comments