first ver

This commit is contained in:
Henry Jameson 2018-01-29 10:47:26 +03:00
parent cd3bf461db
commit b10787d23c
4 changed files with 85 additions and 1 deletions

View file

@ -1,3 +1,4 @@
import StillImage from '../still-image/still-image.vue'
import nsfwImage from '../../assets/nsfw.png' import nsfwImage from '../../assets/nsfw.png'
import fileTypeService from '../../services/file_type/file_type.service.js' import fileTypeService from '../../services/file_type/file_type.service.js'
@ -16,6 +17,9 @@ const Attachment = {
img: document.createElement('img') img: document.createElement('img')
} }
}, },
components: {
StillImage
},
computed: { computed: {
type () { type () {
return fileTypeService.fileType(this.attachment.mimetype) return fileTypeService.fileType(this.attachment.mimetype)

View file

@ -8,7 +8,7 @@
</div> </div>
<a v-if="type === 'image' && !hidden" class="image-attachment" :href="attachment.url" target="_blank"> <a v-if="type === 'image' && !hidden" class="image-attachment" :href="attachment.url" target="_blank">
<img class="base03-border" referrerpolicy="no-referrer" :src="attachment.large_thumb_url || attachment.url"/> <StillImage class="base03-border" referrerpolicy="no-referrer" :mimetype="attachment.mimetype" :src="attachment.large_thumb_url || attachment.url"/>
</a> </a>
<video class="base03" v-if="type === 'video' && !hidden" :src="attachment.url" controls loop></video> <video class="base03" v-if="type === 'video' && !hidden" :src="attachment.url" controls loop></video>

View file

@ -0,0 +1,29 @@
import fileTypeService from '../../services/file_type/file_type.service.js'
const StillImage = {
props: [
'src',
'referrerpolicy',
'mimetype'
],
data () {
return {
hideNsfwLocal: this.$store.state.config.hideNsfw,
}
},
computed: {
animated () {
return this.mimetype === 'image/gif'
}
},
methods: {
drawCanvas() {
const canvas = this.$refs.canvas
if (!canvas) return
const ctx = canvas.getContext('2d')
ctx.drawImage(this.$refs.src, 1, 1, canvas.width, canvas.height)
}
}
}
export default StillImage

View file

@ -0,0 +1,51 @@
<template>
<div class='still-image' :class='{ animated: animated }' >
<canvas ref="canvas" v-if="animated"></canvas>
<img ref="src" :src="src" :referrerpolicy="referrerpolicy" v-on:load="drawCanvas"/>
</div>
</template>
<script src="./still-image.js"></script>
<style lang="scss">
@import '../../_variables.scss';
.still-image {
position: relative;
&:hover canvas {
display: none;
}
&.animated {
&:hover::before,
img {
visibility: hidden
}
&:hover img {
visibility: visible
}
&::before {
content: 'gif';
position: absolute;
top: 5px;
left: 5px;
background: rgba(255,255,255,.5);
display: block;
padding: 2px;
z-index: 2;
}
}
canvas {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
}
}
</style>