misc: add load prompt to images, close #511
This commit is contained in:
5 files changed
+61
-20
No files matched your search
@@ -112,6 +112,11 @@
|
||||
|
||||
<script lang="ts">
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
import { setContext } from 'svelte'
|
||||
|
||||
interface RendererOptions {
|
||||
autoloadImages: boolean
|
||||
}
|
||||
|
||||
interface Props {
|
||||
source?: string
|
||||
@@ -119,6 +124,7 @@
|
||||
noStyle?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
rendererOptions?: RendererOptions
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -127,8 +133,13 @@
|
||||
noStyle = false,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
rendererOptions = {
|
||||
autoloadImages: true,
|
||||
},
|
||||
}: Props = $props()
|
||||
|
||||
setContext('options', rendererOptions)
|
||||
|
||||
options.inline = inline
|
||||
|
||||
let tokens = $derived.by(() => marked.lexer(source))
|
||||
|
||||
@@ -6,6 +6,14 @@
|
||||
optimizeImageURL,
|
||||
} from '$lib/components/lemmy/post/helpers'
|
||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
||||
import { getContext } from 'svelte'
|
||||
import { ArrowDown, ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
let loaded: boolean = $state(
|
||||
(getContext('options') as { autoloadImages: boolean })?.autoloadImages ??
|
||||
true,
|
||||
)
|
||||
|
||||
interface Props {
|
||||
href: string
|
||||
@@ -22,26 +30,40 @@
|
||||
class="w-auto h-auto max-h-96 rounded-2xl p-2 border border-slate-200 dark:border-zinc-800
|
||||
inline-block"
|
||||
>
|
||||
{#if type == 'video' || type == 'embed' || type == 'iframe'}
|
||||
<PostIframe
|
||||
type={iframeType(href)}
|
||||
url={href}
|
||||
opened={true}
|
||||
autoplay={false}
|
||||
class="w-auto h-auto max-h-80 inline-block rounded-lg"
|
||||
/>
|
||||
{#if loaded}
|
||||
{#if type == 'video' || type == 'embed' || type == 'iframe'}
|
||||
<PostIframe
|
||||
type={iframeType(href)}
|
||||
url={href}
|
||||
opened={true}
|
||||
autoplay={false}
|
||||
class="w-auto h-auto max-h-80 inline-block rounded-lg"
|
||||
/>
|
||||
{:else}
|
||||
<button
|
||||
class="inline"
|
||||
onclick={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
>
|
||||
<img
|
||||
src={optimizeImageURL(href, 1024)}
|
||||
{title}
|
||||
alt={text}
|
||||
width={300}
|
||||
height={300}
|
||||
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
|
||||
/>
|
||||
</button>
|
||||
{/if}
|
||||
{:else}
|
||||
<button
|
||||
class="inline"
|
||||
onclick={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
onclick={() => (loaded = true)}
|
||||
class="w-40 h-40 flex flex-col justify-center items-center gap-4 p-2 group"
|
||||
title={$t('common.download')}
|
||||
>
|
||||
<img
|
||||
src={optimizeImageURL(href, 1024)}
|
||||
{title}
|
||||
alt={text}
|
||||
width={300}
|
||||
height={300}
|
||||
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
|
||||
<Icon
|
||||
src={ArrowDownTray}
|
||||
size="24"
|
||||
class="text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
Reference in new issue
Block a user