2019-08-22 09:09:21 -07:00
|
|
|
{#if !blurhash && (type === 'video' || type === 'audio')}
|
2019-08-17 20:54:45 +03:00
|
|
|
<button id={elementId}
|
|
|
|
type="button"
|
2019-08-22 09:10:02 -07:00
|
|
|
class="inline-media play-video-button focus-after {$largeInlineMedia ? '' : 'fixed-size'} {type === 'audio' ? 'play-audio-button' : ''}"
|
2019-08-17 20:54:45 +03:00
|
|
|
aria-label="Play video: {description}"
|
2019-08-24 10:43:50 -07:00
|
|
|
style={inlineMediaStyle}>
|
2019-08-17 20:54:45 +03:00
|
|
|
<PlayVideoIcon />
|
|
|
|
{#if type === 'video'}
|
|
|
|
<LazyImage
|
|
|
|
alt={description}
|
|
|
|
title={description}
|
|
|
|
src={previewUrl}
|
|
|
|
fallback={oneTransparentPixel}
|
2019-08-22 09:09:21 -07:00
|
|
|
{blurhash}
|
2019-08-17 20:54:45 +03:00
|
|
|
width={inlineWidth}
|
|
|
|
height={inlineHeight}
|
|
|
|
background="var(--loading-bg)"
|
|
|
|
{focus}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
</button>
|
2018-05-01 17:05:36 -07:00
|
|
|
{:else}
|
2019-02-23 12:32:00 -08:00
|
|
|
<button id={elementId}
|
|
|
|
type="button"
|
2019-08-22 09:10:02 -07:00
|
|
|
class="inline-media show-image-button focus-after {$largeInlineMedia ? '' : 'fixed-size'}"
|
2018-05-01 17:05:36 -07:00
|
|
|
aria-label="Show image: {description}"
|
|
|
|
title={description}
|
2018-02-04 19:56:06 -08:00
|
|
|
on:mouseover="set({mouseover: event})"
|
2019-08-24 10:43:50 -07:00
|
|
|
style={inlineMediaStyle}>
|
2019-08-23 16:13:25 +02:00
|
|
|
{#if type === 'gifv' && $autoplayGifs && !blurhash}
|
2018-03-31 10:45:11 -07:00
|
|
|
<AutoplayVideo
|
2018-05-01 17:05:36 -07:00
|
|
|
ariaLabel="Animated GIF: {description}"
|
|
|
|
poster={previewUrl}
|
|
|
|
src={url}
|
|
|
|
width={inlineWidth}
|
|
|
|
height={inlineHeight}
|
2018-12-08 18:42:38 +01:00
|
|
|
{focus}
|
2018-02-04 19:56:06 -08:00
|
|
|
/>
|
2019-08-22 09:09:21 -07:00
|
|
|
{:elseif type === 'gifv'}
|
2018-02-04 19:56:06 -08:00
|
|
|
<NonAutoplayGifv
|
2018-05-01 17:05:36 -07:00
|
|
|
class={noNativeWidthHeight ? 'no-native-width-height' : ''}
|
|
|
|
label="Animated GIF: {description}"
|
|
|
|
poster={previewUrl}
|
2019-08-22 09:09:21 -07:00
|
|
|
{blurhash}
|
2018-05-01 17:05:36 -07:00
|
|
|
src={url}
|
|
|
|
staticSrc={previewUrl}
|
2019-08-24 10:43:50 -07:00
|
|
|
useWidthHeight={!blurhash}
|
2018-05-01 17:05:36 -07:00
|
|
|
width={inlineWidth}
|
|
|
|
height={inlineHeight}
|
|
|
|
playing={mouseover}
|
2018-12-08 18:42:38 +01:00
|
|
|
{focus}
|
2018-02-04 19:56:06 -08:00
|
|
|
/>
|
2018-05-01 17:05:36 -07:00
|
|
|
{:else}
|
2018-03-13 23:07:30 -07:00
|
|
|
<LazyImage
|
2018-05-01 17:05:36 -07:00
|
|
|
alt={description}
|
|
|
|
title={description}
|
|
|
|
src={previewUrl}
|
|
|
|
fallback={oneTransparentPixel}
|
2019-08-22 09:09:21 -07:00
|
|
|
{blurhash}
|
2018-05-01 17:05:36 -07:00
|
|
|
width={inlineWidth}
|
|
|
|
height={inlineHeight}
|
2018-03-13 23:07:30 -07:00
|
|
|
background="var(--loading-bg)"
|
2018-12-08 18:42:38 +01:00
|
|
|
{focus}
|
2018-02-04 19:56:06 -08:00
|
|
|
/>
|
2018-05-01 17:05:36 -07:00
|
|
|
{/if}
|
2018-02-04 19:56:06 -08:00
|
|
|
</button>
|
2018-05-01 17:05:36 -07:00
|
|
|
{/if}
|
2018-01-20 15:37:40 -08:00
|
|
|
<style>
|
2018-12-08 18:42:38 +01:00
|
|
|
|
2018-02-04 19:56:06 -08:00
|
|
|
:global(.status-media video, .status-media img) {
|
2018-01-20 15:37:40 -08:00
|
|
|
object-fit: cover;
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
.play-video-button, .show-image-button {
|
|
|
|
margin: auto;
|
2018-01-20 19:19:24 -08:00
|
|
|
padding: 0;
|
|
|
|
border-radius: 0;
|
|
|
|
border: none;
|
|
|
|
background: none;
|
|
|
|
}
|
2019-06-23 09:41:31 -07:00
|
|
|
.play-audio-button {
|
|
|
|
background: var(--audio-bg);
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
|
2018-02-04 15:59:42 -08:00
|
|
|
.show-image-button {
|
|
|
|
cursor: zoom-in;
|
|
|
|
}
|
2019-09-21 18:16:55 -07:00
|
|
|
|
2019-09-24 00:50:35 -07:00
|
|
|
.inline-media {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
2019-09-21 18:16:55 -07:00
|
|
|
@media (max-width: 240px) {
|
|
|
|
.inline-media {
|
|
|
|
min-height: 100px; /* TODO: hack for KaiOS, which renders the grouped-images style as 0 height */
|
|
|
|
}
|
|
|
|
}
|
2018-01-20 15:37:40 -08:00
|
|
|
</style>
|
|
|
|
<script>
|
2018-04-19 21:38:01 -07:00
|
|
|
import { DEFAULT_MEDIA_WIDTH, DEFAULT_MEDIA_HEIGHT, ONE_TRANSPARENT_PIXEL } from '../../_static/media'
|
2019-02-02 23:03:40 -08:00
|
|
|
import { importShowMediaDialog } from '../dialog/asyncDialogs'
|
2018-02-04 16:34:54 -08:00
|
|
|
import { mouseover } from '../../_utils/events'
|
2018-02-01 18:48:59 -08:00
|
|
|
import NonAutoplayGifv from '../NonAutoplayGifv.html'
|
2018-03-10 11:28:30 -08:00
|
|
|
import PlayVideoIcon from '../PlayVideoIcon.html'
|
2018-03-13 17:14:57 -07:00
|
|
|
import { store } from '../../_store/store'
|
2018-03-13 23:07:30 -07:00
|
|
|
import LazyImage from '../LazyImage.html'
|
2018-03-31 10:45:11 -07:00
|
|
|
import AutoplayVideo from '../AutoplayVideo.html'
|
2018-04-17 21:47:30 -07:00
|
|
|
import { registerClickDelegate } from '../../_utils/delegate'
|
2019-08-22 09:09:21 -07:00
|
|
|
import { convertCssPropertyToDataUrl } from '../../_utils/convertCssPropertyToDataUrl'
|
2018-01-20 19:19:24 -08:00
|
|
|
|
2019-08-17 20:54:45 +03:00
|
|
|
export default {
|
|
|
|
async oncreate () {
|
2019-08-17 14:36:13 -07:00
|
|
|
const { elementId } = this.get()
|
2019-02-23 12:32:00 -08:00
|
|
|
registerClickDelegate(this, elementId, () => this.onClick())
|
2018-03-15 08:59:30 -07:00
|
|
|
},
|
2018-01-20 15:37:40 -08:00
|
|
|
computed: {
|
2018-12-08 18:42:38 +01:00
|
|
|
focus: ({ meta }) => meta && meta.focus,
|
2018-02-04 19:56:06 -08:00
|
|
|
// width/height to show inline
|
2018-12-08 09:44:12 -08:00
|
|
|
inlineWidth: ({ smallWidth, $largeInlineMedia }) => {
|
|
|
|
if (!$largeInlineMedia) {
|
|
|
|
return '100%'
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
return smallWidth || DEFAULT_MEDIA_WIDTH
|
|
|
|
},
|
2018-12-08 09:44:12 -08:00
|
|
|
inlineHeight: ({ smallHeight, $largeInlineMedia }) => {
|
|
|
|
if (!$largeInlineMedia) {
|
|
|
|
return 'auto'
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
return smallHeight || DEFAULT_MEDIA_HEIGHT
|
|
|
|
},
|
2018-02-04 19:56:06 -08:00
|
|
|
// width/height to show in a modal
|
2018-12-17 22:13:27 +01:00
|
|
|
modalWidth: ({ originalWidth, smallWidth }) => originalWidth || smallWidth || 0,
|
|
|
|
modalHeight: ({ originalHeight, smallHeight }) => originalHeight || smallHeight || 0,
|
2018-05-01 17:05:36 -07:00
|
|
|
meta: ({ media }) => media.meta,
|
|
|
|
small: ({ meta }) => meta && meta.small,
|
|
|
|
original: ({ meta }) => meta && meta.original,
|
|
|
|
smallWidth: ({ small }) => small && small.width,
|
|
|
|
smallHeight: ({ small }) => small && small.height,
|
|
|
|
originalWidth: ({ original }) => original && original.width,
|
|
|
|
originalHeight: ({ original }) => original && original.height,
|
|
|
|
noNativeWidthHeight: ({ smallWidth, smallHeight }) => typeof smallWidth !== 'number' || typeof smallHeight !== 'number',
|
2019-02-23 12:32:00 -08:00
|
|
|
elementId: ({ media, uuid }) => `media-${uuid}-${media.id}`,
|
2018-05-01 17:05:36 -07:00
|
|
|
description: ({ media }) => media.description || '',
|
|
|
|
previewUrl: ({ media }) => media.preview_url,
|
2019-08-22 09:09:21 -07:00
|
|
|
decodedBlurhash: ({ media }) => media.decodedBlurhash,
|
|
|
|
blurhashToUse: ({ decodedBlurhash, $ignoreBlurhash }) => {
|
|
|
|
if (!$ignoreBlurhash && decodedBlurhash) {
|
|
|
|
return decodedBlurhash
|
|
|
|
}
|
|
|
|
// Convert the var(--loading-bg) variable into a data URL based on a single pixel of color
|
|
|
|
// TODO: this is hacky
|
|
|
|
return convertCssPropertyToDataUrl('--mask-bg')
|
|
|
|
},
|
|
|
|
blurhash: ({ blurhashToUse, showAsSensitive }) => showAsSensitive && blurhashToUse,
|
2018-05-01 17:05:36 -07:00
|
|
|
url: ({ media }) => media.url,
|
2019-08-24 10:43:50 -07:00
|
|
|
type: ({ media }) => media.type,
|
|
|
|
inlineMediaStyle: ({ type, inlineWidth, inlineHeight, blurhash, $largeInlineMedia }) => {
|
|
|
|
if ((type === 'audio') || (blurhash && $largeInlineMedia)) {
|
|
|
|
return ''
|
|
|
|
} else {
|
|
|
|
return `width: ${inlineWidth}px; height: ${inlineHeight}px;`
|
|
|
|
}
|
|
|
|
}
|
2018-01-20 19:19:24 -08:00
|
|
|
},
|
|
|
|
methods: {
|
2019-07-07 17:32:50 -07:00
|
|
|
onClick () {
|
|
|
|
(async () => {
|
2019-08-03 13:49:37 -07:00
|
|
|
const { mediaAttachments, index } = this.get()
|
|
|
|
const showMediaDialog = await importShowMediaDialog()
|
2019-07-07 17:32:50 -07:00
|
|
|
showMediaDialog(mediaAttachments, index)
|
|
|
|
})()
|
|
|
|
return true
|
2018-01-20 19:19:24 -08:00
|
|
|
}
|
2018-01-22 21:47:29 -08:00
|
|
|
},
|
2018-02-11 22:59:33 -08:00
|
|
|
data: () => ({
|
2018-04-29 22:13:41 -07:00
|
|
|
oneTransparentPixel: ONE_TRANSPARENT_PIXEL,
|
2019-08-19 19:08:59 -07:00
|
|
|
mouseover: undefined
|
2018-02-11 22:59:33 -08:00
|
|
|
}),
|
2018-03-13 17:14:57 -07:00
|
|
|
store: () => store,
|
2018-01-22 21:47:29 -08:00
|
|
|
events: {
|
2018-02-04 16:34:54 -08:00
|
|
|
mouseover
|
2018-02-01 18:48:59 -08:00
|
|
|
},
|
|
|
|
components: {
|
2018-03-10 11:28:30 -08:00
|
|
|
NonAutoplayGifv,
|
2018-03-13 23:07:30 -07:00
|
|
|
PlayVideoIcon,
|
2018-03-31 10:45:11 -07:00
|
|
|
LazyImage,
|
|
|
|
AutoplayVideo
|
2018-01-20 15:37:40 -08:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
</script>
|