PageSourceSearch

https://cazloyd.com/wp-content/themes/cazloyd/js/itineraries-filter.js?ver=1.2.5

js cazloyd.com collected 2026-10-01 14:47:18 UTC 7,763 bytes, 279 lines download raw bytes

1var $ = jQuery.noConflict();
2$(document).ready(function () {
3  $(".filter-box__title").on("click", function (event) {
4    if ($(event.target).closest(".clear-filters").length) {
5      return;
6    }
7  });
8
9  /* Custom checkbox dropdown */
10  var $multiSelectBoxes = $(".select-box").has(".select-box__content");
11  var $clearFiltersBtn = $(".clear-filters");
12
13  function closeSelectBoxes($except) {
14    var $openBoxes = $multiSelectBoxes.filter(".is-open");
15    if ($except && $except.length) {
16      $openBoxes = $openBoxes.not($except);
17    }
18    $openBoxes
19      .removeClass("is-open")
20      .find(".select-box__content-inner")
21      .attr("aria-expanded", "false");
22  }
23
24  function updateSelectBoxLabel($box) {
25    var $inner = $box.find(".select-box__content-inner").first();
26    var placeholder = $inner.data("placeholder") || "Select All";
27    var selected = [];
28
29    $box.find('.check-wrap input[type="checkbox"]:checked').each(function () {
30      var labelText =
31        $.trim($(this).closest(".check-wrap").find("label").text()) ||
32        $(this).val();
33      if (labelText) {
34        selected.push(labelText);
35      }
36    });
37
38    var text = selected.length ? selected.join(", ") : placeholder;
39    $inner.text(text).attr("title", text);
40  }
41
42  function toggleClearFiltersButton() {
43    var hasSelection =
44      $multiSelectBoxes.find('.check-wrap input[type="checkbox"]:checked')
45        .length > 0;
46    $clearFiltersBtn
47      .toggleClass("is-visible", hasSelection)
48      .prop("hidden", !hasSelection);
49  }
50
51  function clearAllFilters() {
52    $multiSelectBoxes
53      .find('.check-wrap input[type="checkbox"]:checked')
54      .prop("checked", false);
55    $multiSelectBoxes.each(function () {
56      updateSelectBoxLabel($(this));
57    });
58    closeSelectBoxes();
59    toggleClearFiltersButton();
60  }
61
62  $multiSelectBoxes.each(function () {
63    updateSelectBoxLabel($(this));
64  });
65  toggleClearFiltersButton();
66
67  $(document).on("click", ".select-box__content-inner", function (event) {
68    event.preventDefault();
69    event.stopPropagation();
70
71    var $box = $(this).closest(".select-box");
72    var isOpen = $box.hasClass("is-open");
73
74    closeSelectBoxes($box);
75    $box.toggleClass("is-open", !isOpen);
76    $(this).attr("aria-expanded", !isOpen ? "true" : "false");
77  });
78
79  $(document).on(
80    "change",
81    '.select-box .check-wrap input[type="checkbox"]',
82    function () {
83      updateSelectBoxLabel($(this).closest(".select-box"));
84      toggleClearFiltersButton();
85    },
86  );
87
88  $(document).on("click", ".clear-filters", function (event) {
89    event.preventDefault();
90    event.stopPropagation();
91    clearAllFilters();
92  });
93
94  $(document).on("click", ".select-box__content", function (event) {
95    event.stopPropagation();
96  });
97
98  $(document).on("click", function () {
99    closeSelectBoxes();
100  });
101
102  $(document).on("keydown", function (event) {
103    if (event.key === "Escape") {
104      closeSelectBoxes();
105    }
106  });
107  /* // Custom checkbox dropdown */
108});
109
110/**
111 * Best time to call you.
112 * Options are built in the browser (today / tomorrow, or next Monday on a weekend)
113 * and injected into the WPForms modern dropdown (.best_time_call).
114 */
115function cazloydChoicesConfig(overrides) {
116  var base = window.wpforms_choicesjs_config || {};
117  var config = $.extend({}, overrides || {});
118  var baseInit = base.callbackOnInit;
119  var extraInit = config.callbackOnInit;
120
121  config.callbackOnInit = function () {
122    if (typeof baseInit === "function") {
123      baseInit.call(this);
124    }
125    if (typeof extraInit === "function") {
126      extraInit.call(this);
127    }
128
129    var hiddenClass =
130      this.config && this.config.classNames && this.config.classNames.input
131        ? this.config.classNames.input + "--hidden"
132        : "choices__input--hidden";
133
134    $(this.passedElement.element).removeAttr("hidden").addClass(hiddenClass);
135  };
136
137  return config;
138}
139
140function generateBestTimeOptions() {
141  var options = [];
142  var now = new Date();
143  var today = new Date(now);
144  var tomorrow = new Date(today);
145  tomorrow.setDate(today.getDate() + 1);
146
147  var dayOfWeek = today.getDay();
148  var isWeekend = dayOfWeek === 0 || dayOfWeek === 5 || dayOfWeek === 6;
149
150  var startTime = new Date(now);
151  startTime.setHours(now.getHours() + 3, 0, 0, 0);
152
153  function formatDateHeading(date) {
154    var day = date.getDate();
155    var month = date.getMonth() + 1;
156    var weekday = date.toLocaleString("en", { weekday: "short" });
157    return (
158      weekday +
159      " (" +
160      String(day).padStart(2, "0") +
161      "/" +
162      String(month).padStart(2, "0") +
163      ")"
164    );
165  }
166
167  function formatTime(hour) {
168    var startHour = hour % 12 === 0 ? 12 : hour % 12;
169    var endHour = (hour + 1) % 12 === 0 ? 12 : (hour + 1) % 12;
170    var startSuffix = hour < 12 ? "AM" : "PM";
171    var endSuffix = hour + 1 < 12 || hour + 1 === 24 ? "AM" : "PM";
172    return startHour + " " + startSuffix + " - " + endHour + " " + endSuffix + " (BST)";
173  }
174
175  function pushDay(label, date, startHour) {
176    var dateHeading = formatDateHeading(date);
177    var slots = [];
178    var hour;
179
180    for (hour = startHour; hour <= 17; hour++) {
181      var timeRange = formatTime(hour);
182      slots.push({
183        value: dateHeading + " [" + timeRange + "]",
184        label: timeRange,
185      });
186    }
187
188    options.push({
189      value: label + " - " + dateHeading,
190      label: label + " - " + dateHeading,
191      disabled: true,
192    });
193
194    slots.forEach(function (slot) {
195      options.push(slot);
196    });
197  }
198
199  if (isWeekend) {
200    var nextMonday = new Date(today);
201    var daysUntilMonday = 1;
202    if (dayOfWeek === 5) {
203      daysUntilMonday = 3;
204    } else if (dayOfWeek === 6) {
205      daysUntilMonday = 2;
206    }
207    nextMonday.setDate(today.getDate() + daysUntilMonday);
208    pushDay("Monday", nextMonday, 9);
209  } else {
210    if (now.getHours() < 16) {
211      pushDay("Today", today, startTime.getHours());
212    }
213    pushDay("Tomorrow", tomorrow, 9);
214  }
215
216  return options;
217}
218
219function initBestTimeSelect() {
220  var selectElement = document.querySelector(".best_time_call select");
221  if (!selectElement || typeof Choices !== "function") {
222    return;
223  }
224
225  var $select = $(selectElement);
226  var existing = $select.data("choicesjs");
227  if (existing && typeof existing.destroy === "function") {
228    try {
229      existing.destroy();
230    } catch (err) {}
231  }
232
233  var wrapper = selectElement.closest(".choices");
234  if (wrapper && wrapper.parentNode) {
235    wrapper.parentNode.insertBefore(selectElement, wrapper);
236    wrapper.parentNode.removeChild(wrapper);
237  }
238
239  selectElement.removeAttribute("data-choice");
240  selectElement.hidden = false;
241  $select.empty();
242
243  var choice = new Choices(
244    selectElement,
245    cazloydChoicesConfig({
246      allowHTML: true,
247      removeItems: true,
248      placeholder: true,
249      placeholderValue: "No preference",
250      searchPlaceholderValue: "Search options",
251      shouldSort: false,
252      searchEnabled: true,
253      itemSelectText: "",
254      choices: generateBestTimeOptions(),
255    }),
256  );
257
258  $select.data("choicesjs", choice);
259
260  if (typeof choice.removeActiveItems === "function") {
261    choice.removeActiveItems();
262  }
263
264  var singleList = selectElement.parentNode.querySelector(".choices__list--single");
265  if (singleList) {
266    singleList.textContent = "";
267    var placeholder = document.createElement("div");
268    placeholder.className = "choices__item choices__placeholder choices__item--selectable";
269    placeholder.setAttribute("data-item", "");
270    placeholder.setAttribute("data-value", "");
271    placeholder.setAttribute("aria-selected", "true");
272    placeholder.textContent = "No preference";
273    singleList.appendChild(placeholder);
274  }
275}
276
277initBestTimeSelect();
278$(window).off("wpformsReady.bestTime").on("wpformsReady.bestTime", initBestTimeSelect);
279

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.