MCPcopy
hub / github.com/flatpickr/flatpickr / bindEvents

Function bindEvents

src/index.ts:410–494  ·  view source on GitHub ↗

* Adds all the necessary event listeners

()

Source from the content-addressed store, hash-verified

408 * Adds all the necessary event listeners
409 */
410 function bindEvents(): void {
411 if (self.config.wrap) {
412 ["open", "close", "toggle", "clear"].forEach((evt) => {
413 Array.prototype.forEach.call(
414 self.element.querySelectorAll(`[data-${evt}]`),
415 (el: HTMLElement) =>
416 bind(
417 el,
418 "click",
419 self[evt as "open" | "close" | "toggle" | "clear"]
420 )
421 );
422 });
423 }
424
425 if (self.isMobile) {
426 setupMobile();
427 return;
428 }
429
430 const debouncedResize = debounce(onResize, 50);
431 self._debouncedChange = debounce(triggerChange, DEBOUNCED_CHANGE_MS);
432
433 if (self.daysContainer && !/iPhone|iPad|iPod/i.test(navigator.userAgent))
434 bind(self.daysContainer, "mouseover", (e: MouseEvent) => {
435 if (self.config.mode === "range")
436 onMouseOver(getEventTarget(e) as DayElement);
437 });
438
439 bind(self._input, "keydown", onKeyDown);
440 if (self.calendarContainer !== undefined) {
441 bind(self.calendarContainer, "keydown", onKeyDown);
442 }
443
444 if (!self.config.inline && !self.config.static)
445 bind(window, "resize", debouncedResize);
446
447 if (window.ontouchstart !== undefined)
448 bind(window.document, "touchstart", documentClick);
449 else bind(window.document, "mousedown", documentClick);
450 bind(window.document, "focus", documentClick, { capture: true });
451
452 if (self.config.clickOpens === true) {
453 bind(self._input, "focus", self.open);
454 bind(self._input, "click", self.open);
455 }
456
457 if (self.daysContainer !== undefined) {
458 bind(self.monthNav, "click", onMonthNavClick);
459
460 bind(self.monthNav, ["keyup", "increment"], onYearInput);
461 bind(self.daysContainer, "click", selectDate);
462 }
463
464 if (
465 self.timeContainer !== undefined &&
466 self.minuteElement !== undefined &&
467 self.hourElement !== undefined

Callers 1

initFunction · 0.70

Calls 6

debounceFunction · 0.90
getEventTargetFunction · 0.90
bindFunction · 0.85
setupMobileFunction · 0.85
onMouseOverFunction · 0.85
updateTimeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…