Skip to content

Instantly share code, notes, and snippets.

@ethanhinson
Created August 29, 2013 23:47
Show Gist options
  • Save ethanhinson/6384764 to your computer and use it in GitHub Desktop.
Save ethanhinson/6384764 to your computer and use it in GitHub Desktop.
Resizing GoogleMaps inside of a div which is hidden
/**
* This example will work with foundation 4 sections. However, the idea is the same for any collapsed map.
* Load a map object
* Find it's parent (which is hidden)
* Bind a click event to the element which 'unhides' your container
* */
(function($) {
Drupal.behaviors.foundationCollapseHack = {
attach: function(context, settings) {
// check whether we have a map
if(typeof settings.vrListingMap != 'undefined') {
// on page load
$(window).load(function() {
// grab a map object
var map = Drupal.behaviors.vrwebListingMaps.map;
// if we have a section container
if($(map.b).parents('.section-container').length > 0) {
// find any maps in these tabs and bind a click to it
$(map.b).parents('section').find('p.title').children('a').click(function() {
// B.c of timing - it's important to wrap the resize stuff in a timeOut.
// This assures that getComputedStyle is not null when resize fires
setTimeout(function() {
var coord = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(new google.maps.LatLng(coord.lat(), coord.lng()), settings.vrListingMap.options.default_zoom);
}, 0 );
});
}
});
}
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment