Skip to content

Instantly share code, notes, and snippets.

@scope2229
Created May 22, 2018 19:12
Show Gist options
  • Save scope2229/6ea4d5d2a42f48f1af1538b580359a68 to your computer and use it in GitHub Desktop.
Save scope2229/6ea4d5d2a42f48f1af1538b580359a68 to your computer and use it in GitHub Desktop.
$(document).on('turbolinks:load', function() {
if (!(page.controller() === 'index' && page.action() === 'contact')) {
return;
}
Turbolinks.clearCache();
// only do this if you find the map_canvas_home, otherwise we don't need no maps
if (document.getElementById("map") !== null) {
// check to see if google map is loaded, if so, just init that map! Otherwise, create the script tag
if (isMapsApiLoaded) {
initMap();
} else {
//error is here for some reason when a link is clicked this file inserts another script
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?key=<%= ENV['GAPI'] %>&callback=initMap";
document.body.appendChild(script);
}
}
});
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment