akkoma-fe/src/components/attachment/attachment.vue

294 lines
5.2 KiB
Vue
Raw Normal View History

2016-10-28 16:08:03 +00:00
<template>
2019-07-05 07:17:44 +00:00
<div
v-if="usePlaceHolder"
@click="openModal"
>
<a
2019-01-26 15:45:03 +00:00
v-if="type !== 'html'"
2019-07-05 07:17:44 +00:00
class="placeholder"
target="_blank"
:href="attachment.url"
2019-01-26 15:45:03 +00:00
>
2019-07-05 07:17:44 +00:00
[{{ nsfw ? "NSFW/" : "" }}{{ type.toUpperCase() }}]
2019-01-26 15:45:03 +00:00
</a>
2018-04-09 16:43:31 +00:00
</div>
<div
2019-07-05 07:17:44 +00:00
v-else
v-show="!isEmpty"
2019-07-05 07:17:44 +00:00
class="attachment"
:class="{[type]: true, loading, 'fullwidth': fullwidth, 'nsfw-placeholder': hidden}"
>
2019-07-05 07:17:44 +00:00
<a
v-if="hidden"
class="image-attachment"
:href="attachment.url"
@click.prevent="toggleHidden"
>
<img
:key="nsfwImage"
class="nsfw"
:src="nsfwImage"
:class="{'small': isSmall}"
>
<i
v-if="type === 'video'"
class="play-icon icon-play-circled"
/>
2016-10-28 16:08:03 +00:00
</a>
2019-07-05 07:17:44 +00:00
<div
v-if="nsfw && hideNsfwLocal && !hidden"
class="hider"
>
<a
href="#"
@click.prevent="toggleHidden"
>Hide</a>
2019-01-26 15:45:03 +00:00
</div>
2019-07-05 07:17:44 +00:00
<a
v-if="type === 'image' && (!hidden || preloadImage)"
class="image-attachment"
2019-01-26 15:45:03 +00:00
:class="{'hidden': hidden && preloadImage }"
2019-07-05 07:17:44 +00:00
:href="attachment.url"
target="_blank"
:title="attachment.description"
2019-07-05 07:17:44 +00:00
@click="openModal"
>
2019-07-05 07:17:44 +00:00
<StillImage
:referrerpolicy="referrerpolicy"
:mimetype="attachment.mimetype"
:src="attachment.large_thumb_url || attachment.url"
/>
2016-11-26 00:19:25 +00:00
</a>
2016-10-28 16:08:03 +00:00
2019-07-05 07:17:44 +00:00
<a
v-if="type === 'video' && !hidden"
2019-07-05 07:17:44 +00:00
class="video-container"
:class="{'small': isSmall}"
:href="allowPlay ? undefined : attachment.url"
2019-07-05 07:17:44 +00:00
@click="openModal"
>
2019-07-05 07:17:44 +00:00
<VideoAttachment
class="video"
:attachment="attachment"
:controls="allowPlay"
/>
<i
v-if="!allowPlay"
class="play-icon icon-play-circled"
/>
</a>
2016-10-28 16:08:03 +00:00
2019-07-05 07:17:44 +00:00
<audio
v-if="type === 'audio'"
:src="attachment.url"
controls
/>
2016-11-22 18:45:18 +00:00
2019-07-05 07:17:44 +00:00
<div
v-if="type === 'html' && attachment.oembed"
class="oembed"
@click.prevent="linkClicked"
>
<div
v-if="attachment.thumb_url"
class="image"
>
<img :src="attachment.thumb_url">
2016-10-28 23:38:41 +00:00
</div>
<div class="text">
2019-07-06 21:54:17 +00:00
<!-- eslint-disable vue/no-v-html -->
2019-07-05 07:17:44 +00:00
<h1><a :href="attachment.url">{{ attachment.oembed.title }}</a></h1>
<div v-html="attachment.oembed.oembedHTML" />
2019-07-06 21:54:17 +00:00
<!-- eslint-enabled vue/no-v-html -->
2016-10-28 23:38:41 +00:00
</div>
</div>
2016-10-28 16:08:03 +00:00
</div>
</template>
<script src="./attachment.js"></script>
2016-10-28 23:38:41 +00:00
<style lang="scss">
@import '../../_variables.scss';
.attachments {
2018-04-07 16:30:27 +00:00
display: flex;
flex-wrap: wrap;
.attachment.media-upload-container {
flex: 0 0 auto;
2019-01-26 15:45:03 +00:00
max-height: 200px;
2018-04-07 16:30:27 +00:00
max-width: 100%;
2019-01-26 15:45:03 +00:00
display: flex;
align-items: center;
2019-01-26 15:45:03 +00:00
video {
max-width: 100%;
}
}
.placeholder {
margin-right: 8px;
margin-bottom: 4px;
}
.nsfw-placeholder {
cursor: pointer;
&.loading {
cursor: progress;
}
}
2018-04-07 16:30:27 +00:00
.attachment {
position: relative;
margin-top: 0.5em;
2018-04-07 16:30:27 +00:00
align-self: flex-start;
2018-04-10 19:12:59 +00:00
line-height: 0;
2018-04-07 16:30:27 +00:00
border-style: solid;
border-width: 1px;
border-radius: $fallback--attachmentRadius;
border-radius: var(--attachmentRadius, $fallback--attachmentRadius);
border-color: $fallback--border;
border-color: var(--border, $fallback--border);
2018-04-07 16:30:27 +00:00
overflow: hidden;
}
2019-01-26 15:45:03 +00:00
.non-gallery.attachment {
&.video {
flex: 1 0 40%;
}
.nsfw {
height: 260px;
}
.small {
height: 120px;
flex-grow: 0;
}
.video {
height: 260px;
display: flex;
}
video {
max-height: 100%;
object-fit: contain;
}
}
2018-04-14 12:45:38 +00:00
.fullwidth {
flex-basis: 100%;
}
// fixes small gap below video
&.video {
line-height: 0;
}
2018-04-07 16:30:27 +00:00
.video-container {
2019-01-26 15:45:03 +00:00
display: flex;
max-height: 100%;
}
.video {
2019-01-26 15:45:03 +00:00
width: 100%;
}
.play-icon {
position: absolute;
font-size: 64px;
top: calc(50% - 32px);
left: calc(50% - 32px);
color: rgba(255, 255, 255, 0.75);
text-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
}
.play-icon::before {
margin: 0;
}
&.html {
flex-basis: 90%;
width: 100%;
display: flex;
}
.hider {
position: absolute;
right: 0;
2019-01-26 15:45:03 +00:00
white-space: nowrap;
margin: 10px;
padding: 5px;
background: rgba(230,230,230,0.6);
font-weight: bold;
z-index: 4;
line-height: 1;
border-radius: $fallback--tooltipRadius;
border-radius: var(--tooltipRadius, $fallback--tooltipRadius);
}
2017-02-17 09:16:29 +00:00
video {
z-index: 0;
}
audio {
width: 100%;
}
img.media-upload {
2018-04-10 19:12:59 +00:00
line-height: 0;
2019-01-26 15:45:03 +00:00
max-height: 200px;
max-width: 100%;
}
.oembed {
2018-04-11 16:47:03 +00:00
line-height: 1.2em;
2018-04-14 12:45:38 +00:00
flex: 1 0 100%;
width: 100%;
margin-right: 15px;
display: flex;
img {
2018-04-07 16:30:27 +00:00
width: 100%;
}
2018-04-07 16:30:27 +00:00
.image {
flex: 1;
2018-04-07 16:30:27 +00:00
img {
border: 0px;
2018-04-09 16:43:31 +00:00
border-radius: 5px;
height: 100%;
object-fit: cover;
2018-04-09 16:43:31 +00:00
}
}
2018-04-07 16:30:27 +00:00
.text {
flex: 2;
margin: 8px;
word-break: break-all;
h1 {
font-size: 14px;
margin: 0px;
2018-04-09 16:43:31 +00:00
}
2018-04-07 16:30:27 +00:00
}
}
.image-attachment {
2019-01-26 15:45:03 +00:00
width: 100%;
height: 100%;
2017-02-17 09:16:29 +00:00
2018-12-11 20:58:36 +00:00
&.hidden {
display: none;
}
2019-01-26 15:45:03 +00:00
.nsfw {
object-fit: cover;
width: 100%;
height: 100%;
}
img {
image-orientation: from-image;
}
2018-04-07 16:30:27 +00:00
}
}
2016-10-28 23:38:41 +00:00
</style>