Skip to content

Commit

Permalink
feat: Adding noscript handling for map
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed May 21, 2022
1 parent 50643c7 commit f18681d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
25 changes: 15 additions & 10 deletions cmd/fibr/templates/map-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ <h2 class="flex flex-center header no-margin">
<a href="#" class="button white small">Close</a>
</h2>

<div id="map-container" class="flex flex-center"></div>
{{ $geoURL := "?geojson" }}
{{ if .Search }}
{{ $geoURL = printf "%s&%s" $geoURL .Search.Encode }}
{{ end }}

<div id="map-container" class="flex flex-center">
<noscript class="white">
<h2>You must enable Javascript to have interactive map with pictures.</h2>
<p>
GeoJSON data are available on <a class="primary" href="{{ $geoURL }}">this link</a>
</p>
</noscript>
</div>

<style type="text/css" nonce="{{ .nonce }}">
#map-container {
background-color: var(--grey);
color: var(--dark);
height: 80vh;
width: 90vw;
width: 80vw;
}

.thumbnail-img {
Expand All @@ -50,14 +62,7 @@ <h2 class="flex flex-center header no-margin">

<script type="text/javascript" nonce="{{ .nonce }}">
async function fetchGeoJSON() {
fetchURL = document.location.search
if (fetchURL.includes('?')) {
fetchURL += "&geojson"
} else {
fetchURL += "?geojson"
}

const response = await fetch(fetchURL, { credentials: 'same-origin' });
const response = await fetch('{{ $geoURL }}', { credentials: 'same-origin' });

if (response.status >= 400) {
throw new Error('unable to load geojson');
Expand Down
10 changes: 1 addition & 9 deletions pkg/fibr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import (

func isMethodAllowed(r *http.Request) bool {
switch r.Method {
case http.MethodGet:
fallthrough
case http.MethodPost:
fallthrough
case http.MethodPut:
fallthrough
case http.MethodPatch:
fallthrough
case http.MethodDelete:
case http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete:
return true
default:
return false
Expand Down

0 comments on commit f18681d

Please sign in to comment.