Skip Navigation

[Closed] When and which JQ eventlisteners will be resetted in custom search?

This support ticket is created 2 years, 1 month ago. 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Waqar 2 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#2483701

a.R

Hi 🙂

I´ve read somewhere, that on (infinite scroll) pagination (or other events?), some JQ eventlisteners will get lost?
So what do we have to do to keep them working?

Thank you 🙂

#2484447

Hi,

Thank you for contacting us and I'd be happy to assist.

Toolset views offer a number of useful events, which can be used to trigger or reinitialize script-based functions.

You'll find the list of those events, in this forum reply:
https://toolset.com/forums/topic/is-there-a-list-of-frontent-events/

I hope this helps and please let me know if you need any further assistance with this.

regards,
Waqar

#2484509

a.R

Thank you, but this is not exactly what I was asking for.

Some JQ eventlisteners will be deleted when a search is triggered, or at pagination, right?

It would help us SO much, if you could tell us, what evenlisteners will be deleted at which event?

THANK YOU 🙂

#2486243

Thanks for writing back.

Can you please share some background information about where exactly you read that some JQ event listeners will get lost? This will help in understanding the context of the statement.

It would also help if you could share a link to an example/demo page with infinite scrolling, where some functionality is lost, after the pagination.

This will help in narrowing down exactly what we're discussing.

#2488455

a.R

On hidden link many listeners will get lost, when triggering a search.
Much JQ won´t work on hidden link ('suche' is the german word for search).

#2490701

a.R

... What is going on there?

#2491037

Thank you for waiting and for sharing the links.

I apologize for the delay in getting back on this, as we had an unusually busy forum queue over the weekend.

I've checked the source code of the pages that you've shared and I've found a number of custom scripts that are set to execute when the page loading completes, i.e. on the 'ready' event.

For example:


(function($) {
	$( document ).ready(function() {
		// code to add some changes to page/DOM elements
	});
});

But when the search form or results are updated through AJAX, the DOM or page's elements are reloaded and are now different from the elements which are were originally loaded when the page loaded. So any functions that your custom script had attached to them on the page load, will no longer work on the newly loaded elements.

So it is not that your custom jQuery events or event listeners are getting removed on AJAX. It is just that after the AJAX, the DOM/page's content elements are replaced with new ones, which is why your previous event listeners can no longer recognize or associate with them.

To overcome this, you'll have to restructure your custom jQuery scripts so that they are not only executed on the 'ready' (page load) event but also when Toolset completes the AJAX requests.

For example:


(function($) {
	$( document ).on( 'ready js_event_wpv_pagination_completed js_event_wpv_parametric_search_form_updated js_event_wpv_parametric_search_results_updated', function( event, data ) {
		// code to add some changes to page/DOM elements
	});
});

In this second example, I've updated the code from the first example, to not only execute when the page loading completes ('ready' event) but also when the pagination completes ('js_event_wpv_pagination_completed' event), the search form is updated ('js_event_wpv_parametric_search_form_updated' event) and the search results are updated ('js_event_wpv_parametric_search_results_updated' event).

I hope this explanation will make this clearer and let me know if you have any follow up questions.

#2491117

a.R

Yes, thank you, we knew that.

But we think we see some other effects as well - will keep observing...

#2491769

Sure, please take your time and this ticket will stay open for a couple of weeks, in case you have any follow-up questions.

For a new question or concern, you're welcome to start a new ticket.

The topic ‘[Closed] When and which JQ eventlisteners will be resetted in custom search?’ is closed to new replies.