Skip to content

Commit 31e758a

Browse files
committedJan 18, 2021
feat: handle error on load page
1 parent 30a5854 commit 31e758a

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed
 

‎assets/js/main.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,25 @@
243243
el.addEventListener('click', function(evt){
244244
evt.preventDefault();
245245
evt.stopPropagation();
246+
247+
const url = el.getAttribute('modal-href');
248+
const $spinner = $modal.find('#modal-spinner');
249+
const $content = $modal.find('#modal-content');
250+
$spinner.show();
246251
$modal.fadeIn();
247-
let url = el.getAttribute('modal-href');
248-
let $content = $modal.find('#modal-content');
252+
249253
$.ajax({
250254
url: 'pages/' + url,
255+
dataType: 'html',
251256
success: function(html){
252257
$content.html(html);
258+
},
259+
error: function(request, status, error) {
260+
let text = request.responseText || "Page Not Found";
261+
$content.html(`<h1>${request.status} ${request.statusText}</h1><p style="color:#ff4545;">${text}</p>`);
262+
},
263+
complete: function() {
264+
$spinner.hide();
253265
}
254266
})
255267
});

‎index.html

+12-3
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ <h1 class="heading">Apps &amp; Projects</h1>
294294
</div>
295295
</div>
296296
<div class="col app-wrapper">
297-
<a href="#" modal-href="sample.html" class="app display-block">
297+
<a href="#" modal-href="sample.html" modal-bg="#eee" modal-fg="#333" class="app display-block">
298298
<img src="images/logos/buffalo-chess.png" alt="" />
299299
</a>
300300
<div class="details">
@@ -310,15 +310,15 @@ <h1 class="heading">Apps &amp; Projects</h1>
310310
</div>
311311
</div>
312312
<div class="col app-wrapper">
313-
<a href="#" modal-href="sample.html" class="app display-block">
313+
<a href="#" modal-href="sample2.html" class="app display-block">
314314
<img src="images/logos/rubiks-race.png" alt="" />
315315
</a>
316316
<div class="details">
317317
<p>Rubik's Race</p>
318318
</div>
319319
</div>
320320
<div class="col app-wrapper">
321-
<a href="#" modal-href="sample.html" class="app display-block">
321+
<a href="#" modal-href="sample3.html" class="app display-block">
322322
<img src="images/logos/jcloud.png" alt="" />
323323
</a>
324324
<div class="details">
@@ -415,6 +415,15 @@ <h5>Links</h5>
415415
</div>
416416
<div class="modal-wrapper">
417417
<div class="inner">
418+
<div class="text-center" id="modal-spinner" style="padding: 3em 0;">
419+
<div class="spinner-grow" style="width: 1rem; height: 1rem; animation-delay: 0ms;" role="status">
420+
<span class="sr-only">Loading...</span>
421+
</div>
422+
<div class="spinner-grow" style="width: 1rem; height: 1rem; animation-delay: 100ms; margin-left: 1rem;" role="status">
423+
</div>
424+
<div class="spinner-grow" style="width: 1rem; height: 1rem; animation-delay: 200ms; margin-left: 1rem;" role="status">
425+
</div>
426+
</div>
418427
<div class="container my-5" id="modal-content">
419428
</div>
420429
</div>

0 commit comments

Comments
 (0)