Skip to content

Commit

Permalink
Merge pull request #157 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Add an intersection observer
  • Loading branch information
Ziedelth authored Feb 8, 2024
2 parents 0a659cc + 5a0bf68 commit 02a84cc
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
15 changes: 15 additions & 0 deletions src/main/resources/assets/js/intersection_observer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const images = document.querySelectorAll('img[loading="lazy"]');

const observer = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const image = entry.target;
image.src = image.dataset.src;
observer.unobserve(image);
}
});
});

images.forEach((image) => {
observer.observe(image);
});
1 change: 1 addition & 0 deletions src/main/resources/templates/site/anime.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
</div>
<script src="/assets/js/hover_cards.js"></script>
<script src="/assets/js/intersection_observer.js"></script>
</@navigation.display>
1 change: 1 addition & 0 deletions src/main/resources/templates/site/catalog.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
</div>

<script src="/assets/js/hover_cards.js"></script>
<script src="/assets/js/intersection_observer.js"></script>
</@navigation.display>
2 changes: 1 addition & 1 deletion src/main/resources/templates/site/components/anime.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<article>
<a href="/animes/${anime.slug}" class="text-decoration-none text-white">
<div class="hover-card position-relative">
<img loading="lazy" src="https://api.shikkanime.fr/v1/attachments?uuid=${anime.uuid}&type=image"
<img loading="lazy" data-src="https://api.shikkanime.fr/v1/attachments?uuid=${anime.uuid}&type=image"
alt="${anime.shortName?replace("\"", "'")} anime image" class="w-100">
<span class="h6 mt-2 text-truncate-2">${anime.shortName}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/site/components/episode.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a href="${episode.url}" target="_blank" class="text-decoration-none text-white">
<div class="hover-card position-relative">
<div class="position-relative">
<img loading="lazy" src="https://api.shikkanime.fr/v1/attachments?uuid=${episode.uuid}&type=image"
<img loading="lazy" data-src="https://api.shikkanime.fr/v1/attachments?uuid=${episode.uuid}&type=image"
alt="${episode.anime.shortName?replace("\"", "'")} episode preview image"
class="w-100<#if episode.uncensored> blur</#if>">
<img src="https://www.shikkanime.fr/assets/img/platforms/${episode.platform.image}"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/site/home.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
</div>

<script src="/assets/js/hover_cards.js"></script>
<script src="/assets/js/intersection_observer.js"></script>
</@navigation.display>
22 changes: 0 additions & 22 deletions src/test/kotlin/fr/shikkanime/AnimeSlug.kt

This file was deleted.

0 comments on commit 02a84cc

Please sign in to comment.