2018-05-02 02:05:36 +02:00
|
|
|
{#if type === 'video'}
|
2018-02-05 04:56:06 +01:00
|
|
|
<button type="button"
|
2018-12-08 18:44:12 +01:00
|
|
|
class="play-video-button {$largeInlineMedia ? '' : 'fixed-size'}"
|
2018-05-02 02:05:36 +02:00
|
|
|
aria-label="Play video: {description}"
|
|
|
|
delegate-key={delegateKey}
|
|
|
|
style="width: {inlineWidth}px; height: {inlineHeight}px;">
|
2018-03-10 20:28:30 +01:00
|
|
|
<PlayVideoIcon />
|
2018-03-14 07:07:30 +01:00
|
|
|
<LazyImage
|
2018-05-02 02:05:36 +02:00
|
|
|
alt={description}
|
|
|
|
title={description}
|
|
|
|
src={previewUrl}
|
|
|
|
fallback={oneTransparentPixel}
|
|
|
|
width={inlineWidth}
|
|
|
|
height={inlineHeight}
|
2018-03-14 07:07:30 +01:00
|
|
|
background="var(--loading-bg)"
|
2018-12-08 18:42:38 +01:00
|
|
|
{focus}
|
2018-02-05 04:56:06 +01:00
|
|
|
/>
|
|
|
|
</button>
|
2018-05-02 02:05:36 +02:00
|
|
|
{:else}
|
2018-02-05 04:56:06 +01:00
|
|
|
<button type="button"
|
2018-12-08 18:44:12 +01:00
|
|
|
class="show-image-button {$largeInlineMedia ? '' : 'fixed-size'}"
|
2018-05-02 02:05:36 +02:00
|
|
|
aria-label="Show image: {description}"
|
|
|
|
title={description}
|
|
|
|
delegate-key={delegateKey}
|
2018-02-05 04:56:06 +01:00
|
|
|
on:mouseover="set({mouseover: event})"
|
2018-12-08 18:42:38 +01:00
|
|
|
style="width: {inlineWidth}px; height: {inlineHeight}px;">
|
2018-05-02 02:05:36 +02:00
|
|
|
{#if type === 'gifv' && $autoplayGifs}
|
2018-03-31 19:45:11 +02:00
|
|
|
<AutoplayVideo
|
2018-05-02 02:05:36 +02:00
|
|
|
ariaLabel="Animated GIF: {description}"
|
|
|
|
poster={previewUrl}
|
|
|
|
src={url}
|
|
|
|
width={inlineWidth}
|
|
|
|
height={inlineHeight}
|
2018-12-08 18:42:38 +01:00
|
|
|
{focus}
|
2018-02-05 04:56:06 +01:00
|
|
|
/>
|
2018-05-02 02:05:36 +02:00
|
|
|
{:elseif type === 'gifv' && !$autoplayGifs}
|
2018-02-05 04:56:06 +01:00
|
|
|
<NonAutoplayGifv
|
2018-05-02 02:05:36 +02:00
|
|
|
class={noNativeWidthHeight ? 'no-native-width-height' : ''}
|
|
|
|
label="Animated GIF: {description}"
|
|
|
|
poster={previewUrl}
|
|
|
|
src={url}
|
|
|
|
staticSrc={previewUrl}
|
|
|
|
width={inlineWidth}
|
|
|
|
height={inlineHeight}
|
|
|
|
playing={mouseover}
|
2018-12-08 18:42:38 +01:00
|
|
|
{focus}
|
2018-02-05 04:56:06 +01:00
|
|
|
/>
|
2018-05-02 02:05:36 +02:00
|
|
|
{:else}
|
2018-03-14 07:07:30 +01:00
|
|
|
<LazyImage
|
2018-05-02 02:05:36 +02:00
|
|
|
alt={description}
|
|
|
|
title={description}
|
|
|
|
src={previewUrl}
|
|
|
|
fallback={oneTransparentPixel}
|
|
|
|
width={inlineWidth}
|
|
|
|
height={inlineHeight}
|
2018-03-14 07:07:30 +01:00
|
|
|
background="var(--loading-bg)"
|
2018-12-08 18:42:38 +01:00
|
|
|
{focus}
|
2018-02-05 04:56:06 +01:00
|
|
|
/>
|
2018-05-02 02:05:36 +02:00
|
|
|
{/if}
|
2018-02-05 04:56:06 +01:00
|
|
|
</button>
|
2018-05-02 02:05:36 +02:00
|
|
|
{/if}
|
2018-01-21 00:37:40 +01:00
|
|
|
<style>
|
2018-12-08 18:42:38 +01:00
|
|
|
|
2018-02-05 04:56:06 +01:00
|
|
|
:global(.status-media video, .status-media img) {
|
2018-01-21 00:37:40 +01:00
|
|
|
object-fit: cover;
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
.play-video-button, .show-image-button {
|
|
|
|
margin: auto;
|
2018-01-21 04:19:24 +01:00
|
|
|
padding: 0;
|
|
|
|
border-radius: 0;
|
|
|
|
border: none;
|
|
|
|
background: none;
|
2018-02-05 00:59:42 +01:00
|
|
|
position: relative;
|
2018-01-21 04:19:24 +01:00
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
|
2018-02-05 00:59:42 +01:00
|
|
|
.show-image-button {
|
|
|
|
cursor: zoom-in;
|
|
|
|
}
|
2018-01-21 00:37:40 +01:00
|
|
|
</style>
|
|
|
|
<script>
|
2018-04-20 06:38:01 +02:00
|
|
|
import { DEFAULT_MEDIA_WIDTH, DEFAULT_MEDIA_HEIGHT, ONE_TRANSPARENT_PIXEL } from '../../_static/media'
|
2018-04-21 18:56:53 +02:00
|
|
|
import { importShowVideoDialog, importShowImageDialog } from '../dialog/asyncDialogs'
|
2018-02-05 01:34:54 +01:00
|
|
|
import { mouseover } from '../../_utils/events'
|
2018-02-02 03:48:59 +01:00
|
|
|
import NonAutoplayGifv from '../NonAutoplayGifv.html'
|
2018-03-10 20:28:30 +01:00
|
|
|
import PlayVideoIcon from '../PlayVideoIcon.html'
|
2018-03-14 01:14:57 +01:00
|
|
|
import { store } from '../../_store/store'
|
2018-03-14 07:07:30 +01:00
|
|
|
import LazyImage from '../LazyImage.html'
|
2018-03-31 19:45:11 +02:00
|
|
|
import AutoplayVideo from '../AutoplayVideo.html'
|
2018-04-18 06:47:30 +02:00
|
|
|
import { registerClickDelegate } from '../../_utils/delegate'
|
2018-01-21 04:19:24 +01:00
|
|
|
|
2018-01-21 00:37:40 +01:00
|
|
|
export default {
|
2018-04-20 06:38:01 +02:00
|
|
|
oncreate () {
|
2018-04-19 18:37:05 +02:00
|
|
|
let { delegateKey } = this.get()
|
|
|
|
registerClickDelegate(this, delegateKey, () => {
|
2018-04-20 19:36:20 +02:00
|
|
|
let { type } = this.get()
|
|
|
|
if (type === 'video') {
|
2018-03-15 16:59:30 +01:00
|
|
|
this.onClickPlayVideoButton()
|
|
|
|
} else {
|
|
|
|
this.onClickShowImageButton()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2018-01-21 00:37:40 +01:00
|
|
|
computed: {
|
2018-12-08 18:42:38 +01:00
|
|
|
focus: ({ meta }) => meta && meta.focus,
|
2018-02-05 04:56:06 +01:00
|
|
|
// width/height to show inline
|
2018-12-08 18:44:12 +01:00
|
|
|
inlineWidth: ({ smallWidth, $largeInlineMedia }) => {
|
|
|
|
if (!$largeInlineMedia) {
|
|
|
|
return '100%'
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
return smallWidth || DEFAULT_MEDIA_WIDTH
|
|
|
|
},
|
2018-12-08 18:44:12 +01:00
|
|
|
inlineHeight: ({ smallHeight, $largeInlineMedia }) => {
|
|
|
|
if (!$largeInlineMedia) {
|
|
|
|
return 'auto'
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
return smallHeight || DEFAULT_MEDIA_HEIGHT
|
|
|
|
},
|
2018-02-05 04:56:06 +01:00
|
|
|
// width/height to show in a modal
|
2018-05-02 02:05:36 +02:00
|
|
|
modalWidth: ({ originalWidth, inlineWidth }) => originalWidth || inlineWidth,
|
|
|
|
modalHeight: ({ originalHeight, inlineHeight }) => originalHeight || inlineHeight,
|
|
|
|
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',
|
|
|
|
delegateKey: ({ media, uuid }) => `media-${uuid}-${media.id}`,
|
|
|
|
description: ({ media }) => media.description || '',
|
|
|
|
previewUrl: ({ media }) => media.preview_url,
|
|
|
|
url: ({ media }) => media.url,
|
|
|
|
type: ({ media }) => media.type
|
2018-01-21 04:19:24 +01:00
|
|
|
},
|
|
|
|
methods: {
|
2018-04-20 06:38:01 +02:00
|
|
|
async onClickPlayVideoButton () {
|
2018-04-20 19:36:20 +02:00
|
|
|
let { previewUrl, url, modalWidth, modalHeight, description } = this.get()
|
2018-04-21 18:56:53 +02:00
|
|
|
let showVideoDialog = await importShowVideoDialog()
|
|
|
|
showVideoDialog(previewUrl, url,
|
2018-04-20 19:36:20 +02:00
|
|
|
modalWidth, modalHeight, description)
|
2018-02-05 00:59:42 +01:00
|
|
|
},
|
2018-04-20 06:38:01 +02:00
|
|
|
async onClickShowImageButton () {
|
2018-04-20 19:36:20 +02:00
|
|
|
let { previewUrl, url, modalWidth, modalHeight, description, type } = this.get()
|
2018-04-21 18:56:53 +02:00
|
|
|
let showImageDialog = await importShowImageDialog()
|
|
|
|
showImageDialog(previewUrl, url, type,
|
2018-04-20 19:36:20 +02:00
|
|
|
modalWidth, modalHeight, description)
|
2018-01-21 04:19:24 +01:00
|
|
|
}
|
2018-01-23 06:47:29 +01:00
|
|
|
},
|
2018-02-12 07:59:33 +01:00
|
|
|
data: () => ({
|
2018-04-30 07:13:41 +02:00
|
|
|
oneTransparentPixel: ONE_TRANSPARENT_PIXEL,
|
|
|
|
mouseover: void 0
|
2018-02-12 07:59:33 +01:00
|
|
|
}),
|
2018-03-14 01:14:57 +01:00
|
|
|
store: () => store,
|
2018-01-23 06:47:29 +01:00
|
|
|
events: {
|
2018-02-05 01:34:54 +01:00
|
|
|
mouseover
|
2018-02-02 03:48:59 +01:00
|
|
|
},
|
|
|
|
components: {
|
2018-03-10 20:28:30 +01:00
|
|
|
NonAutoplayGifv,
|
2018-03-14 07:07:30 +01:00
|
|
|
PlayVideoIcon,
|
2018-03-31 19:45:11 +02:00
|
|
|
LazyImage,
|
|
|
|
AutoplayVideo
|
2018-01-21 00:37:40 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 18:42:38 +01:00
|
|
|
</script>
|