|
648 | 648 | open: open, |
649 | 649 | redraw: redrawDatePicker, |
650 | 650 | getDatePicker: getDatePicker, |
| 651 | + resetMonthsView: resetMonthsView, |
651 | 652 | destroy: function() |
652 | 653 | { |
653 | 654 | $(self).unbind('.datepicker'); |
|
706 | 707 | box.find('.apply-btn').hide(); |
707 | 708 | } |
708 | 709 |
|
709 | | - var defaultTime = opt.defaultTime ? opt.defaultTime : new Date(); |
710 | | - if (opt.lookBehind) |
711 | | - { |
712 | | - if (opt.startDate && compare_month(defaultTime, opt.startDate) < 0 ) defaultTime = nextMonth(moment(opt.startDate).toDate()); |
713 | | - if (opt.endDate && compare_month(defaultTime,opt.endDate) > 0 ) defaultTime = moment(opt.endDate).toDate(); |
714 | | - |
715 | | - showMonth(prevMonth(defaultTime),'month1'); |
716 | | - showMonth(defaultTime,'month2'); |
717 | | - |
718 | | - } |
719 | | - else |
720 | | - { |
721 | | - if (opt.startDate && compare_month(defaultTime,opt.startDate) < 0 ) defaultTime = moment(opt.startDate).toDate(); |
722 | | - if (opt.endDate && compare_month(nextMonth(defaultTime),opt.endDate) > 0 ) defaultTime = prevMonth(moment(opt.endDate).toDate()); |
723 | | - |
724 | | - showMonth(defaultTime,'month1'); |
725 | | - showMonth(nextMonth(defaultTime),'month2'); |
726 | | - } |
727 | | - |
728 | | - if (opt.singleDate) |
729 | | - { |
730 | | - if (opt.startDate && compare_month(defaultTime,opt.startDate) < 0 ) defaultTime = moment(opt.startDate).toDate(); |
731 | | - if (opt.endDate && compare_month(defaultTime,opt.endDate) > 0 ) defaultTime = moment(opt.endDate).toDate(); |
732 | | - |
733 | | - showMonth(defaultTime,'month1'); |
734 | | - } |
| 710 | + var defaultTime = getDefaultTime(); |
| 711 | + resetMonthsView(defaultTime); |
735 | 712 |
|
736 | 713 | if (opt.time.enabled) |
737 | 714 | { |
|
2260 | 2237 | return re; |
2261 | 2238 | } |
2262 | 2239 |
|
| 2240 | + function getDefaultTime() |
| 2241 | + { |
| 2242 | + var defaultTime = opt.defaultTime ? opt.defaultTime : new Date(); |
| 2243 | + |
| 2244 | + if (opt.lookBehind) |
| 2245 | + { |
| 2246 | + if (opt.startDate && compare_month(defaultTime, opt.startDate) < 0 ) defaultTime = nextMonth(moment(opt.startDate).toDate()); |
| 2247 | + if (opt.endDate && compare_month(defaultTime,opt.endDate) > 0 ) defaultTime = moment(opt.endDate).toDate(); |
| 2248 | + } |
| 2249 | + else |
| 2250 | + { |
| 2251 | + if (opt.startDate && compare_month(defaultTime,opt.startDate) < 0 ) defaultTime = moment(opt.startDate).toDate(); |
| 2252 | + if (opt.endDate && compare_month(nextMonth(defaultTime),opt.endDate) > 0 ) defaultTime = prevMonth(moment(opt.endDate).toDate()); |
| 2253 | + } |
| 2254 | + |
| 2255 | + if (opt.singleDate) |
| 2256 | + { |
| 2257 | + if (opt.startDate && compare_month(defaultTime,opt.startDate) < 0 ) defaultTime = moment(opt.startDate).toDate(); |
| 2258 | + if (opt.endDate && compare_month(defaultTime,opt.endDate) > 0 ) defaultTime = moment(opt.endDate).toDate(); |
| 2259 | + } |
| 2260 | + |
| 2261 | + return defaultTime; |
| 2262 | + } |
| 2263 | + |
| 2264 | + function resetMonthsView(time) |
| 2265 | + { |
| 2266 | + if (!time) { |
| 2267 | + time = getDefaultTime(); |
| 2268 | + } |
| 2269 | + |
| 2270 | + if (opt.lookBehind) |
| 2271 | + { |
| 2272 | + showMonth(prevMonth(time),'month1'); |
| 2273 | + showMonth(time,'month2'); |
| 2274 | + } |
| 2275 | + else |
| 2276 | + { |
| 2277 | + showMonth(time,'month1'); |
| 2278 | + showMonth(nextMonth(time),'month2'); |
| 2279 | + } |
| 2280 | + |
| 2281 | + if (opt.singleDate) |
| 2282 | + { |
| 2283 | + showMonth(time,'month1'); |
| 2284 | + } |
| 2285 | + |
| 2286 | + showSelectedDays(); |
| 2287 | + showGap(); |
| 2288 | + } |
2263 | 2289 |
|
2264 | 2290 | }; |
2265 | 2291 | })); |
0 commit comments