From 7295d5f87f83333695b80ac5a07cd460ecacf2c7 Mon Sep 17 00:00:00 2001 From: Ramil Valitov Date: Thu, 14 Jul 2016 00:47:49 +0300 Subject: [PATCH] [fix] removed duplicates for checking if Google maps script is linked correctly --- map_ex/views/widget.php | 67 ++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/map_ex/views/widget.php b/map_ex/views/widget.php index 2e7570b..dee0782 100644 --- a/map_ex/views/widget.php +++ b/map_ex/views/widget.php @@ -306,38 +306,43 @@ function() { $debug->printDebugStrings(); ?> jQuery(document).ready(function($){ - var countAPILoaded=0; - var isUsingMap=false; - var srcFirstAPI=''; - $("script").each(function() { - var srcAPI=$(this).attr("src"); - if ( (srcAPI) && (srcAPI.indexOf('/maps.google.com/')>0) ) { - console.info('Found Google Maps API loading script: '+srcAPI); - if (countAPILoaded==0) - srcFirstAPI=srcAPI; - countAPILoaded++; + if (typeof window.functionCheckMapExWidget === 'undefined') { + window.functionCheckMapExWidget = function() { + var countAPILoaded=0; + var isUsingMap=false; + var srcFirstAPI=''; + $("script").each(function() { + var srcAPI=$(this).attr("src"); + if ( (srcAPI) && (srcAPI.indexOf('/maps.google.com/')>0) ) { + console.info('Found Google Maps API loading script: '+srcAPI); + if (countAPILoaded==0) + srcFirstAPI=srcAPI; + countAPILoaded++; + } + if ( (srcAPI) && (srcAPI.indexOf('wkInitializeGoogleMapsApi')>0) ) + isUsingMap=true; + }); + switch(countAPILoaded){ + case 0: + console.error('No script found that loads Google Maps API. It\'s a fatal error. Possible reasons: invalid installation or conflict with other components, modules or plugins.'); + break; + case 1: + console.info('Single script detected that loads Google Maps API.'); + if (srcFirstAPI.length>0) + if (srcFirstAPI.indexOf('wkInitializeGoogleMapsEx')>0) + console.info('The Google Maps API loading script is correct.'); + else + console.error('The Google Maps API loading script is not correct. Some other component, module or plugin on your website overrides our script making this widget inactive.'); + break; + default: + if (isUsingMap) + console.error('We found out that you are using both MapEx and Map widget on the same page. This leads to conflicts and errors. You can use only MapEx or Map widget, but not both. You can convert all your Map widgets to MapEx widgets in the control panel.'); + else + console.error('Multiple scripts detected that try to load Google Maps API. This may cause unexpected behaviour or malfunction of the widget. Please, turn of other plugins that use Goolge Maps API to fix this error.'); + break; + } } - if ( (srcAPI) && (srcAPI.indexOf('wkInitializeGoogleMapsApi')>0) ) - isUsingMap=true; - }); - switch(countAPILoaded){ - case 0: - console.error('No script found that loads Google Maps API. It\'s a fatal error. Possible reasons: invalid installation or conflict with other components, modules or plugins.'); - break; - case 1: - console.info('Single script detected that loads Google Maps API.'); - if (srcFirstAPI.length>0) - if (srcFirstAPI.indexOf('wkInitializeGoogleMapsEx')>0) - console.info('The Google Maps API loading script is correct.'); - else - console.error('The Google Maps API loading script is not correct. Some other component, module or plugin on your website overrides our script making this widget inactive.'); - break; - default: - if (isUsingMap) - console.error('We found out that you are using both MapEx and Map widget on the same page. This leads to conflicts and errors. You can use only MapEx or Map widget, but not both. You can convert all your Map widgets to MapEx widgets in the control panel.'); - else - console.error('Multiple scripts detected that try to load Google Maps API. This may cause unexpected behaviour or malfunction of the widget. Please, turn of other plugins that use Goolge Maps API to fix this error.'); - break; + functionCheckMapExWidget(); } });