Skip to content

Instantly share code, notes, and snippets.

@KZeni
Last active November 9, 2019 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KZeni/20842ddc27483f22812191f45a934928 to your computer and use it in GitHub Desktop.
Save KZeni/20842ddc27483f22812191f45a934928 to your computer and use it in GitHub Desktop.
// Customize the map's marker behavior on the homepage
function customizeHomepageMapMarkerBehavior(){
if($('body.home').length > 0 && typeof WPGMZA !== 'undefined'){
$(WPGMZA.maps).each(function(){
$(this.markers).each(function(){
// Clear out previous googleMarker listener events
google.maps.event.clearListeners(this.googleMarker, 'mouseover');
google.maps.event.clearListeners(this.googleMarker, 'click');
// Create our own marker event listeners (note: `this.googleMarker` is for the Google Maps Marker itself while `this` is the WPGM marker [includes title & other info])
google.maps.event.addListener(this.googleMarker, 'mouseover', function(event) {
$('.location-details .group').hide(); // Hide the current community
$('.location-details .group h4:contains("'+this.title+'")').closest('.group').show(); // Show the appropriate community
$('.location-details select option').removeAttr('selected').filter(':contains("'+this.title+'")').prop('selected', true); // Set the selector to the correct community
});
google.maps.event.addListener(this.googleMarker, 'click', function(event) {
window.location.href = this.link; // Follow marker's link URL when clicked
});
});
});
}
}
customizeHomepageMapMarkerBehavior();
setTimeout(function(){customizeHomepageMapMarkerBehavior();},500);
setTimeout(function(){customizeHomepageMapMarkerBehavior();},1000);
setTimeout(function(){customizeHomepageMapMarkerBehavior();},2000);
setTimeout(function(){customizeHomepageMapMarkerBehavior();},5000);
setTimeout(function(){customizeHomepageMapMarkerBehavior();},10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment