Skip to content

Commit

Permalink
Improve redirect handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Feb 11, 2022
1 parent 07f4fd0 commit 8c37551
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 9 additions & 10 deletions resources/GoogleMaps/jquery.googlemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 ) {
Expand Down
13 changes: 12 additions & 1 deletion resources/leaflet/jquery.leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8c37551

Please sign in to comment.