Skip to content

Commit

Permalink
Apply view transition to medium cover if found
Browse files Browse the repository at this point in the history
  • Loading branch information
opatry committed Jan 5, 2025
1 parent 6e21062 commit f3d3675
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion content/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ uuid: d45018b8-4b50-4d56-a403-aee411ab5931
---

<%
# TODO Ideally the view-transition should be applied to these cover as well, not the case for now
books = recent_books
unless books.empty?
%>
Expand Down
11 changes: 9 additions & 2 deletions content/static/view-transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ window.addEventListener('pageswap', async (e) => {
const isbn = targetBookMatch.pathname.groups.isbn
setTemporaryViewTransitionNames([
[document.querySelector('.profile-picture'), 'avatar'],
[document.querySelector(`img[src='/cover/${isbn}-mini.jpg']`), 'cover'],
[
// favor medium if any, fallback to mini otherwise
document.querySelector(`img[src='/cover/${isbn}-medium.jpg']`) || document.querySelector(`img[src='/cover/${isbn}-mini.jpg']`),
'cover'
],
], e.viewTransition.finished);
}
}
Expand All @@ -48,7 +52,10 @@ window.addEventListener('pagereveal', async (e) => {
const isbn = fromBookMatch.pathname.groups.isbn
setTemporaryViewTransitionNames([
[document.querySelector('.profile-picture'), 'avatar'],
[document.querySelector(`img[src='/cover/${isbn}-mini.jpg']`), 'cover'],
[
document.querySelector(`img[src='/cover/${isbn}-medium.jpg']`) || document.querySelector(`img[src='/cover/${isbn}-mini.jpg']`),
'cover'
],
], e.viewTransition.ready);
}

Expand Down

0 comments on commit f3d3675

Please sign in to comment.