(e: MouseEvent | KeyboardEvent)
| 2317 | } |
| 2318 | |
| 2319 | function selectDate(e: MouseEvent | KeyboardEvent) { |
| 2320 | e.preventDefault(); |
| 2321 | e.stopPropagation(); |
| 2322 | |
| 2323 | const isSelectable = (day: Element) => |
| 2324 | day.classList && |
| 2325 | day.classList.contains("flatpickr-day") && |
| 2326 | !day.classList.contains("flatpickr-disabled") && |
| 2327 | !day.classList.contains("notAllowed"); |
| 2328 | |
| 2329 | const t = findParent(getEventTarget(e) as Element, isSelectable); |
| 2330 | |
| 2331 | if (t === undefined) return; |
| 2332 | |
| 2333 | const target = t as DayElement; |
| 2334 | |
| 2335 | const selectedDate = (self.latestSelectedDateObj = new Date( |
| 2336 | target.dateObj.getTime() |
| 2337 | )); |
| 2338 | |
| 2339 | const shouldChangeMonth = |
| 2340 | (selectedDate.getMonth() < self.currentMonth || |
| 2341 | selectedDate.getMonth() > |
| 2342 | self.currentMonth + self.config.showMonths - 1) && |
| 2343 | self.config.mode !== "range"; |
| 2344 | |
| 2345 | self.selectedDateElem = target; |
| 2346 | |
| 2347 | if (self.config.mode === "single") self.selectedDates = [selectedDate]; |
| 2348 | else if (self.config.mode === "multiple") { |
| 2349 | const selectedIndex = isDateSelected(selectedDate); |
| 2350 | |
| 2351 | if (selectedIndex) self.selectedDates.splice(parseInt(selectedIndex), 1); |
| 2352 | else self.selectedDates.push(selectedDate); |
| 2353 | } else if (self.config.mode === "range") { |
| 2354 | if (self.selectedDates.length === 2) { |
| 2355 | self.clear(false, false); |
| 2356 | } |
| 2357 | self.latestSelectedDateObj = selectedDate; |
| 2358 | self.selectedDates.push(selectedDate); |
| 2359 | |
| 2360 | // unless selecting same date twice, sort ascendingly |
| 2361 | if (compareDates(selectedDate, self.selectedDates[0], true) !== 0) |
| 2362 | self.selectedDates.sort((a, b) => a.getTime() - b.getTime()); |
| 2363 | } |
| 2364 | |
| 2365 | setHoursFromInputs(); |
| 2366 | |
| 2367 | if (shouldChangeMonth) { |
| 2368 | const isNewYear = self.currentYear !== selectedDate.getFullYear(); |
| 2369 | self.currentYear = selectedDate.getFullYear(); |
| 2370 | self.currentMonth = selectedDate.getMonth(); |
| 2371 | |
| 2372 | if (isNewYear) { |
| 2373 | triggerEvent("onYearChange"); |
| 2374 | buildMonthSwitch(); |
| 2375 | } |
| 2376 |
no test coverage detected
searching dependent graphs…