diff options
| author | shpuld <shp@cock.li> | 2019-01-14 19:23:13 +0200 |
|---|---|---|
| committer | shpuld <shp@cock.li> | 2019-01-14 19:23:13 +0200 |
| commit | 17735943d5cdde1eb852d36f1c3bb699d23f7eb6 (patch) | |
| tree | d5a6b7f8d8c3512a6f262371f0038a2adb311288 /src/components/attachment | |
| parent | a51167fa72a64505080c9aea47b5d3bc97a529b0 (diff) | |
Add media viewer module and media module component, modify attachment behavior
Diffstat (limited to 'src/components/attachment')
| -rw-r--r-- | src/components/attachment/attachment.js | 19 | ||||
| -rw-r--r-- | src/components/attachment/attachment.vue | 47 |
2 files changed, 44 insertions, 22 deletions
diff --git a/src/components/attachment/attachment.js b/src/components/attachment/attachment.js index 97c4f283..5e672ef2 100644 --- a/src/components/attachment/attachment.js +++ b/src/components/attachment/attachment.js @@ -7,7 +7,8 @@ const Attachment = { 'attachment', 'nsfw', 'statusId', - 'size' + 'size', + 'setMedia' ], data () { return { @@ -17,13 +18,17 @@ const Attachment = { loopVideo: this.$store.state.config.loopVideo, showHidden: false, loading: false, - img: fileTypeService.fileType(this.attachment.mimetype) === 'image' && document.createElement('img') + img: fileTypeService.fileType(this.attachment.mimetype) === 'image' && document.createElement('img'), + modalOpen: false } }, components: { StillImage }, computed: { + usePlaceHolder () { + return this.size === 'hide' || this.type === 'unknown' + }, type () { return fileTypeService.fileType(this.attachment.mimetype) }, @@ -37,7 +42,7 @@ const Attachment = { return this.size === 'small' }, fullwidth () { - return fileTypeService.fileType(this.attachment.mimetype) === 'html' + return this.type === 'html' || this.type === 'audio' } }, methods: { @@ -62,6 +67,14 @@ const Attachment = { this.showHidden = !this.showHidden } }, + toggleModal (event) { + if (this.type !== 'image' && this.type !== 'video') { + return + } + event.preventDefault() + this.setMedia() + this.$store.dispatch('setCurrent', this.attachment) + }, onVideoDataLoad (e) { if (typeof e.srcElement.webkitAudioDecodedByteCount !== 'undefined') { // non-zero if video has audio track diff --git a/src/components/attachment/attachment.vue b/src/components/attachment/attachment.vue index 5eaa0d1d..1c6b84df 100644 --- a/src/components/attachment/attachment.vue +++ b/src/components/attachment/attachment.vue @@ -1,19 +1,29 @@ <template> - <div v-if="size==='hide'"> + <div v-if="usePlaceHolder" @click="toggleModal"> <a class="placeholder" v-if="type !== 'html'" target="_blank" :href="attachment.url">[{{nsfw ? "NSFW/" : ""}}{{type.toUpperCase()}}]</a> </div> - <div v-else class="attachment" :class="{[type]: true, loading, 'small-attachment': isSmall, 'fullwidth': fullwidth, 'nsfw-placeholder': hidden}" v-show="!isEmpty"> + <div + v-else class="attachment" + :class="{[type]: true, loading, 'small-attachment': isSmall, 'fullwidth': fullwidth, 'nsfw-placeholder': hidden}" + v-show="!isEmpty" + @click="toggleModal" + > <a class="image-attachment" v-if="hidden" @click.prevent="toggleHidden()"> <img :key="nsfwImage" :src="nsfwImage"/> </a> <div class="hider" v-if="nsfw && hideNsfwLocal && !hidden"> <a href="#" @click.prevent="toggleHidden()">Hide</a> </div> - <a v-if="type === 'image' && (!hidden || preloadImage)" class="image-attachment" :class="{'hidden': hidden && preloadImage}" :href="attachment.url" target="_blank" :title="attachment.description"> + <a v-if="type === 'image' && (!hidden || preloadImage)" + class="image-attachment" + :class="{'hidden': hidden && preloadImage}" + :href="attachment.url" target="_blank" + :title="attachment.description" + > <StillImage :class="{'small': isSmall}" referrerpolicy="no-referrer" :mimetype="attachment.mimetype" :src="attachment.large_thumb_url || attachment.url"/> </a> - <video :class="{'small': isSmall}" v-if="type === 'video' && !hidden" @loadeddata="onVideoDataLoad" :src="attachment.url" controls :loop="loopVideo" playsinline></video> + <video :class="{'small': isSmall}" v-if="type === 'video' && !hidden" :src="attachment.url"></video> <audio v-if="type === 'audio'" :src="attachment.url" controls></audio> @@ -40,12 +50,13 @@ .attachment.media-upload-container { flex: 0 0 auto; - max-height: 300px; + max-height: 160px; max-width: 100%; } .placeholder { - margin-right: 0.5em; + margin-right: 8px; + margin-bottom: 4px; } .nsfw-placeholder { @@ -57,16 +68,12 @@ } .small-attachment { - &.image, &.video { - max-width: 35%; - } max-height: 100px; } .attachment { position: relative; - flex: 1 0 30%; - margin: 0.5em 0.7em 0.6em 0.0em; + margin: 0.5em 0.5em 0em 0em; align-self: flex-start; line-height: 0; @@ -86,6 +93,10 @@ line-height: 0; } + .video { + object-fit: cover; + } + &.html { flex-basis: 90%; width: 100%; @@ -107,10 +118,10 @@ .small { max-height: 100px; } + video { - max-height: 500px; + max-height: 160px; height: 100%; - width: 100%; z-index: 0; } @@ -120,7 +131,7 @@ img.media-upload { line-height: 0; - max-height: 300px; + max-height: 160px; max-width: 100%; } @@ -165,21 +176,19 @@ } .still-image { - width: 100%; height: 100%; } .small { img { - max-height: 100px; + max-height: 80px; } } img { - object-fit: contain; - width: 100%; + object-fit: cover; height: 100%; /* If this isn't here, chrome will stretch the images */ - max-height: 500px; + height: 160px; image-orientation: from-image; } } |
