PageSourceSearch

https://centercityphila.org/wp-content/themes/center-city-district/assets/dist/ajax.js?ver=1790159353

js centercityphila.org collected 2026-09-24 18:02:33 UTC 14,254 bytes, 363 lines download raw bytes

1jQuery(document).ready(function($) {
2
3    
4        function filterMap(section_id) {
5            var $section = $('section[data-section-id="' + section_id + '"]');
6            var $display_count = $section.find('.map-results p');
7            var $markers = $section.find('.p10-map-marker');
8            $markers.hide();
9            $section.find('.p10-map-marker').removeClass('active-marker');
10            $section.find('.card').removeClass('highlight');
11            var visibleCards = $section.find('.map-list .card');
12            var locationsArray = [];
13            visibleCards.each(function() {
14                var postId = $(this).data('post-id');
15                var lon = parseFloat($(this).data('long'));
16                var lat = parseFloat($(this).data('lat'));
17                if (isFinite(lon) && isFinite(lat)) {
18                    locationsArray.push([lon, lat]);
19                    var $marker = $section.find('.p10-map-marker[data-post-id="' + postId + '"]');
20                    $marker.show();
21                }
22            });
23
24            var count = visibleCards.length;
25            if (count != 0) {
26                if(count > 1) {
27                    $display_count.text('Displaying ' + count + ' results');
28                } else {
29                    $display_count.text('Displaying ' + count + ' result');
30                }
31            } else {
32                $display_count.text('');
33            }
34
35            checkForData(section_id);
36        }
37
38        function createActiveFilters($changedInput, $form, $section) {
39            var $activeWrapper = $section.find('.filter-activated-wrapper');
40            var filterValue = $changedInput.val();
41
42            if(filterValue === 'all') {
43                filterText = 'All '+ $changedInput.data('taxonomy-label') + ' Locations';
44                $section.find('.active-filter[data-filter-taxonomy="' + $changedInput.data('taxonomy') + '"]').remove();
45            } else {
46                var filterText = $changedInput.parent('label').text();
47            }
48
49            if($changedInput.is(':checked')) {
50                // Add active filter
51                $activeWrapper.prepend('<a href="javascript:void(0);" class="active-filter" data-filter-taxonomy="' + $changedInput.data('taxonomy') + '" data-filter-value="' + filterValue + '">' + filterText + ' <span><svg width="8" height="8" viewBox="0 0 8 8" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3.11111 4L0 7.11111L0.888889 8L4 4.88889L7.11111 8L8 7.11111L4.88889 4L8 0.888889L7.11111 0L4 3.11111L0.888889 0L2.11928e-07 0.888889L3.11111 4Z" fill="white"/></svg></span></a>');
52            } else {
53                // Remove active filter
54                $activeWrapper.find('.active-filter[data-filter-value="' + filterValue + '"]').remove();
55            }
56
57            updateDropdownLabel($section);
58
59        }
60
61        function updateDropdownLabel($section) {
62
63            var ActiveFilters = $section.find('.active-filter');
64            $section.find('.dropdown-header .dropdown-text-wrapper').text('All');
65
66            if(ActiveFilters.length) {
67                titleArray = [];
68                
69                ActiveFilters.each(function() {
70                    var text = $(this).text().trim();
71                    var taxonomy = $(this).data('filter-taxonomy');
72                    var found = false;
73                    for (var i = 0; i < titleArray.length; i++) {
74                        if (titleArray[i].taxonomy === taxonomy) {
75                            titleArray[i].texts.push(text);
76                            found = true;
77                            break;
78                        }
79                    }
80                    if (!found) {
81                        titleArray.push({ taxonomy: taxonomy, texts: [text] });
82                    }
83                });
84
85
86                titleArray.forEach(function(group) {
87                    var combinedText = group.texts.join(', ');
88                    $section.find('.dropdown-header .dropdown-text-wrapper[data-taxonomy="' + group.taxonomy + '"]').text(combinedText);
89                });
90
91            } else {
92                $section.find('.dropdown-header .dropdown-text-wrapper').text('All');
93            }
94
95        }
96
97        function checkForData(section_id) {
98            var $section = $('section[data-section-id="' + section_id + '"]');
99            var $checkboxes = $section.find('form input[type="checkbox"]');
100            var $searchInput = $section.find('form input[name="search"]');
101            var anyChecked = $checkboxes.filter(':checked').length > 0;
102            var hasSearch = $.trim($searchInput.val() || '').length > 0;
103            var $activeWrapper = $section.find('.filter-activated-wrapper');
104            var $mapResults = $section.find('.map-results');
105
106            if (anyChecked || hasSearch) {
107                $activeWrapper.addClass('active');
108                $mapResults.addClass('active');
109            } else {
110                $activeWrapper.removeClass('active');
111                $mapResults.removeClass('active');
112            }
113            
114        }
115        
116
117
118        function checkForArchiveData(section) {
119            var $checkboxes = section.find('form input[type="checkbox"]');
120            var $searchInput = section.find('form input[name="search"]');
121            var anyChecked = $checkboxes.filter(':checked').length > 0;
122            var hasSearch = $.trim($searchInput.val() || '').length > 0;
123            var $activeWrapper = section.find('.filter-activated-wrapper');
124
125            if (anyChecked || hasSearch) {
126                $activeWrapper.addClass('active');
127            } else {
128                $activeWrapper.removeClass('active');
129            }
130        }
131
132        $(document).on('submit', 'form', function() {
133            var $searchInput = $(this).find('input[name="search"]');
134            var hasSearch = $searchInput.length && $.trim($searchInput.val() || '').length > 0;
135
136            if (hasSearch) {
137                $('.filter-form.active').removeClass('active');
138                $('body').removeClass('active-mobile-filters');
139            }
140        });
141
142
143        $(document).on('click', '.active-filter', function(e) {
144            e.preventDefault();
145            var filterValue = $(this).data('filter-value');
146            var $section = $(this).closest('section');
147            var $form = $section.find('form');
148            var dataFilterValue = $(this).data('filter-value');
149
150            if(dataFilterValue === 'all') {
151                var $input = $form.find('input[type="checkbox"][data-taxonomy="' + $(this).data('filter-taxonomy') + '"]');
152            } else {
153                var $input = $form.find('input[type="checkbox"][value="' + filterValue + '"]');
154            }                
155
156            $input.prop('checked', false);
157
158            $(this).remove();
159
160            $form.submit();
161            updateDropdownLabel($section);
162
163            
164        });
165    
166    if($('.archive-form').length) { //FOR ARCHIVE BLOCK
167
168        var $paginationContainer = $('.archive-pagination');
169
170        $('.archive-form').each(function() {
171            var $form = $(this);
172            var $cpt = $form.data('cpt');
173            var $section = $form.closest('section');
174            var $archive_view = $section.find('.archive-view');
175
176            $('.archive-filter').on('change', function() {
177                var $form = $(this).closest('form');                
178                $form.submit();
179                createActiveFilters($(this), $form, $section);
180            });
181
182
183            $form.on('submit', function(e) {
184                e.preventDefault();
185                var search_query = $(this).find('input[name="search"]').val();
186                var $taxonomies = {};
187                $(this).find('input[type="checkbox"]:checked').each(function() {
188                    var taxonomy = $(this).data('taxonomy');
189                    if (!$taxonomies[taxonomy]) {
190                            $taxonomies[taxonomy] = [];
191                        }
192                    $taxonomies[taxonomy].push($(this).val());
193                    
194                });
195                
196                var selectedCategories = [];
197
198                for (var tax in $taxonomies) {
199                    selectedCategories = selectedCategories.concat($taxonomies[tax]);
200                }
201
202                var data = {
203                    'action': 'filter_archive_action', // PHP function hook
204                    'nonce': MyAjax.nonce,
205                    'cpt': $cpt,
206                    'search_query': search_query,
207                    'tax_and_terms': $taxonomies,
208                    'page_id': $form.data('page'),
209                };
210
211                $.ajax({
212                    url: MyAjax.ajaxurl,
213                    type: 'POST',
214                    data: data,
215                    beforeSend: function() {
216                        $archive_view.html('<p>Loading ...</p>');
217                    },
218                    success: function(response) {
219                        $archive_view.html(response);
220                    },
221                    error: function(error) {
222                        $archive_view.html('<p>An error occurred.</p>');
223                    }
224                });
225                checkForArchiveData($section);
226            });
227
228        });
229    }
230
231
232    if($('.filter-form').length) { //FOR MAP BLOCK
233
234        $('.map-results p').each(function() {
235            var $section = $(this).closest('section');
236            var $cards = $section.find('.map-list .card');
237            var count = $cards.length;
238            if (count != 0) {
239                if(count > 1) {
240                    $(this).text('Displaying ' + count + ' results');
241                } else {
242                    $(this).text('Displaying ' + count + ' result');
243                }
244            }
245            
246        });
247
248        $('.filter-form').each(function() {
249            var $form = $(this);
250            var $cpt = $form.data('cpt');
251            var $section = $form.closest('section');
252            var $map_list = $section.find('.map-list');
253            var $list_view = $section.find('.list-view');
254            
255            
256
257            $('.map-filter').on('change', function() {
258                var $form = $(this).closest('form');
259                var text = $(this).text();
260                var $filter_group = $(this).closest('div.filter');
261
262                if($(this).val() === 'all') {
263                    // Uncheck all other checkboxes
264                    $filter_group.find('input[type="checkbox"]').not(this).prop('checked', false);
265
266                } else {
267                    // Uncheck the 'all' checkbox
268                    $filter_group.find('input[type="checkbox"][value="all"]').prop('checked', false);
269
270                }
271
272                $form.submit();
273
274                createActiveFilters($(this), $form, $section);
275            });
276
277
278            $form.on('submit', function(e) {
279                e.preventDefault();
280                var search_query = $(this).find('input[name="search"]').val();
281                var type = $(this).data('type');
282                var $taxonomies = {};
283                $(this).find('input[type="checkbox"]:checked').each(function() {
284                    var taxonomy = $(this).data('taxonomy');
285                    if($(this).val() === 'all') {
286                        var terms = $(this).data('all-terms');
287                        // Normalize terms to an array: if it's a comma-separated string, split and trim each term
288                        if (typeof terms === 'string') {
289                            terms = terms.split(',').map(function(t) { return $.trim(t); });
290                        } else if (!$.isArray(terms)) {
291                            terms = [terms];
292                        }
293                        $taxonomies[taxonomy] = terms;
294                    } else {
295                        if (!$taxonomies[taxonomy]) {
296                            $taxonomies[taxonomy] = [];
297                        }
298                        $taxonomies[taxonomy].push($(this).val());
299                    }
300                    
301                });
302                
303                
304                var selectedCategories = [];
305
306                for (var tax in $taxonomies) {
307                    selectedCategories = selectedCategories.concat($taxonomies[tax]);
308                }
309
310
311                var data = {
312                    'action': 'filter_map_action', // PHP function hook
313                    'nonce': MyAjax.nonce,
314                    'cpt': $cpt,
315                    'type': type,
316                    'search_query': search_query,
317                    'tax_and_terms': $taxonomies,
318                };
319
320                var dataList = {
321                    'action': 'filter_list_action', // PHP function hook
322                    'nonce': MyAjax.nonce,
323                    'cpt': $cpt,
324                    'type': type,
325                    'search_query': search_query,
326                    'tax_and_terms': $taxonomies,
327                };
328
329                $.ajax({
330                    url: MyAjax.ajaxurl,
331                    type: 'POST',
332                    data: dataList,
333                    beforeSend: function() {
334                        $list_view.html('<p>Loading locations...</p>');
335                    },
336                    success: function(response) {
337                        $list_view.html(response);
338                    },
339                    error: function(error) {
340                        $list_view.html('<p>An error occurred.</p>');
341                    }
342                });
343
344                $.ajax({
345                    url: MyAjax.ajaxurl,
346                    type: 'POST',
347                    data: data,
348                    beforeSend: function() {
349                        $map_list.html('<p>Loading locations...</p>');
350                    },
351                    success: function(response) {
352                        $map_list.html(response);
353                        filterMap($section.data('section-id'));
354                    },
355                    error: function(error) {
356                        $map_list.html('<p>An error occurred.</p>');
357                    }
358                });
359            });
360        }); 
361    }
362
363});

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.