gancio/components/MyPicture.vue

113 lines
2.3 KiB
Vue
Raw Normal View History

<template>
2022-05-03 12:08:10 +02:00
<div :class='{ thumb, img: true }'
2022-04-27 11:27:08 +02:00
:height="height" :width="width"
:style="backgroundPreview">
<img
v-if='media'
:class='{ "u-featured": true, loading }'
:alt='media.name' :loading='lazy?"lazy":"eager"'
:src="src"
2022-05-03 12:08:10 +02:00
:srcset="srcset"
itemprop="image"
2022-04-27 11:27:08 +02:00
:height="height" :width="width"
:style="{ 'object-position': thumbnailPosition }"
@load="loaded">
<img v-else-if='!media && thumb' class='thumb' src="noimg.svg" alt=''>
2022-05-03 12:08:10 +02:00
</div>
</template>
<script>
export default {
props: {
event: { type: Object, default: () => ({}) },
thumb: { type: Boolean, default: false },
lazy: { type: Boolean, default: false },
showPreview: { type: Boolean, default: true }
},
data () {
return { loading: true }
},
computed: {
2022-04-27 11:27:08 +02:00
backgroundPreview () {
2022-04-29 17:56:34 +02:00
if (this.media && this.media.preview) {
2022-04-27 11:27:08 +02:00
return {
backgroundPosition: this.thumbnailPosition,
backgroundImage: "url('data:image/png;base64," + this.media.preview + "')" }
}
},
2022-05-03 12:08:10 +02:00
srcset () {
if (this.thumb) return ''
return `/media/thumb/${this.media.url} 500w, /media/${this.media.url} 1200w`
},
media () {
return this.event.media[0]
},
2022-04-27 11:27:08 +02:00
height () {
return this.media ? this.media.height : 'auto'
},
width () {
return this.media ? this.media.width : 'auto'
},
src () {
if (this.media) {
2022-05-03 12:08:10 +02:00
return '/media/thumb/' + this.media.url
}
if (this.thumb) {
return '/noimg.svg'
}
},
thumbnailPosition () {
2022-04-27 11:27:08 +02:00
if (this.media.focalpoint) {
const focalpoint = this.media.focalpoint
return `${(focalpoint[0] + 1) * 50}% ${(focalpoint[1] + 1) * 50}%`
}
return 'center center'
},
},
methods: {
loaded () {
this.loading = false
}
}
}
</script>
<style>
.img {
width: 100%;
height: auto;
position: relative;
overflow: hidden;
2022-04-27 11:27:08 +02:00
display: flex;
background-size: cover;
}
.img img {
2022-05-03 12:08:10 +02:00
display: flex;
width: 100%;
max-width: 100%;
height: auto;
overflow: hidden;
2022-05-03 12:08:10 +02:00
transition: opacity .5s;
opacity: 1;
background-size: 100%;
}
.img.thumb img {
display: flex;
max-height: 250px;
min-height: 160px;
object-fit: cover;
object-position: top;
aspect-ratio: 1.7778;
}
2022-05-03 12:08:10 +02:00
.img img.loading {
opacity: 0;
}
</style>