|
| 1 | +{{/* A single large image (a map or diagram) with a full-screen view. |
| 2 | + Front matter: map_image (file in the page bundle), map_alt. Open the page with #full |
| 3 | + to land straight in the full-screen view. */}} |
| 4 | +{{ define "main" }} |
| 5 | +{{ $img := .Resources.GetMatch (.Params.map_image | default "map.webp") }} |
| 6 | +<div class="map-page"> |
| 7 | + <nav class="resources-breadcrumb" aria-label="Breadcrumb"> |
| 8 | + <a href="/resources/">Resources</a> |
| 9 | + <span class="breadcrumb-sep" aria-hidden="true">/</span> |
| 10 | + <span>{{ .Title }}</span> |
| 11 | + </nav> |
| 12 | + |
| 13 | + <header class="map-header"> |
| 14 | + <h1>{{ .Title }}</h1> |
| 15 | + {{ with .Description }}<p class="map-lead">{{ . }}</p>{{ end }} |
| 16 | + </header> |
| 17 | + |
| 18 | + {{ with $img }} |
| 19 | + <div class="map-toolbar"> |
| 20 | + <button type="button" class="map-btn map-btn--primary" id="map-fullscreen">Full screen</button> |
| 21 | + <a href="{{ .RelPermalink }}" class="map-btn" target="_blank" rel="noopener">Open the image ↗</a> |
| 22 | + <a href="{{ .RelPermalink }}" class="map-btn" download>Download</a> |
| 23 | + <a href="/resources/software/" class="map-btn">Browse the tools →</a> |
| 24 | + </div> |
| 25 | + |
| 26 | + <figure class="map-stage" id="map-stage"> |
| 27 | + <button type="button" class="map-close" id="map-close" aria-label="Close full screen">✕</button> |
| 28 | + <img src="{{ .RelPermalink }}" alt="{{ $.Params.map_alt }}" width="{{ .Width }}" height="{{ .Height }}" id="map-img"> |
| 29 | + </figure> |
| 30 | + {{ end }} |
| 31 | +</div> |
| 32 | + |
| 33 | +<script> |
| 34 | +(function () { |
| 35 | + var stage = document.getElementById('map-stage'); |
| 36 | + if (!stage) return; |
| 37 | + var openBtn = document.getElementById('map-fullscreen'); |
| 38 | + var closeBtn = document.getElementById('map-close'); |
| 39 | + var img = document.getElementById('map-img'); |
| 40 | + |
| 41 | + function open() { |
| 42 | + stage.classList.add('is-full'); |
| 43 | + document.documentElement.classList.add('map-locked'); |
| 44 | + if (stage.requestFullscreen) { try { stage.requestFullscreen().catch(function () {}); } catch (e) {} } |
| 45 | + if (location.hash !== '#full') history.replaceState(null, '', '#full'); |
| 46 | + } |
| 47 | + function close() { |
| 48 | + stage.classList.remove('is-full', 'is-zoomed'); |
| 49 | + document.documentElement.classList.remove('map-locked'); |
| 50 | + if (document.fullscreenElement && document.exitFullscreen) { try { document.exitFullscreen(); } catch (e) {} } |
| 51 | + if (location.hash === '#full') history.replaceState(null, '', location.pathname + location.search); |
| 52 | + } |
| 53 | + |
| 54 | + openBtn.addEventListener('click', open); |
| 55 | + closeBtn.addEventListener('click', close); |
| 56 | + img.addEventListener('click', function () { |
| 57 | + if (!stage.classList.contains('is-full')) { open(); return; } |
| 58 | + stage.classList.toggle('is-zoomed'); |
| 59 | + }); |
| 60 | + document.addEventListener('keydown', function (e) { if (e.key === 'Escape' && stage.classList.contains('is-full')) close(); }); |
| 61 | + document.addEventListener('fullscreenchange', function () { |
| 62 | + if (!document.fullscreenElement && stage.classList.contains('is-full')) close(); |
| 63 | + }); |
| 64 | + |
| 65 | + // Landing on /#full shows the map filling the window (browsers only allow the |
| 66 | + // true full-screen mode after a click, so this uses the in-page full-window view). |
| 67 | + if (location.hash === '#full') { |
| 68 | + stage.classList.add('is-full'); |
| 69 | + document.documentElement.classList.add('map-locked'); |
| 70 | + } |
| 71 | +})(); |
| 72 | +</script> |
| 73 | +{{ end }} |
0 commit comments