Last active
February 18, 2017 03:53
-
-
Save Fitoussi/6f30b80acba12a717f3dce9ffdbb83ae to your computer and use it in GitHub Desktop.
Trigger map resize when inside a tab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gmw_resize_tab_map() { | |
?> | |
<script type="text/javascript"> | |
jQuery( 'document' ).ready( function($) { | |
// on click | |
jQuery( '.test_tab' ).on( 'click', function() { | |
setTimeout(function() { | |
// search for the map ID | |
var mapId = jQuery( '#tab-test' ).find( '.gmw-map' ).attr( 'id' ).replace(/[^0-9]/g, ''); | |
if ( typeof gmwMapObjects[mapId] !== undefined ) { | |
// resize map | |
google.maps.event.trigger( gmwMapObjects[mapId].map, 'resize' ); | |
// pan to marker | |
gmwMapObjects[mapId].map.panTo( gmwMapObjects[mapId]['markers'][0].getPosition() ); | |
} | |
}, 100); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'gmw_resize_tab_map', 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment