Skip to content

Commit

Permalink
Support ?forceBlankTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Jun 3, 2023
1 parent 85fcd6b commit 5c04720
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/_js/map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(function() {

const IS_TIBIAMAPS_IO = location.origin === 'https://tibiamaps.io';
function TibiaMap() {
this.map = null;
this.crosshairs = null;
Expand Down Expand Up @@ -195,7 +197,7 @@
'flag', 'lock', 'mouth', 'red down', 'red left', 'red right',
'red up', 'skull', 'spear', 'star', 'sword', 'up',
];
const IMAGE_URL_PREFIX = location.origin === 'https://tibiamaps.io' ? '/_img/marker-icons/' : '_img/marker-icons/';
const IMAGE_URL_PREFIX = IS_TIBIAMAPS_IO ? '/_img/marker-icons/' : '_img/marker-icons/';
symbols.forEach(s => {
icons[s] = L.icon({
iconSize: [11, 11],
Expand Down Expand Up @@ -410,17 +412,26 @@
};

const unembed = function(url) {
return url.replace('/embed', '');
const updated = url.replace('/embed', '').replace('?forceBlankTarget', '');
return updated;
};

const fullscreen = document.querySelector('.leaflet-control-fullscreen-button');
// Make the fullscreen ‘button’ act as a permalink in embed views.
if (isEmbed) {
// Ensure right-click → copy URL works.
fullscreen.href = unembed(location.href);
const forceBlankTarget = new URLSearchParams(location.search).has('forceBlankTarget');
if (forceBlankTarget) {
fullscreen.target = '_blank';
}
// Override the fullscreen behavior.
fullscreen.addEventListener('click', function(event) {
window.top.location = unembed(location.href);
if (forceBlankTarget) {
window.open(fullscreen.href, '_blank');
} else {
window.top.location = fullscreen.href;
}
event.stopPropagation();
});
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<link rel="icon" href="favicon.ico">
</head>
<body>
<h1>Embedding the map viewer</h1>
<h2>Without <code>forceBlankTarget</code></h2>
<iframe src="embed/#32659,32117,7:2"></iframe>
<h2>With <code>forceBlankTarget</code></h2>
<iframe src="embed/?forceBlankTarget#32659,32117,7:2"></iframe>
</body>
</html>

0 comments on commit 5c04720

Please sign in to comment.