Skip to content

Instantly share code, notes, and snippets.

@AchalJ
Created June 8, 2023 11:03
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 AchalJ/2a4a35fed587a4f6e18892c65f6013a2 to your computer and use it in GitHub Desktop.
Save AchalJ/2a4a35fed587a4f6e18892c65f6013a2 to your computer and use it in GitHub Desktop.
PowerPack Google Map - Show Info Window on Hover Over Marker
// 1. Add the following CSS class to the PowerPack's Google Map module under the Advanced settings > HTML Element > Class: show-info-on-hover
// 2. Add this JavaScript code to Beaver Builder's Global JavaScript editor or in a JS file in your current child theme.
;(function($) {
var showInfoOnHover = function() {
var mapModules = $('.show-info-on-hover');
if ( mapModules.length === 0 ) {
return;
}
mapModules.each(function() {
var nodeId = $(this).data('node');
var moduleInstance = window['pp_map_' + nodeId];
if ( 'undefined' === typeof moduleInstance ) {
return;
}
moduleInstance.mapObjects.markers.forEach(function(marker, i) {
var infoWin = new google.maps.InfoWindow();
google.maps.event.addListener( marker, 'mouseover', (function ( marker, i ) {
return function () {
var contentString = '<div class="pp-infowindow-content">';
contentString += moduleInstance.infoWindowText[i];
contentString += '</div>';
infoWin.setContent(contentString);
infoWin.open( moduleInstance.mapObjects.map, marker );
}
})(marker, i));
google.maps.event.addListener( marker, 'mouseout', ( function ( infowindow ) {
return function () {
infowindow.close();
}
})(infoWin));
});
});
};
$(window).on('load', function() {
setTimeout(showInfoOnHover, 1000);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment