diff --git a/.gitignore b/.gitignore index e43b0f9..084ce8e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +bak/ diff --git a/assets/script-bak.js b/assets/script-bak.js deleted file mode 100644 index 2f57939..0000000 --- a/assets/script-bak.js +++ /dev/null @@ -1,176 +0,0 @@ -jQuery(document).ready(function ($) { - /** Triggers filtering and pagination of resources based on the current form state. - * - * @param {number} [paged=1] - The page number to query. - */ - function triggerFiltering(paged = 1) { - let searchTerm = $('#search').val(); - - let selectedTypes = $('input[name="resource_type[]"]:checked') - .map(function () { - return $(this).closest('label').text().trim(); - }) - .get(); - - let selectedSubjects = $('input[name="resource_subject[]"]:checked') - .map(function () { - return $(this).closest('label').text().trim(); - }) - .get(); - - let appliedFilters = []; - - // Search Term - if (searchTerm) { - appliedFilters.push( - ` - Search: "${searchTerm}" - - ` - ); - } - - // Resource Types - $('input[name="resource_type[]"]:checked').each(function () { - const slug = $(this).val(); // Get the slug - const name = $(this).closest('label').text().trim(); // Get the name - - appliedFilters.push( - ` - Type: ${name} - - ` - ); - }); - - // Resource Subjects - selectedSubjects.forEach(function (subject) { - appliedFilters.push( - ` - Subject: ${subject} - - ` - ); - }); - - $('#applied-filters').html( - appliedFilters.length ? appliedFilters.join(' ') : 'None' - ); - - let formData = { - action: 'filter_resources', - nonce: resourceFilterAjax.nonce, - search: $('#search').val(), - resource_type: $('input[name="resource_type[]"]:checked') - .map(function () { - return this.value; - }) - .get(), - resource_subject: $('input[name="resource_subject[]"]:checked') - .map(function () { - return this.value; - }) - .get(), - sort_order: $('#sort-order').val(), - paged: paged, - }; - - $.post(resourceFilterAjax.ajaxurl, formData, function (response) { - response = JSON.parse(response); - - $('#resource-results').html(response.html); - $('#result-count').text(response.count); - - // Update pagination - if (response.pagination && response.pagination.length > 0) { - // Clear and update pagination container - if (!$('.pagination').length) { - $('#resource-results').after(''); - } - $('.pagination').html(response.pagination.join('')); - } else { - $('.pagination').html(''); // Clear pagination if no links are needed - } - }); - } - - // Handle filter removal - $(document).on('click', '.remove-filter', function (e) { - e.preventDefault(); - - let $filter = $(this).closest('.filter-item'); - let filterType = $filter.data('type'); - let filterValue = $filter.data('value'); - - // Remove the corresponding filter - if (filterType === 'search') { - $('#search').val(''); - } else if (filterType === 'resource_type') { - $('input[name="resource_type[]"]:checked').each(function () { - if ($(this).val() === filterValue) { // Match the slug, not the name - $(this).prop('checked', false); - } - }); - } else if (filterType === 'resource_subject') { - $('input[name="resource_subject[]"]:checked').each(function () { - if ($(this).closest('label').text().trim() === filterValue) { - $(this).prop('checked', false); - } - }); - } - - // Re-trigger filtering after removing the filter - triggerFiltering(1); - }); - - // Handle form submission - $('#resource-filter').on('submit', function (e) { - e.preventDefault(); - triggerFiltering(); - }); - - // Handle sort order change - $('#sort-order').on('change', function () { - triggerFiltering(); - }); - - // Handle pagination click - $(document).on('click', '.pagination a', function (e) { - e.preventDefault(); - - // Extract the page number from the link - let pagedMatch = $(this).attr('href').match(/paged=(\d+)/); - let paged = pagedMatch ? pagedMatch[1] : 1; // Default to page 1 if no match is found - - // Trigger filtering for the selected page - triggerFiltering(paged); - }); -}); - -document.addEventListener('DOMContentLoaded', function () { - // Toggle dropdown visibility - document.querySelectorAll('.custom-dropdown .dropdown-toggle').forEach(function (button) { - button.addEventListener('click', function () { - const dropdown = this.parentElement; - - // Close all other dropdowns - document.querySelectorAll('.custom-dropdown').forEach(function (otherDropdown) { - if (otherDropdown !== dropdown) { - otherDropdown.classList.remove('open'); - } - }); - - // Toggle the current dropdown - dropdown.classList.toggle('open'); - }); - }); - - // Close dropdowns when clicking outside - document.addEventListener('click', function (event) { - if (!event.target.closest('.custom-dropdown')) { - document.querySelectorAll('.custom-dropdown').forEach(function (dropdown) { - dropdown.classList.remove('open'); - }); - } - }); -}); diff --git a/resource-filter.php b/resource-filter.php index b0c7109..5f1a03c 100644 --- a/resource-filter.php +++ b/resource-filter.php @@ -153,7 +153,7 @@ class ContentFilterPlugin { wp_enqueue_style('content-filter-style', $theme_stylesheet_url, [], filemtime($theme_stylesheet)); } else { // Fall back to the plugin's stylesheet - wp_enqueue_style('content-filter-style', plugins_url('assets/style.css', __FILE__), [], filemtime(plugin_dir_path(__FILE__) . 'assets/style.css')); + wp_enqueue_style('content-filter-style', plugins_url('templates/style.css', __FILE__), [], filemtime(plugin_dir_path(__FILE__) . 'templates/style.css')); } // Load script only if the shortcode is present on the page diff --git a/templates/filter-form-bak.php b/templates/filter-form-bak.php deleted file mode 100644 index 00024f3..0000000 --- a/templates/filter-form-bak.php +++ /dev/null @@ -1,48 +0,0 @@ - 'resource_type', 'hide_empty' => true]); -$resource_subjects = get_terms(['taxonomy' => 'resource_subject', 'hide_empty' => true]); -?> - - -
- -
- - - - -
- -
- -
- Resource Type - -
- - - -
-
- - -
- Resource Subject - -
- - - -
-
-
-
diff --git a/templates/filter-homepage-bak.php b/templates/filter-homepage-bak.php deleted file mode 100644 index b4af00d..0000000 --- a/templates/filter-homepage-bak.php +++ /dev/null @@ -1,20 +0,0 @@ - - -
- 'resource_type']); - - if (!empty($resource_types)) : - ?> - - - - - - -
diff --git a/templates/resource-results-bak.php b/templates/resource-results-bak.php deleted file mode 100644 index 1915e25..0000000 --- a/templates/resource-results-bak.php +++ /dev/null @@ -1,38 +0,0 @@ -ID; - $postTitle = get_the_title($postID); - $postLink = get_permalink($postID); - ?> -
-

- -
-

Resource Type: name); ?>

-

- Resource Subject(s): - name); - } else { - echo esc_html($subject->name) . ', '; - } - - $i++; - } - ?> -

-
-
- - -

No resources found.

- diff --git a/assets/style.css b/templates/style.css similarity index 100% rename from assets/style.css rename to templates/style.css