diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 1f70e996a..0da9e36b9 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -5,7 +5,10 @@ different releases and which versions of PHP and MediaWiki they support, see the ## Maps 9.0.6 +Released on February 11th, 2022. + * Fixed warning occurring when using an invalid map type in Google Maps `types` parameter +* Improved redirect handling for both Google Maps and Leaflet ## Maps 9.0.5 diff --git a/resources/GoogleMaps/jquery.googlemap.js b/resources/GoogleMaps/jquery.googlemap.js index 435e7fef4..f78073e15 100644 --- a/resources/GoogleMaps/jquery.googlemap.js +++ b/resources/GoogleMaps/jquery.googlemap.js @@ -112,7 +112,7 @@ google.maps.event.addListener(marker, 'click', function (e) { if (e.target !== undefined && (e.target instanceof HTMLAnchorElement || e.target.tagName == 'A')) { //click link defined in inlinelabel - window.location.href = e.target.href; + redirectToUrl( e.target.href ); } else { openBubbleOrLink.call(this, markerData, e, marker); } @@ -794,23 +794,22 @@ } function openBubbleOrLink(markerData, event, obj) { - if (markerData.link && isValidHttpUrl(markerData.link)) { - window.location.href = markerData.link; + if ( markerData.link ) { + redirectToUrl( markerData.link ); } else if (markerData.text.trim() !== '') { openBubble.call(this, markerData, event, obj); } } - function isValidHttpUrl(string) { - let url; - + function redirectToUrl( url ) { try { - url = new URL(string); + let urlObject = new URL( url ); + + if ( urlObject.protocol === "http:" || urlObject.protocol === "https:" ) { + window.location.href = url; + } } catch (_) { - return false; } - - return url.protocol === "http:" || url.protocol === "https:"; } function openBubble( markerData, event, obj ) { diff --git a/resources/leaflet/jquery.leaflet.js b/resources/leaflet/jquery.leaflet.js index 351571977..406a8e860 100644 --- a/resources/leaflet/jquery.leaflet.js +++ b/resources/leaflet/jquery.leaflet.js @@ -213,12 +213,23 @@ this.map.on( 'click', function(e) { - window.location.href = newClickTargetUrl(e.latlng); + _this.redirectToUrl( newClickTargetUrl( e.latlng ) ); } ); } }; + this.redirectToUrl = function( url ) { + try { + let urlObject = new URL( url ); + + if ( urlObject.protocol === "http:" || urlObject.protocol === "https:" ) { + window.location.href = url; + } + } catch (_) { + } + } + this.getBaseLayers = function() { if ( options.imageLayers.length === 0 ) { return this.getNormalBaseLayers();