PageSourceSearch

https://vdcforum.org/wp-content/themes/divi-child/assets/js/custom.js?ver=1791587479

js vdcforum.org collected 2026-10-09 23:12:14 UTC 9,520 bytes, 274 lines download raw bytes

1(function($) {
2  "use strict";
3
4
5/*$(document).ready(function() {
6  var isLoading = false;
7  var canLoadMore = true; // Flag to track if we can still load more posts
8
9  
10
11  // Scroll-based "Load More" functionality
12  $(window).on("scroll", function() {
13   
14    if (!isLoading && canLoadMore) {
15      
16      var lastPost = $('.whatsresource').last(); // Get the last .whatsresource element
17      var lastPostPosition = lastPost.offset().top + lastPost.outerHeight(); // Calculate the position of the last post
18
19      // Check if the last post is within the viewport (a little buffer from the bottom of the page)
20      if ($(window).scrollTop() + $(window).height() >= lastPostPosition - 200) {
21       
22
23        isLoading = true;
24        var curr_page_num = $('#curr_page_num').val();
25        var total_posts = $('#total_posts').val();
26        var form = $('#resource_form_result_data').serialize();
27
28        $.ajax({
29          type: 'POST',
30          url: vdcforum_ajax_object.ajax_url,
31          data: {
32            action: 'resource_ajax_load_more',
33            paged: curr_page_num,
34            total_posts: total_posts,
35            form_data: form,
36          },
37          beforeSend: function() {
38            $('#loading-spinner').show();
39          },
40          success: function(res) {
41            var obj = JSON.parse(res);
42            if (obj.html !== null) { 
43              if (obj.html.trim() === "") {
44                canLoadMore = false; // No more posts, stop loading
45                $('#loading-spinner').hide(); // Hide the spinner
46              } else {
47                $('.allresourcePosts').append(obj.html); // Append new posts
48                $("#curr_page_num").val(obj.curr_page_num); // Update current page number
49                $('#loading-spinner').hide(); // Hide the spinner
50              }
51            }else{
52              canLoadMore = false; // No more posts, stop loading
53                $('#loading-spinner').hide(); // Hide the spinner
54            }
55            isLoading = false; // Reset the flag
56          },
57          error: function() {
58            isLoading = false; // Allow retries if there's an error
59          }
60        });
61      }
62    }
63  });
64
65  // Filter form submission
66  $('#resource_form_result_data').on('submit', function(e) {
67    e.preventDefault();
68    // Disable Load More while filtering
69    canLoadMore = false; // Disable Load More immediately during the filter
70    $('#loading-spinner').show(); // Show the loading spinner while filtering
71
72    var form = $('#resource_form_result_data').serialize();
73    //var form = $(this).serializeArray();
74    if (form != '') {
75      $.ajax({
76        data: {
77          action: 'resource_filter_ajax',
78          form_data: form,
79        },
80        type: 'POST',
81        url: vdcforum_ajax_object.ajax_url,
82        beforeSend: function() {
83          $('#resource-submit').val('Please wait...').attr('disabled', 'disabled');
84        },
85        success: function(response) {
86          var obj = JSON.parse(response);
87
88          // Check if the response contains posts
89          if (obj.html.trim() === "") {
90            
91            $('#loading-spinner').hide(); // Hide the spinner if no posts are returned
92            $('#resource-submit').val('No Posts Found').prop("disabled", true); // Optionally, disable the submit button or change text
93            canLoadMore = false; // Disable further "Load More" when no posts are found
94          } else {
95            
96            $('.allresourcePosts').html(obj.html); // Update the posts with filtered results
97            $("#curr_page_num").val(1); // Reset page number to 1 after filter
98            $('#resource-submit').val('Filter').prop("disabled", false); // Re-enable the button
99            $('#loading-spinner').hide(); // Hide the spinner once the data is loaded
100
101            // Enable Load More again after filter is applied
102            canLoadMore = true; // Re-enable "Load More"
103
104            // Force the scroll event to check if "Load More" should be triggered immediately
105            $(window).trigger("scroll");
106          }
107        },
108        error: function() {
109          $('#resource-submit').val('Error! Try Again').prop("disabled", false); // Handle error
110          $('#loading-spinner').hide(); // Hide the spinner in case of an error
111        }
112      });
113    }
114  });
115});
116
117
118$(document).ready(function() {
119      $('.select-filter').select2(); // Apply Chosen to elements with select-filter class
120  });
121*/
122
123 function fetchPosts_vdcforum_resource(page = 1) {
124      const form = $('#vdcforum-resource-filter-form');
125      const data = form.serialize() + '&action=vdcforum_resource_ajax_filter&page=' + page;
126
127      $.ajax({
128          url: vdcforum_resource_ajax_filter.ajax_url,
129          type: 'POST',
130          data: data,
131          beforeSend: function () {
132              $('#vdcforum-resource-results').html('<p>Loading...</p>');
133          },
134          success: function (response) {
135              $('#vdcforum-resource-results').html(response);
136          }
137      });
138  }
139
140  fetchPosts_vdcforum_resource();
141
142        // Update child term dropdown on parent change
143$(document).on('change', '.parent-term', function () {
144    const parentID = $(this).val();
145    const taxonomy = $(this).data('taxonomy');
146    const childSelect = $('.child-term[data-taxonomy="' + taxonomy + '"]');
147
148    // Clear child dropdown
149    childSelect.html('<option value="">Categories</option>');
150
151    // Remove existing taxonomy input for this taxonomy
152    $('input[name="taxonomy[' + taxonomy + ']"]').remove();
153
154    if (!parentID) {
155        fetchPosts_vdcforum_resource();
156        return;
157    }
158
159    // Only add parent filter if no child is selected
160    const selectedChild = childSelect.val();
161    if (!selectedChild) {
162        // Get parent slug via AJAX
163        $.ajax({
164            url: vdcforum_resource_ajax_filter.ajax_url,
165            method: 'POST',
166            data: {
167                action: 'get_term_slug_by_id',
168                term_id: parentID,
169                taxonomy: taxonomy
170            },
171            success: function (res) {
172                if (res.success && res.data.slug) {
173                    $('#vdcforum-resource-filter-form').append(
174                        '<input type="hidden" name="taxonomy[' + taxonomy + ']" value="' + res.data.slug + '">'
175                    );
176                    fetchPosts_vdcforum_resource();
177                }
178            }
179        });
180    }
181
182    // Load child terms regardless
183    $.ajax({
184        url: vdcforum_resource_ajax_filter.ajax_url,
185        method: 'POST',
186        data: {
187            action: 'get_child_terms',
188            parent_id: parentID,
189            taxonomy: taxonomy
190        },
191        beforeSend: function () {
192            childSelect.html('<option>Loading...</option>');
193        },
194        success: function (res) {
195            if (res.success) {
196                let options = '<option value="">Categories</option>';
197                res.data.terms.forEach(function (term) {
198                    options += '<option value="' + term.id + '">' + term.name + '</option>';
199                });
200                childSelect.html(options);
201            } else {
202                childSelect.html('<option value="">Categories</option>');
203            }
204        }
205    });
206});
207
208
209        // Filter on child dropdown change
210       
211        $(document).on('change', '.child-term', function () {
212            const taxonomy = $(this).data('taxonomy');
213            const childSlug = $(this).val();
214
215            // Remove any existing hidden taxonomy input for this taxonomy
216            $('input[name="taxonomy[' + taxonomy + ']"]').remove();
217
218            if (childSlug) {
219                // Add hidden input with child term slug
220                $('#vdcforum-resource-filter-form').append(
221                    '<input type="hidden" name="taxonomy[' + taxonomy + ']" value="' + childSlug + '">'
222                );
223            } else {
224                // If child is empty, re-trigger parent to add its input again
225                $('.parent-term[data-taxonomy="' + taxonomy + '"]').trigger('change');
226            }
227
228            fetchPosts_vdcforum_resource();
229        });
230
231        // Search input filter
232        $(document).on('keyup', '#vdcforum-resource-filter-form input[name="search"]', function () {
233            clearTimeout($.data(this, 'timer'));
234            const wait = setTimeout(fetchPosts_vdcforum_resource, 500);
235            $(this).data('timer', wait);
236        });
237
238        // Pagination
239        $(document).on('click', '#vdcforum-resource-pagination a', function (e) {
240            e.preventDefault();
241            const page = $(this).data('page');
242            fetchPosts_vdcforum_resource(page);
243        });
244
245
246
247
248})(jQuery);
249
250
251/*function toggleDropdown(button) {
252  const dropdown = button.nextElementSibling;
253  const arrow = button.querySelector('.arrow');
254
255  const isOpen = dropdown.classList.contains('show');
256
257  document.querySelectorAll('.filter-options').forEach(el => el.classList.remove('show'));
258  document.querySelectorAll('.arrow').forEach(a => a.classList.remove('rotate'));
259
260  if (!isOpen) {
261    dropdown.classList.add('show');
262    arrow.classList.add('rotate');
263  }
264}
265
266// Close dropdown on outside click
267document.addEventListener('click', function(e) {
268  document.querySelectorAll('.filter-dropdown').forEach(drop => {
269    if (!drop.contains(e.target)) {
270      drop.querySelector('.filter-options').classList.remove('show');
271      drop.querySelector('.arrow').classList.remove('rotate');
272    }
273  });
274});*/

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.