Skip to content

Commit 5e314dd

Browse files
committed
refactor image includes by support @tomkyle
1 parent 2f1bfec commit 5e314dd

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

src/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ <h3 class="font-bold text-xl md:text-2xl mb-1">Open Source und frei nutzbar</h3>
8686

8787
<div id="sidebarContent"
8888
class="relative bg-white border border-slate-300 leading-normal lg:text-lg m-3 rounded text-black text-md hidden">
89+
<style>
90+
#detailImage {
91+
display: none;
92+
}
93+
94+
#detailImage:has(img.loaded) {
95+
display: block;
96+
}
97+
</style>
8998
<div id="detailImage"></div>
9099
<ul class="p-3 space-y-3" id="detailList"></ul>
91100
</div>

src/main.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,27 @@ async function fetchJsonData(url) {
131131
async function fetchBlob(url, monumentFunction) {
132132
if (!url || typeof url !== 'string') return
133133

134-
try {
135-
const response = await fetch(url, { method: 'get', mode: 'cors' })
136-
if (!response.ok) {
137-
console.warn(`${url} returned HTTP status code ${response.status}`)
138-
return
139-
}
140-
const blob = await response.blob()
141-
const imageUrl = URL.createObjectURL(blob)
142-
const imageElement = document.createElement('img')
143-
imageElement.src = imageUrl
144-
imageElement.setAttribute('alt', monumentFunction || 'Denkmalschutz')
145-
146-
const divElement = document.createElement('div')
147-
divElement.classList.add('px-3', 'py-2', 'w-full', 'text-xs', 'text-gray-100', 'bg-gray-600')
148-
divElement.innerText = 'Foto © Landesamt für Denkmalpflege'
149-
150-
const container = document.querySelector('#detailImage')
151-
if (!container) {
152-
console.error('Element #detailImage not found')
153-
return
154-
}
155-
container.appendChild(imageElement)
156-
container.appendChild(divElement)
157-
} catch (error) {
158-
console.error('Error in fetchBlob:', error)
134+
const container = document.querySelector('#detailImage')
135+
container.innerHTML = ''
136+
137+
const imageElement = document.createElement('img')
138+
imageElement.src = url
139+
140+
imageElement.onload = () => { imageElement.classList.add('loaded') }
141+
// imageElement.onerror = () => { container.classList.add('hidden') }
142+
imageElement.setAttribute('alt', monumentFunction || 'Denkmalschutz')
143+
144+
const divElement = document.createElement('div')
145+
divElement.classList.add('px-3', 'py-2', 'w-full', 'text-xs', 'text-gray-100', 'bg-gray-600')
146+
divElement.innerText = 'Foto © Landesamt für Denkmalpflege'
147+
148+
if (!container) {
149+
console.error('Element #detailImage not found')
150+
return
159151
}
152+
153+
container.appendChild(imageElement)
154+
container.appendChild(divElement)
160155
}
161156

162157
async function fetchMonumentPointsByBounds() {

0 commit comments

Comments
 (0)