Passer la navigation

[Résolu] Archive Page Built with Blocks – Insert Views 'frontend' event handler

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How do we Insert the Frontend event handler, as we need to run some Javascript after each filter is used to effect the Custom search?
Solution:

Using blocks, you can go to the JavaScript tab in the side bar and add your code: https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/

You can track when the filter is executed using 'js_event_wpv_parametric_search_results_updated', that should replace the need of running the code every X seconds.

Please check the explanation of my colleague here for further reference: https://toolset.com/forums/topic/javascript-call-back-function-of-scroll-to-top-map-while-using-ajax-pagination/#post-1437607

And here a skeleton of how you'd use js_event_wpv_parametric_search_results_updated: https://toolset.com/forums/topic/trigger-js-event-after-ajax-filtering-finished/#post-477382

This support ticket is created Il y a 2 years, 2 months. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Fuseau horaire du supporter : America/Sao_Paulo (GMT-03:00)

Ce sujet contient 1 reply, a 2 voix.

Dernière mise à jour par Mateus Getulio Il y a 2 years, 2 months.

Assisté par: Mateus Getulio.

Auteur
Publications
#2687254

Hi

We have had to build the Archive Page with Blocks, and the nine filters use Ajax to refresh the page content and filter the options.

How do we Insert the Frontend event handler, as we need to run some Javascript after each filter is used to effect the Custom search?

We want to update the Text overlays on the images.

lien caché

Just now we get around it with this code:

<script>
function initializeOverlays() {
var thumbnailContainers = document.querySelectorAll('.archive-image');

thumbnailContainers.forEach(function(container) {
// Check if the overlay already exists
var existingOverlay = container.querySelector('.year-round-overlay');
if (!existingOverlay) {
var overlay = document.createElement('div');
overlay.className = 'year-round-overlay';

// Retrieve the custom field value from the data attribute
var overlayText = container.getAttribute('data-overlay-text');
if (overlayText) {
overlay.textContent = overlayText;
container.appendChild(overlay);
}
}
});
}

// Run initializeOverlays on DOMContentLoaded
document.addEventListener("DOMContentLoaded", function() {
initializeOverlays();
});

// Function to check for URL change
var lastUrl = location.href;
setInterval(function() {
if (location.href !== lastUrl) {
initializeOverlays();
lastUrl = location.href;
}
}, 1000); // Check every 1000 milliseconds (1 second)
</script>

But it's a bit messy, and not how it should be done.

Is there a better way to achieve this?

#2687319

Mateus Getulio
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Sao_Paulo (GMT-03:00)

Hello there,

Using blocks, you can go to the JavaScript tab in the side bar and add your code: https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/

You can track when the filter is executed using 'js_event_wpv_parametric_search_results_updated', that should replace the need of running the code every X seconds.

Please check the explanation of my colleague here for further reference: https://toolset.com/forums/topic/javascript-call-back-function-of-scroll-to-top-map-while-using-ajax-pagination/#post-1437607

And here a skeleton of how you'd use js_event_wpv_parametric_search_results_updated: https://toolset.com/forums/topic/trigger-js-event-after-ajax-filtering-finished/#post-477382

Please give it a try and let us know.
Mateus