I have a search result page, with the first set of data being fetched during the page load, and we add a Load More button. Clicking on this button fires an AJAX call, using the ajax_links_api module. After the AJAX call is completed, we append more search results to the current set. I have a behavior where I read the URL parameter; if it exists, I open a Colorbox.
If the colorbox opens on page load, we close it, and then click on Load More (which fires AJAX); then the Colorbox JavaScript is fired again, and we see the popup in action again.
I don’t want to fire the Colorbox JavaScript after AJAX is completed/fired.
I tried jQuery Once, but it didn’t work.
How can I achieve this? Can I detect when an AJAX call happens?
The following is the code I am using.
Drupal.behaviors.openColorbox = { attach: function (context, settings) { if ($('body', context).hasClass('page-search-site')) { var nid = url('?node'); if (nid != undefined) { if (nid.trim()) { $('div.search-result') .find('.node-' + nid) .once('colorbox-clicked') .click(); } } } } };