callback on click? | WordPress.org

[ad_1]

Hi @efishinsea,

Thank you for getting in touch, we do appreciate your time.

Yes, this is possible in a few ways as we offer both an extendable JavaScript core, and various document events. For this example, I’ll showcase the event system as this is a bit simpler and more future-safe as it does not override any of the core modules.

Please see an example script below:

jQuery(($) => {
$(document.body).on('click.wpgmza', (event) => {
/* Check if the click originated from a marker */
if(event && event.target && event.target instanceof WPGMZA.Marker){
const marker = event.target;
const map = marker.map;
const infowindow = marker.infoWindow;

/* Note, the infowindow might not be ready yet. We'd recommend a short timeout here, to allow it to initialize */
console.log(marker, map, infowindow);
}
});
});

As an alternative, you may prefer to simply listen for infowindow (popup) open calls, as seen below:

jQuery(($) => {
$(document.body).on('infowindowopen.wpgmza', (event) => {
/* Act on the info-window, you can also access data from the event object */
if(event && event.target && event.target instanceof WPGMZA.InfoWindow){
const infowindowElement = event.target.element;
const infowindowMarker = event.target.feature;
const infowindowMap = event.target.parent;

console.log(infowindowElement, infowindowMarker, infowindowMap);
}
});
});

This second option may simplify the way you integrate with the plugin, as it will trigger whenever the popups are opened, instead of opening specifically on a marker click event.

I hope this helps?

My pleasure @efishinsea – Have a great day!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer