MCPcopy
hub / github.com/flatpickr/flatpickr / timeWrapper

Function timeWrapper

src/index.ts:2871–2927  ·  view source on GitHub ↗
(
    e: MouseEvent | KeyboardEvent | FocusEvent | IncrementEvent
  )

Source from the content-addressed store, hash-verified

2869 }
2870
2871 function timeWrapper(
2872 e: MouseEvent | KeyboardEvent | FocusEvent | IncrementEvent
2873 ): void {
2874 e.preventDefault();
2875
2876 const isKeyDown = e.type === "keydown",
2877 eventTarget = getEventTarget(e),
2878 input = eventTarget as HTMLInputElement;
2879
2880 if (self.amPM !== undefined && eventTarget === self.amPM) {
2881 self.amPM.textContent =
2882 self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2883 }
2884
2885 const min = parseFloat(input.getAttribute("min") as string),
2886 max = parseFloat(input.getAttribute("max") as string),
2887 step = parseFloat(input.getAttribute("step") as string),
2888 curValue = parseInt(input.value, 10),
2889 delta =
2890 (e as IncrementEvent).delta ||
2891 (isKeyDown ? ((e as KeyboardEvent).which === 38 ? 1 : -1) : 0);
2892
2893 let newValue = curValue + step * delta;
2894
2895 if (typeof input.value !== "undefined" && input.value.length === 2) {
2896 const isHourElem = input === self.hourElement,
2897 isMinuteElem = input === self.minuteElement;
2898
2899 if (newValue < min) {
2900 newValue =
2901 max +
2902 newValue +
2903 int(!isHourElem) +
2904 (int(isHourElem) && int(!self.amPM));
2905
2906 if (isMinuteElem) incrementNumInput(undefined, -1, self.hourElement);
2907 } else if (newValue > max) {
2908 newValue =
2909 input === self.hourElement ? newValue - max - int(!self.amPM) : min;
2910
2911 if (isMinuteElem) incrementNumInput(undefined, 1, self.hourElement);
2912 }
2913
2914 if (
2915 self.amPM &&
2916 isHourElem &&
2917 (step === 1
2918 ? newValue + curValue === 23
2919 : Math.abs(newValue - curValue) > step)
2920 ) {
2921 self.amPM.textContent =
2922 self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2923 }
2924
2925 input.value = pad(newValue);
2926 }
2927 }
2928

Callers 1

updateTimeFunction · 0.85

Calls 4

getEventTargetFunction · 0.90
intFunction · 0.90
padFunction · 0.90
incrementNumInputFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…