attachment.vue 4.81 KB
Newer Older
lain's avatar
lain committed
1
<template>
Shpuld Shpludson's avatar
Shpuld Shpludson committed
2 3 4 5 6 7 8
  <div v-if="usePlaceHolder" @click="openModal">
    <a class="placeholder"
      v-if="type !== 'html'"
      target="_blank" :href="attachment.url"
    >
      [{{nsfw ? "NSFW/" : ""}}{{type.toUpperCase()}}]
    </a>
Shpuld Shpludson's avatar
Shpuld Shpludson committed
9
  </div>
10 11
  <div
    v-else class="attachment"
12
    :class="{[type]: true, loading, 'fullwidth': fullwidth, 'nsfw-placeholder': hidden}"
13 14
    v-show="!isEmpty"
  >
Shpuld Shpludson's avatar
Shpuld Shpludson committed
15 16
    <a class="image-attachment" v-if="hidden" :href="attachment.url" @click.prevent="toggleHidden">
      <img class="nsfw" :key="nsfwImage" :src="nsfwImage" :class="{'small': isSmall}"/>
17
      <i v-if="type === 'video'" class="play-icon icon-play-circled"></i>
lain's avatar
lain committed
18
    </a>
Shpuld Shpludson's avatar
Shpuld Shpludson committed
19 20 21
    <div class="hider" v-if="nsfw && hideNsfwLocal && !hidden">
      <a href="#" @click.prevent="toggleHidden">Hide</a>
    </div>
22

23
    <a v-if="type === 'image' && (!hidden || preloadImage)"
Shpuld Shpludson's avatar
Shpuld Shpludson committed
24
      @click="openModal"
25
      class="image-attachment"
Shpuld Shpludson's avatar
Shpuld Shpludson committed
26
      :class="{'hidden': hidden && preloadImage }"
27 28 29
      :href="attachment.url" target="_blank"
      :title="attachment.description"
    >
30
      <StillImage :referrerpolicy="referrerpolicy" :mimetype="attachment.mimetype" :src="attachment.large_thumb_url || attachment.url"/>
dtluna's avatar
dtluna committed
31
    </a>
lain's avatar
lain committed
32

33
    <a class="video-container"
Shpuld Shpludson's avatar
Shpuld Shpludson committed
34
      @click="openModal"
35 36
      v-if="type === 'video' && !hidden"
      :class="{'small': isSmall}"
37
      :href="allowPlay ? undefined : attachment.url"
38
    >
Shpuld Shpludson's avatar
Shpuld Shpludson committed
39 40
      <VideoAttachment class="video" :attachment="attachment" :controls="allowPlay" />
      <i v-if="!allowPlay" class="play-icon icon-play-circled"></i>
41
    </a>
lain's avatar
lain committed
42

dtluna's avatar
dtluna committed
43 44
    <audio v-if="type === 'audio'" :src="attachment.url" controls></audio>

45
    <div @click.prevent="linkClicked" v-if="type === 'html' && attachment.oembed" class="oembed">
lain's avatar
lain committed
46
      <div v-if="attachment.thumb_url" class="image">
47
        <img :src="attachment.thumb_url"/>
lain's avatar
lain committed
48 49 50 51 52 53
      </div>
      <div class="text">
        <h1><a :href="attachment.url">{{attachment.oembed.title}}</a></h1>
        <div v-html="attachment.oembed.oembedHTML"></div>
      </div>
    </div>
lain's avatar
lain committed
54 55 56 57
  </div>
</template>

<script src="./attachment.js"></script>
lain's avatar
lain committed
58 59

<style lang="scss">
60 61
@import '../../_variables.scss';

62
.attachments {
HJ's avatar
indents  
HJ committed
63 64 65 66 67
  display: flex;
  flex-wrap: wrap;

  .attachment.media-upload-container {
    flex: 0 0 auto;
Shpuld Shpludson's avatar
Shpuld Shpludson committed
68
    max-height: 200px;
HJ's avatar
indents  
HJ committed
69
    max-width: 100%;
Shpuld Shpludson's avatar
Shpuld Shpludson committed
70 71 72 73
    display: flex;
    video {
      max-width: 100%;
    }
74
  }
75

76
  .placeholder {
77 78
    margin-right: 8px;
    margin-bottom: 4px;
79 80
  }

81 82
  .nsfw-placeholder {
    cursor: pointer;
83 84 85 86

    &.loading {
      cursor: progress;
    }
87 88
  }

HJ's avatar
indents  
HJ committed
89
  .attachment {
HJ's avatar
HJ committed
90
    position: relative;
91
    margin-top: 0.5em;
HJ's avatar
indents  
HJ committed
92
    align-self: flex-start;
Shpuld Shpludson's avatar
Shpuld Shpludson committed
93
    line-height: 0;
HJ's avatar
indents  
HJ committed
94 95 96 97 98

    border-style: solid;
    border-width: 1px;
    border-radius: $fallback--attachmentRadius;
    border-radius: var(--attachmentRadius, $fallback--attachmentRadius);
99 100
    border-color: $fallback--border;
    border-color: var(--border, $fallback--border);
HJ's avatar
indents  
HJ committed
101
    overflow: hidden;
102
  }
Shpuld Shpludson's avatar
Shpuld Shpludson committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

  .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;
    }
  }

125 126 127
  .fullwidth {
    flex-basis: 100%;
  }
128 129 130 131
  // fixes small gap below video
  &.video {
    line-height: 0;
  }
HJ's avatar
indents  
HJ committed
132

133
  .video-container {
Shpuld Shpludson's avatar
Shpuld Shpludson committed
134 135
    display: flex;
    max-height: 100%;
136 137
  }

138
  .video {
Shpuld Shpludson's avatar
Shpuld Shpludson committed
139
    width: 100%;
140 141
  }

142 143 144 145 146 147 148 149 150 151 152 153 154
  .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;
  }

155 156 157 158 159
  &.html {
    flex-basis: 90%;
    width: 100%;
    display: flex;
  }
160

161 162
  .hider {
    position: absolute;
Shpuld Shpludson's avatar
Shpuld Shpludson committed
163
    white-space: nowrap;
164 165 166 167 168
    margin: 10px;
    padding: 5px;
    background: rgba(230,230,230,0.6);
    font-weight: bold;
    z-index: 4;
169 170 171
    line-height: 1;
    border-radius: $fallback--tooltipRadius;
    border-radius: var(--tooltipRadius, $fallback--tooltipRadius);
172
  }
lain's avatar
lain committed
173

174 175 176
  video {
    z-index: 0;
  }
177

178 179 180
  audio {
    width: 100%;
  }
181

182
  img.media-upload {
Shpuld Shpludson's avatar
Shpuld Shpludson committed
183
    line-height: 0;
Shpuld Shpludson's avatar
Shpuld Shpludson committed
184
    max-height: 200px;
185 186
    max-width: 100%;
  }
187

188
  .oembed {
189
    line-height: 1.2em;
190
    flex: 1 0 100%;
191 192 193
    width: 100%;
    margin-right: 15px;
    display: flex;
194

195
    img {
HJ's avatar
indents  
HJ committed
196
      width: 100%;
197
    }
HJ's avatar
indents  
HJ committed
198

199 200
    .image {
      flex: 1;
HJ's avatar
indents  
HJ committed
201
      img {
202
        border: 0px;
Shpuld Shpludson's avatar
Shpuld Shpludson committed
203
        border-radius: 5px;
204 205
        height: 100%;
        object-fit: cover;
Shpuld Shpludson's avatar
Shpuld Shpludson committed
206
      }
207
    }
HJ's avatar
indents  
HJ committed
208

209 210 211 212 213 214 215
    .text {
      flex: 2;
      margin: 8px;
      word-break: break-all;
      h1 {
        font-size: 14px;
        margin: 0px;
Shpuld Shpludson's avatar
Shpuld Shpludson committed
216
      }
HJ's avatar
indents  
HJ committed
217
    }
218
  }
219

220
  .image-attachment {
Shpuld Shpludson's avatar
Shpuld Shpludson committed
221 222
    width: 100%;
    height: 100%;
lain's avatar
lain committed
223

ValD's avatar
ValD committed
224 225 226 227
    &.hidden {
      display: none;
    }

Shpuld Shpludson's avatar
Shpuld Shpludson committed
228 229 230 231
    .nsfw {
      object-fit: cover;
      width: 100%;
      height: 100%;
232
    }
233 234 235 236

    img {
      image-orientation: from-image;
    }
HJ's avatar
indents  
HJ committed
237 238
  }
}
lain's avatar
lain committed
239
</style>