Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery('.filter-link').on('click', function(e) {
- e.preventDefault();
- jQuery(this).toggleClass('activeFilter');
- console.log(jQuery(this).data('type'));
- editFilterInputs(jQuery('#filters-' + jQuery(this).data('type')), jQuery(this).data('id'));
- filterProducts();
- });
- function editFilterInputs(inputField, value) {
- const currentFilters = inputField.val().split(',');
- const newFilter = value.toString();
- if (currentFilters.includes(newFilter)) {
- const i = currentFilters.indexOf(newFilter);
- currentFilters.splice(i, 1);
- inputField.val(currentFilters);
- } else {
- inputField.val(inputField.val() + ',' + newFilter);
- }
- }
- function filterProducts() {
- const catIds = jQuery('#filters-category').val().split(',');
- const tagIds = jQuery('#filters-tag').val().split(',');
- jQuery.ajax({
- type: 'POST',
- url: 'https://staging.project-progress.net/projects/netstarta/wp-admin/admin-ajax.php',
- dataType: 'json',
- data: {
- action: 'filter_products',
- catIds,
- tagIds,
- },
- success: function(res) {
- jQuery('#result-count').html(res.total);
- jQuery('.project-tiles').html(res.html);
- },
- error: function(err) {
- console.error(err);
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment