PageSourceSearch

https://saddleback.com/scripts/Events/Mixins/EventSearchUtilsMixin…?v=517cdeafa93af7720f65d0a6f449ca34186eeedc

js saddleback.com collected 2026-09-24 17:19:30 UTC 6,192 bytes, 175 lines download raw bytes

1import { slugify } from '/scripts/utils/slugify.js';
2
3/**
4 * EventSearchUtilsMixin
5 * Pure helper methods: date ranges, event list filtering,
6 * deduplication, tag lookup, DOM cleanup.
7 */
8export default {
9  methods: {
10    // Centralized name -> URL-safe slug, shared via /scripts/utils/slugify.js.
11    // Used for the cosmetic {title} segment of /event/{title}/{id}.
12    slugify,
13    getIsDebug() {
14      const urlParams = new URLSearchParams(window.location.search);
15      return urlParams.has('debug');
16    },
17    getDatesInRange(startDate, endDate) {
18      const dates = [];
19      let currentDate = new Date(startDate.getTime());
20
21      while (currentDate <= endDate) {
22        dates.push(new Date(currentDate));
23        currentDate.setDate(currentDate.getDate() + 1);
24      }
25      return dates;
26    },
27    filteredEventsList(eventsList, firstDay, lastDay) {
28      var tempList = [];
29      eventsList.forEach((el) => {
30        tempList.push({
31          date: dayjs(el.date).format('dddd, MMMM D, YYYY'),
32          events: el.events.filter((e) => {
33            return dayjs(e.occurrence.localEndDateTime).isAfter(dayjs());
34          }),
35        });
36      });
37
38      this.addEmptyDays(tempList, firstDay, lastDay);
39
40      // Remove duplicate items from the filteredEventListDisplay array
41      this.filteredEventListDisplay = this.filteredEventListDisplay.filter(
42        (item, index, self) => index === self.findIndex((t) => t.date === item.date)
43      );
44
45      this.isLoading = false;
46
47      return this.filteredEventListDisplay.sort((a, b) => {
48        return new Date(a.date) - new Date(b.date);
49      });
50    },
51    addEmptyDays(tempList, firstDay, lastDay) {
52      const filteredEventsToday = new Date(firstDay);
53      const filteredEventsLastDay = new Date(lastDay);
54      var dateExists = '';
55      const filteredEventsDateRange = this.getDatesInRange(filteredEventsToday, filteredEventsLastDay);
56
57      var i = 0;
58      filteredEventsDateRange.forEach((date) => {
59        var dateFormatted = dayjs(date).format('dddd, MMMM D, YYYY');
60
61        dateExists = tempList.find(function (e) {
62          return e.date === dateFormatted;
63        });
64
65        if (typeof dateExists === 'undefined') {
66          tempList.push({
67            date: dateFormatted,
68            events: [],
69          });
70        }
71        this.filteredEventListDisplay.push(tempList[i]);
72        i++;
73      });
74    },
75    eventsListDisplay() {
76      this.displayFullResults = true;
77    },
78    datesAlreadyCalledCheck(firstDay, lastDay) {
79      const dateRange = { firstDay: firstDay, lastDay: lastDay };
80      const dateRangeString = JSON.stringify(dateRange);
81      const dateRangeExists = this.datesAlreadyCalled.some((item) => JSON.stringify(item) === dateRangeString);
82      if (!dateRangeExists) {
83        this.datesAlreadyCalled.push(dateRange);
84        this.datesCheck = true;
85      } else {
86        this.datesCheck = false;
87        $('#eventDatePicker').removeClass('events-loading');
88      }
89    },
90    getNextDateRange(firstLoadedDay) {
91      const dayjsFirst =
92        firstLoadedDay == ''
93          ? this.scrollDateRange.firstDay
94            ? dayjs(this.scrollDateRange.firstDay)
95            : dayjs().startOf('day')
96          : dayjs(firstLoadedDay).startOf('day').add(1, 'month');
97
98      let newFirstDay = this.scrollDateRange.lastDay
99        ? dayjs(this.scrollDateRange.lastDay).add(1, 'day')
100        : dayjsFirst;
101
102      let newLastDay;
103
104      this.scrollDateRange.view = this.monthViewOpen ? 'month' : 'week';
105
106      if (this.scrollDateRange.view === 'month' || window.innerWidth >= 1024) {
107        newFirstDay = newFirstDay.clone().startOf('month').startOf('week');
108        newLastDay = newFirstDay.clone().add(1, 'month').endOf('month');
109      } else {
110        newLastDay = newFirstDay.clone().add(6, 'day');
111      }
112
113      this.scrollDateRange.firstDay = newFirstDay;
114      this.scrollDateRange.lastDay = newLastDay;
115
116      firstLoadedDay = '';
117
118      return {
119        startDate: newFirstDay.toDate(),
120        endDate: newLastDay.toDate(),
121      };
122    },
123    resetScrollDateRange() {
124      this.isTextSearch = false;
125      this.isLoading = true;
126      this.textSearchCurrentPage = 0;
127      this.textSearchEventsDisplay = [];
128      this.scrollDateRange.firstDay = null;
129      this.scrollDateRange.lastDay = null;
130      $('.event-category-filter').removeClass('active');
131      $('.event-category-filter.view-all-filter').add('active');
132      $('#eventDatePicker').mobiscroll('setVal', new Date());
133      this.scrollMagicDateSetup(false);
134    },
135    removeAllEventDivsBeforeToday() {
136      $('.events-list-date').each(function () {
137        var eventDate = $(this).find('.events-list-date-inner').attr('data-event-date');
138        if (eventDate && dayjs(eventDate).isBefore(dayjs(), 'day')) {
139          $(this).remove();
140        }
141      });
142    },
143    getTagIdByName(tagArray) {
144      var url = new URL(document.location);
145      if (url.searchParams.get('tags')) {
146        url.searchParams
147          .get('tags')
148          .split(',')
149          .forEach((tag) => {
150            var tagId = parseInt(tag);
151            if (isNaN(tagId)) {
152              var filteredTags = tagArray.filter((t) => t.Name.toLowerCase() === tag.toLowerCase());
153              if (filteredTags.length) {
154                filteredTags.forEach((t) => {
155                  if (this.isDebug) console.log(t.Id);
156                });
157                filteredTags.forEach((t) => this.selectedTags.push(t.Id));
158              }
159              if (this.isDebug) console.log('selectedTags: ', this.selectedTags);
160            } else {
161              this.selectedTags.push(tagId);
162              if (this.isDebug) console.log('selectedTags: ', this.selectedTags);
163            }
164          });
165      }
166    },
167    checkIfTodaySelected(selDate, dateStr, fp) {
168      let today = new Date().toLocaleDateString();
169      let selDateDay = new Date(selDate).toLocaleDateString();
170      if (selDateDay === today) {
171        fp._input.value = 'Today';
172      }
173    },
174  },
175};

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.