PageSourceSearch

https://embassybank.com/wp-content/themes/embassy-bank/assets/js/contact-form-hours.js?ver=1.0

js embassybank.com collected 2026-10-04 13:27:59 UTC 3,994 bytes, 146 lines download raw bytes

1/*
2-----------------------------
3
4Fluent Form Date Restrictions
5
6-----------------------------
7*/
8(function () {
9  const FORM_ID = 4; // <-- update
10
11  const RULES = {
12    1: { min: "09:00", max: "16:45" }, // Mon
13    2: { min: "09:00", max: "16:45" }, // Tue
14    3: { min: "09:00", max: "16:45" }, // Wed
15    4: { min: "09:00", max: "16:45" }, // Thu
16    5: { min: "09:00", max: "17:45" }, // Fri
17    6: { min: "09:00", max: "11:45" }, // Sat
18    0: null // Sun
19  };
20
21  function dateKey(d) {
22    // key by yyyy-mm-dd so we only re-apply when the *date* changes
23    return d ? `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}` : "";
24  }
25
26  function dateWithTime(baseDate, hhmm) {
27    const [h, m] = hhmm.split(":").map(Number);
28    const d = new Date(baseDate);
29    d.setHours(h, m, 0, 0);
30    return d;
31  }
32
33  function clamp(fp, rule) {
34    const current = fp.selectedDates && fp.selectedDates[0] ? fp.selectedDates[0] : null;
35    if (!current) return;
36
37    const minD = dateWithTime(current, rule.min);
38    const maxD = dateWithTime(current, rule.max);
39
40    if (current < minD) fp.setDate(minD, true);
41    if (current > maxD) fp.setDate(maxD, true);
42  }
43
44  function applyForDate(fp, d) {
45    if (!fp || !d) return;
46
47    // Re-entry guard (prevents loops caused by setDate/redraw)
48    if (fp.__hoursApplying) return;
49    fp.__hoursApplying = true;
50
51    const rule = RULES[d.getDay()];
52    if (!rule) {
53      fp.clear();
54      fp.__hoursApplying = false;
55      return;
56    }
57
58    // Only set if changed (avoids redraw storms)
59    if (fp.config.minTime !== rule.min) fp.set("minTime", rule.min);
60    if (fp.config.maxTime !== rule.max) fp.set("maxTime", rule.max);
61
62    clamp(fp, rule);
63
64    fp.__hoursApplying = false;
65  }
66
67  function bind(input) {
68    if (!input || input.dataset.hoursBound === "1") return;
69    const fp = input._flatpickr;
70    if (!fp) return;
71
72    input.dataset.hoursBound = "1";
73
74    // Static options ONCE
75    fp.set({
76      enableTime: true,
77      allowInput: false,
78      time_24hr: false,
79      dateFormat: "m/d/Y h:i K",
80      minuteIncrement: 15,
81      disableMobile: true,
82      disable: [d => d.getDay() === 0] // Sunday disabled
83    });
84
85    // Track last applied date so we only re-apply when date changes
86    fp.__lastDateKey = "";
87
88    // When user selects a date/time
89    fp.config.onChange.push(function (selectedDates, dateStr, inst) {
90      const d = selectedDates && selectedDates[0] ? selectedDates[0] : null;
91      if (!d) return;
92
93      const key = dateKey(d);
94      if (key !== inst.__lastDateKey) {
95        inst.__lastDateKey = key;
96        applyForDate(inst, d);
97      } else {
98        // same date, just clamp (covers manual time adjustments)
99        const rule = RULES[d.getDay()];
100        if (rule) clamp(inst, rule);
101      }
102    });
103
104    // When opening the calendar, apply based on current selection (or today)
105    fp.config.onOpen.push(function (selectedDates, dateStr, inst) {
106      const d = (inst.selectedDates && inst.selectedDates[0]) ? inst.selectedDates[0] : new Date();
107      const key = dateKey(d);
108      if (key !== inst.__lastDateKey) {
109        inst.__lastDateKey = key;
110        applyForDate(inst, d);
111      }
112    });
113
114    // If prefilled
115    if (fp.selectedDates && fp.selectedDates[0]) {
116      const d = fp.selectedDates[0];
117      fp.__lastDateKey = dateKey(d);
118      applyForDate(fp, d);
119    }
120  }
121
122  function scan() {
123    const form = document.querySelector(`#fluentform_${FORM_ID}`);
124    if (!form) return;
125
126    const inputs = form.querySelectorAll(
127      "input.ff_datetimepicker, input.flatpickr-input, input[data-toggle='flatpickr']"
128    );
129
130    inputs.forEach((input) => {
131      if (input._flatpickr) bind(input);
132    });
133  }
134
135  document.addEventListener("DOMContentLoaded", function () {
136    scan();
137
138    // Re-scan for conditional/multi-step rendering (lightweight)
139    let tries = 0;
140    const t = setInterval(() => {
141      scan();
142      tries++;
143      if (tries >= 200) clearInterval(t); // 20s
144    }, 100);
145  });
146})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.