Skip to content

Commit

Permalink
Support users with disabled JS
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Feb 1, 2023
1 parent 0ebb971 commit 3a79111
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
23 changes: 21 additions & 2 deletions src/routes/(site)/genuary/collage.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
<script lang="ts">
import { onMount } from 'svelte';
import Dialog from './dialog.svelte';
import Media from './media.svelte';
import type { CollagePiece } from './collage';
export let data: CollagePiece[] = [];
const anchors: HTMLAnchorElement[] = [];
onMount(() => {
anchors.forEach((anchor) => {
anchor.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
});
});
});
</script>

<div class="grid-outer-wrapper">
Expand All @@ -14,7 +27,13 @@
{@const video = src.endsWith('.mp4') || src.endsWith('.mov')}
{@const ext = src.split('.').pop()}
<div class="artwork-container">
<div class="artwork">
<a
class="artwork"
bind:this={anchors[i]}
href={src}
target="_blank"
rel="noopener noreferrer"
>
<Dialog>
<Media {src} {video} {alt} {view} slot="opener" rounded={true} />

Expand All @@ -28,7 +47,7 @@
<span role="button" class="closer">Close</span>
</div>
</Dialog>
</div>
</a>
</div>
{/each}
</div>
Expand Down
45 changes: 27 additions & 18 deletions src/routes/(site)/genuary/media.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
export let rounded = false;
</script>

<svelte:element
this={video ? 'video' : 'img'}
class="media"
{src}
{alt}
class:wide={view === 'wide'}
class:tall={view === 'tall'}
class:big={view === 'big'}
autoplay={video}
loop={video}
muted={true}
playsinline={video}
style:--border-radius={rounded ? '5px' : undefined}
/>
<a href={src} class="media-container" target="_blank" rel="noopener noreferrer">
<svelte:element
this={video ? 'video' : 'img'}
{src}
{alt}
class="media"
class:wide={view === 'wide'}
class:tall={view === 'tall'}
class:big={view === 'big'}
loading="lazy"
autoplay={video}
loop={video}
muted={true}
style:--border-radius={rounded ? '5px' : undefined}
/>
</a>

<style lang="scss">
.media {
.media-container {
max-width: 100%;
vertical-align: middle;
display: inline-block;
Expand All @@ -32,17 +34,24 @@
border-radius: var(--border-radius, 0);
}
.media.wide {
.media {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: var(--border-radius, 0);
}
.media-container.wide {
width: 100%;
height: auto;
}
.media.tall {
.media-container.tall {
width: auto;
height: 100%;
}
.media.big {
.media-container.big {
width: 100%;
height: 100%;
}
Expand Down

0 comments on commit 3a79111

Please sign in to comment.