2019-01-04 14:34:32 +00:00
|
|
|
<template>
|
|
|
|
<div class="image-viewer"
|
2019-01-12 20:08:07 +00:00
|
|
|
:class="{ 'is-visible': isVisible }">
|
2019-01-13 20:22:02 +00:00
|
|
|
<transition name="trans-bg-image">
|
2019-01-22 12:57:44 +00:00
|
|
|
<div v-if="backgroundImageUrl !== null"
|
|
|
|
:key="backgroundImageUrl"
|
|
|
|
class="viewer-background"
|
|
|
|
:style="backgroundStyle"
|
|
|
|
></div>
|
2019-01-13 18:06:56 +00:00
|
|
|
</transition>
|
|
|
|
<div class="image-container">
|
|
|
|
<transition name="trans-bg-image">
|
2019-01-13 20:56:05 +00:00
|
|
|
<img v-if="showLoading" class="image" :src="loadingImageUrl">
|
2019-01-13 18:06:56 +00:00
|
|
|
</transition>
|
2019-01-12 20:08:07 +00:00
|
|
|
</div>
|
2019-01-13 10:35:38 +00:00
|
|
|
<div class="image-container">
|
2019-01-13 18:06:56 +00:00
|
|
|
<transition name="trans-image" mode="out-in">
|
2019-01-22 12:57:44 +00:00
|
|
|
<img v-if="displayImageUrl !== null"
|
|
|
|
:key="displayImageUrl"
|
2019-01-23 11:36:51 +00:00
|
|
|
class="image image-shadow"
|
2019-01-22 12:57:44 +00:00
|
|
|
:src="displayImageUrl"
|
|
|
|
>
|
2019-01-13 18:06:56 +00:00
|
|
|
</transition>
|
2019-01-13 10:35:38 +00:00
|
|
|
</div>
|
2019-01-10 13:28:35 +00:00
|
|
|
<div class="close-viewer mobile-only"
|
2019-01-04 14:34:32 +00:00
|
|
|
@click="$emit('close')">
|
|
|
|
X
|
|
|
|
</div>
|
2019-01-10 13:28:35 +00:00
|
|
|
<ThumbNav v-if="hasPrev"
|
|
|
|
class="thumb-nav thumb-nav--left mobile-only"
|
|
|
|
direction="left"
|
|
|
|
@navClick="$emit('clickPrev')"/>
|
|
|
|
<ThumbNav v-if="hasNext"
|
|
|
|
class="thumb-nav thumb-nav--right mobile-only"
|
|
|
|
direction="right"
|
|
|
|
@navClick="$emit('clickNext')"/>
|
2019-01-04 14:34:32 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-01-10 13:28:35 +00:00
|
|
|
import ThumbNav from '@/components/ThumbNav'
|
2019-01-13 21:33:55 +00:00
|
|
|
import imageLoader from '~/mixins/imageLoader.js'
|
2019-01-10 13:28:35 +00:00
|
|
|
|
2019-01-04 14:34:32 +00:00
|
|
|
export default {
|
2019-01-10 13:28:35 +00:00
|
|
|
components: {
|
|
|
|
ThumbNav
|
|
|
|
},
|
2019-01-13 21:33:55 +00:00
|
|
|
mixins: [ imageLoader ],
|
2019-01-04 14:34:32 +00:00
|
|
|
props: {
|
|
|
|
isVisible: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
2019-01-09 21:23:03 +00:00
|
|
|
},
|
|
|
|
imageUrl: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default () {
|
|
|
|
return ''
|
|
|
|
}
|
2019-01-10 13:28:35 +00:00
|
|
|
},
|
|
|
|
hasNext: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
hasPrev: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
2019-01-04 14:34:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data () {
|
|
|
|
return {
|
2019-01-13 18:06:56 +00:00
|
|
|
loadingImageUrl: 'https://via.placeholder.com/120x120',
|
2019-01-22 12:55:03 +00:00
|
|
|
backgroundImageUrl: null, // blurred vwersion of image that makes up the background
|
|
|
|
displayImageUrl: null, // image being viewed
|
2019-01-13 18:06:56 +00:00
|
|
|
showLoading: true,
|
|
|
|
loadingTimeout: null
|
2019-01-04 14:34:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-01-09 21:23:03 +00:00
|
|
|
computed: {
|
2019-01-12 20:08:07 +00:00
|
|
|
backgroundStyle () {
|
2019-01-09 21:23:03 +00:00
|
|
|
return {
|
2019-01-13 18:06:56 +00:00
|
|
|
backgroundImage: 'url(' + this.backgroundImageUrl + ')'
|
2019-01-09 21:23:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-01-13 18:06:56 +00:00
|
|
|
watch: {
|
|
|
|
imageUrl () {
|
|
|
|
this.setImages(this.imageUrl)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted () {
|
|
|
|
this.setImages(this.imageUrl)
|
|
|
|
},
|
|
|
|
|
2019-01-04 14:34:32 +00:00
|
|
|
methods: {
|
2019-01-13 18:06:56 +00:00
|
|
|
setImages(url) {
|
|
|
|
this.displayImageUrl = null
|
|
|
|
this.loadingTimeout = setTimeout(() => {
|
|
|
|
this.showLoading = true
|
|
|
|
}, 1000)
|
|
|
|
this.loadImage(this.imageUrl)
|
|
|
|
.then(img => {
|
|
|
|
this.displayImageUrl = img.src
|
|
|
|
clearTimeout(this.loadingTimeout)
|
|
|
|
this.showLoading = false
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.backgroundImageUrl = img.src
|
|
|
|
})
|
|
|
|
}, 200)
|
|
|
|
})
|
|
|
|
// TODO catch errors
|
|
|
|
},
|
|
|
|
},
|
2019-01-04 14:34:32 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.image-viewer {
|
2019-01-13 10:35:38 +00:00
|
|
|
background-color: #222;
|
2019-01-12 20:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.image-container {
|
2019-01-10 13:28:35 +00:00
|
|
|
background-size: contain;
|
|
|
|
background-repeat: no-repeat;
|
2019-01-12 20:08:07 +00:00
|
|
|
background-color: transparent;
|
2019-01-04 14:34:32 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:35:38 +00:00
|
|
|
.image {
|
2019-01-13 20:56:05 +00:00
|
|
|
position: absolute;
|
2019-01-13 10:35:38 +00:00
|
|
|
width: auto;
|
|
|
|
height: auto;
|
|
|
|
max-height: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
margin: 0 auto;
|
|
|
|
top: 50%;
|
2019-01-13 20:56:05 +00:00
|
|
|
left: 50%;
|
|
|
|
transform: translate(-50%, -50%);
|
2019-01-13 10:35:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 11:36:51 +00:00
|
|
|
.image-shadow {
|
|
|
|
box-shadow: 2px 4px 12px -2px rgba($color__neutral-200, .4);
|
|
|
|
}
|
|
|
|
|
2019-01-04 14:34:32 +00:00
|
|
|
@media (max-width: $bp__layout) {
|
|
|
|
.close-viewer {
|
2019-01-12 20:08:07 +00:00
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
2019-01-04 14:34:32 +00:00
|
|
|
font-size: 10em;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.image-viewer {
|
|
|
|
z-index: 50;
|
2019-01-12 20:08:07 +00:00
|
|
|
position: relative;
|
2019-01-04 14:34:32 +00:00
|
|
|
|
|
|
|
transition: opacity 1s; //TEMP
|
|
|
|
opacity: 0;
|
|
|
|
pointer-events: none;
|
|
|
|
|
|
|
|
&.is-visible {
|
|
|
|
opacity: 1;
|
|
|
|
pointer-events: auto;
|
|
|
|
}
|
|
|
|
}
|
2019-01-12 20:08:07 +00:00
|
|
|
|
|
|
|
.image-container {
|
|
|
|
position: absolute;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
background-position: center center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.thumb-nav {
|
|
|
|
position: absolute;
|
|
|
|
width: 50%;
|
|
|
|
height: 100%;
|
|
|
|
top: 0;
|
|
|
|
|
|
|
|
&--left {
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&--right {
|
|
|
|
right: 0;
|
|
|
|
}
|
|
|
|
}
|
2019-01-04 14:34:32 +00:00
|
|
|
}
|
2019-01-09 21:23:03 +00:00
|
|
|
|
|
|
|
@media (min-width: $bp__layout) {
|
2019-01-10 13:28:35 +00:00
|
|
|
.mobile-only {
|
2019-01-09 21:23:03 +00:00
|
|
|
display: none;
|
|
|
|
}
|
2019-01-10 13:28:35 +00:00
|
|
|
|
|
|
|
.image-viewer {
|
2019-01-12 20:08:07 +00:00
|
|
|
padding: 1rem 1rem 1rem 4rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.image-container {
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
left: calc(3rem + 8px);
|
2019-01-17 11:42:41 +00:00
|
|
|
right: $gallery-featured-width--compact;
|
2019-01-12 20:08:07 +00:00
|
|
|
bottom: 8px;
|
|
|
|
background-position: top center;
|
2019-01-17 11:42:41 +00:00
|
|
|
|
|
|
|
@media (min-width: $bp__gallery-compact) {
|
|
|
|
right: $gallery-featured-width;
|
|
|
|
}
|
2019-01-10 13:28:35 +00:00
|
|
|
}
|
2019-01-13 10:35:38 +00:00
|
|
|
|
|
|
|
.viewer-background {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
background-size: 100% 100%;
|
|
|
|
background-position: center center;
|
|
|
|
filter: blur(100px);
|
|
|
|
opacity: .3;
|
|
|
|
}
|
2019-01-09 21:23:03 +00:00
|
|
|
}
|
2019-01-13 18:06:56 +00:00
|
|
|
|
2019-01-13 20:11:19 +00:00
|
|
|
.trans-image {
|
2019-01-13 20:56:05 +00:00
|
|
|
&-enter-active {
|
|
|
|
transition: opacity 1s .4s;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-leave-active {
|
|
|
|
transition: opacity .5s;
|
2019-01-13 20:11:19 +00:00
|
|
|
}
|
2019-01-13 18:06:56 +00:00
|
|
|
|
2019-01-13 20:11:19 +00:00
|
|
|
&-enter, &-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2019-01-13 18:06:56 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 20:11:19 +00:00
|
|
|
.trans-bg-image {
|
|
|
|
&-enter-active, &-leave-active {
|
2019-01-13 20:22:02 +00:00
|
|
|
transition: opacity .8s;
|
2019-01-13 20:11:19 +00:00
|
|
|
}
|
2019-01-13 18:06:56 +00:00
|
|
|
|
2019-01-13 20:11:19 +00:00
|
|
|
&-enter, &-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2019-01-13 18:06:56 +00:00
|
|
|
}
|
2019-01-04 14:34:32 +00:00
|
|
|
</style>
|