Skip to content

Commit 2e014f4

Browse files
committed
Add JSON syntax error modal
1 parent f60e570 commit 2e014f4

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

docs/viewer/index.html

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,28 @@
176176
input[type=text] {
177177
padding: 9px 0.5em !important;
178178
}
179+
180+
.error-modal {
181+
display: none;
182+
position: absolute;
183+
left: 15vw;
184+
right: 15vw;
185+
top: 15vw;
186+
bottom: 15vw;
187+
border: solid 2px red;
188+
background-color: #fee;
189+
cursor: pointer;
190+
font-size: 150%;
191+
}
192+
193+
.error-modal .message {
194+
padding: 5vw;
195+
display: inline-block;
196+
}
197+
198+
.error-modal .message::before {
199+
content: '\26A0 \A0 \A0';
200+
}
179201
</style>
180202
</head>
181203

@@ -207,6 +229,9 @@ <h2>Selection attributes</h2>
207229
This software is freely available for use, modification, and distribution under the MIT License, provided the original copyright notice and license terms are included.
208230
<a href="https://github.com/buildingSMART/IFC5-development/">https://github.com/buildingSMART/IFC5-development/</a>
209231
</div>
232+
<div class="error-modal" onclick="document.querySelector('.error-modal').style.display = 'none';">
233+
<span class="message"></span>
234+
</div>
210235
</div>
211236
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
212237
<script src="https://cdn.jsdelivr.net/npm/three@0.142.0/examples/js/controls/OrbitControls.js"></script>
@@ -221,18 +246,33 @@ <h2>Selection attributes</h2>
221246
if (file) {
222247
const reader = new FileReader();
223248
reader.onload = function(e) {
224-
addModel(file.name, JSON.parse(e.target.result));
249+
let json = null;
250+
try {
251+
json = JSON.parse(e.target.result);
252+
} catch(e) {
253+
document.querySelector('.error-modal .message').innerHTML = e.message;
254+
document.querySelector('.error-modal').style.display = 'block';
255+
}
256+
if (json) {
257+
addModel(file.name, json);
258+
}
225259
};
226260
reader.readAsText(file);
227261
}
228262
});
229263

230264
document.querySelector('#urlForm').addEventListener('submit', function(event) {
231265
event.preventDefault();
232-
fetch(event.target.urlInput.value).then(r => r.json()).then((j) => {
233-
const name = event.target.urlInput.value.split('/').reverse()[0];
234-
addModel(name, j);
235-
});
266+
fetch(event.target.urlInput.value)
267+
.then(r => r.json())
268+
.then((j) => {
269+
const name = event.target.urlInput.value.split('/').reverse()[0];
270+
addModel(name, j);
271+
})
272+
.catch(e => {
273+
document.querySelector('.error-modal .message').innerHTML = e.message;
274+
document.querySelector('.error-modal').style.display = 'block';
275+
});
236276
});
237277
</script>
238278
</body>

0 commit comments

Comments
 (0)