From 8cefd042a9b1fb996d91a4121baecc67ef30ca1d Mon Sep 17 00:00:00 2001 From: eki89 Date: Thu, 27 Oct 2022 12:39:44 +0200 Subject: [PATCH] Init of "google maps api ready" event moved from maps bundle into google services bundle --- .../templates/js/js_em_google_services.html5 | 24 +------------------ src/Resources/public/google-maps-api-ready.js | 19 +++++++++++++++ 2 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 src/Resources/public/google-maps-api-ready.js diff --git a/src/Resources/contao/templates/js/js_em_google_services.html5 b/src/Resources/contao/templates/js/js_em_google_services.html5 index cda7d08..9f59ee8 100644 --- a/src/Resources/contao/templates/js/js_em_google_services.html5 +++ b/src/Resources/contao/templates/js/js_em_google_services.html5 @@ -1,27 +1,5 @@ - - diff --git a/src/Resources/public/google-maps-api-ready.js b/src/Resources/public/google-maps-api-ready.js new file mode 100644 index 0000000..ca9b482 --- /dev/null +++ b/src/Resources/public/google-maps-api-ready.js @@ -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); +}