Skip to content

Commit

Permalink
Init of "google maps api ready" event moved from maps bundle into goo…
Browse files Browse the repository at this point in the history
…gle services bundle
  • Loading branch information
eki89 committed Oct 27, 2022
1 parent 0a1848c commit 8cefd04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
24 changes: 1 addition & 23 deletions src/Resources/contao/templates/js/js_em_google_services.html5
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

$GLOBALS['TL_JAVASCRIPT'][] = 'bundles/estatemanagergoogleservices/google-maps-api-ready.js|static';
$GLOBALS['TL_JAVASCRIPT'][] = 'https://maps.googleapis.com/maps/api/js?key=' . Contao\Config::get('googleApiToken') . '&libraries=places&callback=onGoogleMapsApiReady|async';

?>

<script>
/**
* Listen to Google Callback for start building the map
*/
function onGoogleMapsApiReady (e){
if (document.readyState !== 'complete') {
var stateCheck = setInterval(function() {
if (document.readyState === 'complete') {
clearInterval(stateCheck);
onGoogleMapsApiReady(e);
}
}, 100);

return false;
}

var customOnReadyEvent = new CustomEvent('googlemaps.onApiReady', {detail: e});

document.dispatchEvent(customOnReadyEvent);
}
</script>
19 changes: 19 additions & 0 deletions src/Resources/public/google-maps-api-ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Listen to Google Callback for start building the map
*/
function onGoogleMapsApiReady (e){
if (document.readyState !== 'complete') {
var stateCheck = setInterval(function() {
if (document.readyState === 'complete') {
clearInterval(stateCheck);
onGoogleMapsApiReady(e);
}
}, 100);

return false;
}

var customOnReadyEvent = new CustomEvent('googlemaps.onApiReady', {detail: e});

document.dispatchEvent(customOnReadyEvent);
}

0 comments on commit 8cefd04

Please sign in to comment.