2019-01-14 17:23:13 +00:00
|
|
|
import StillImage from '../still-image/still-image.vue'
|
2019-01-26 15:45:03 +00:00
|
|
|
import VideoAttachment from '../video_attachment/video_attachment.vue'
|
2019-10-18 11:05:01 +00:00
|
|
|
import Modal from '../modal/modal.vue'
|
2021-08-02 21:42:10 +00:00
|
|
|
import PinchZoom from '../pinch_zoom/pinch_zoom.vue'
|
2021-08-02 23:11:59 +00:00
|
|
|
import SwipeClick from '../swipe_click/swipe_click.vue'
|
2019-11-08 06:16:26 +00:00
|
|
|
import GestureService from '../../services/gesture_service/gesture_service'
|
2021-06-17 23:01:37 +00:00
|
|
|
import Flash from 'src/components/flash/flash.vue'
|
2021-08-02 23:11:59 +00:00
|
|
|
import fileTypeService from '../../services/file_type/file_type.service.js'
|
2020-10-20 19:13:19 +00:00
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
import {
|
|
|
|
faChevronLeft,
|
2021-08-15 22:02:56 +00:00
|
|
|
faChevronRight,
|
2022-03-03 17:51:13 +00:00
|
|
|
faCircleNotch,
|
|
|
|
faTimes
|
2020-10-20 19:13:19 +00:00
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
|
|
library.add(
|
|
|
|
faChevronLeft,
|
2021-08-15 22:02:56 +00:00
|
|
|
faChevronRight,
|
2022-03-03 17:51:13 +00:00
|
|
|
faCircleNotch,
|
|
|
|
faTimes
|
2020-10-20 19:13:19 +00:00
|
|
|
)
|
2019-01-14 17:23:13 +00:00
|
|
|
|
|
|
|
const MediaModal = {
|
|
|
|
components: {
|
2019-01-26 15:45:03 +00:00
|
|
|
StillImage,
|
2019-10-18 11:05:01 +00:00
|
|
|
VideoAttachment,
|
2021-08-02 21:42:10 +00:00
|
|
|
PinchZoom,
|
2021-08-02 23:11:59 +00:00
|
|
|
SwipeClick,
|
2021-06-17 23:01:37 +00:00
|
|
|
Modal,
|
|
|
|
Flash
|
2019-01-14 17:23:13 +00:00
|
|
|
},
|
2021-08-15 22:02:56 +00:00
|
|
|
data () {
|
|
|
|
return {
|
2021-08-02 21:42:10 +00:00
|
|
|
loading: false,
|
2021-08-02 23:11:59 +00:00
|
|
|
swipeDirection: GestureService.DIRECTION_LEFT,
|
2021-08-03 01:19:04 +00:00
|
|
|
swipeThreshold: () => {
|
|
|
|
const considerableMoveRatio = 1 / 4
|
|
|
|
return window.innerWidth * considerableMoveRatio
|
|
|
|
},
|
2021-08-02 23:21:18 +00:00
|
|
|
pinchZoomMinScale: 1,
|
|
|
|
pinchZoomScaleResetLimit: 1.2
|
2021-08-15 22:02:56 +00:00
|
|
|
}
|
2019-01-14 17:23:13 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
showing () {
|
|
|
|
return this.$store.state.mediaViewer.activated
|
|
|
|
},
|
2019-02-10 18:23:01 +00:00
|
|
|
media () {
|
|
|
|
return this.$store.state.mediaViewer.media
|
|
|
|
},
|
2021-08-15 16:45:48 +00:00
|
|
|
description () {
|
|
|
|
return this.currentMedia.description
|
|
|
|
},
|
2019-01-14 17:23:13 +00:00
|
|
|
currentIndex () {
|
|
|
|
return this.$store.state.mediaViewer.currentIndex
|
|
|
|
},
|
|
|
|
currentMedia () {
|
2019-02-10 18:23:01 +00:00
|
|
|
return this.media[this.currentIndex]
|
|
|
|
},
|
|
|
|
canNavigate () {
|
|
|
|
return this.media.length > 1
|
2019-01-14 17:23:13 +00:00
|
|
|
},
|
|
|
|
type () {
|
2021-08-15 22:02:56 +00:00
|
|
|
return this.currentMedia ? this.getType(this.currentMedia) : null
|
2019-01-14 17:23:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-08-15 22:02:56 +00:00
|
|
|
getType (media) {
|
|
|
|
return fileTypeService.fileType(media.mimetype)
|
2019-11-08 06:16:26 +00:00
|
|
|
},
|
2019-01-14 17:23:13 +00:00
|
|
|
hide () {
|
2021-08-02 23:34:18 +00:00
|
|
|
// HACK: Closing immediately via a touch will cause the click
|
|
|
|
// to be processed on the content below the overlay
|
|
|
|
const transitionTime = 100 // ms
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$store.dispatch('closeMediaViewer')
|
|
|
|
}, transitionTime)
|
2019-02-10 18:23:01 +00:00
|
|
|
},
|
2022-02-21 03:45:58 +00:00
|
|
|
hideIfNotSwiped (event) {
|
|
|
|
// If we have swiped over SwipeClick, do not trigger hide
|
|
|
|
const comp = this.$refs.swipeClick
|
|
|
|
if (!comp) {
|
|
|
|
this.hide()
|
|
|
|
} else {
|
|
|
|
comp.$gesture.click(event)
|
|
|
|
}
|
2019-02-10 18:23:01 +00:00
|
|
|
},
|
|
|
|
goPrev () {
|
|
|
|
if (this.canNavigate) {
|
|
|
|
const prevIndex = this.currentIndex === 0 ? this.media.length - 1 : (this.currentIndex - 1)
|
2021-08-15 22:02:56 +00:00
|
|
|
const newMedia = this.media[prevIndex]
|
|
|
|
if (this.getType(newMedia) === 'image') {
|
|
|
|
this.loading = true
|
|
|
|
}
|
|
|
|
this.$store.dispatch('setCurrentMedia', newMedia)
|
2019-02-10 18:23:01 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
goNext () {
|
|
|
|
if (this.canNavigate) {
|
|
|
|
const nextIndex = this.currentIndex === this.media.length - 1 ? 0 : (this.currentIndex + 1)
|
2021-08-15 22:02:56 +00:00
|
|
|
const newMedia = this.media[nextIndex]
|
|
|
|
if (this.getType(newMedia) === 'image') {
|
|
|
|
this.loading = true
|
|
|
|
}
|
|
|
|
this.$store.dispatch('setCurrentMedia', newMedia)
|
2019-02-10 18:23:01 +00:00
|
|
|
}
|
|
|
|
},
|
2021-08-15 22:02:56 +00:00
|
|
|
onImageLoaded () {
|
|
|
|
this.loading = false
|
|
|
|
},
|
2021-08-01 23:46:27 +00:00
|
|
|
handleSwipePreview (offsets) {
|
2021-08-02 23:11:59 +00:00
|
|
|
this.$refs.pinchZoom.setTransform({ scale: 1, x: offsets[0], y: 0 })
|
2021-08-01 23:46:27 +00:00
|
|
|
},
|
|
|
|
handleSwipeEnd (sign) {
|
2021-08-03 00:03:01 +00:00
|
|
|
this.$refs.pinchZoom.setTransform({ scale: 1, x: 0, y: 0 })
|
|
|
|
if (sign > 0) {
|
2021-08-01 23:46:27 +00:00
|
|
|
this.goNext()
|
2021-08-03 01:19:04 +00:00
|
|
|
} else if (sign < 0) {
|
2021-08-01 23:46:27 +00:00
|
|
|
this.goPrev()
|
2019-02-10 18:23:01 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
handleKeyupEvent (e) {
|
|
|
|
if (this.showing && e.keyCode === 27) { // escape
|
|
|
|
this.hide()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleKeydownEvent (e) {
|
|
|
|
if (!this.showing) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.keyCode === 39) { // arrow right
|
|
|
|
this.goNext()
|
|
|
|
} else if (e.keyCode === 37) { // arrow left
|
|
|
|
this.goPrev()
|
|
|
|
}
|
2019-01-14 17:23:13 +00:00
|
|
|
}
|
2019-02-10 18:23:01 +00:00
|
|
|
},
|
|
|
|
mounted () {
|
2020-06-04 14:30:28 +00:00
|
|
|
window.addEventListener('popstate', this.hide)
|
2019-02-10 18:23:01 +00:00
|
|
|
document.addEventListener('keyup', this.handleKeyupEvent)
|
|
|
|
document.addEventListener('keydown', this.handleKeydownEvent)
|
|
|
|
},
|
2021-04-25 10:44:50 +00:00
|
|
|
unmounted () {
|
2020-06-04 14:30:28 +00:00
|
|
|
window.removeEventListener('popstate', this.hide)
|
2019-02-10 18:23:01 +00:00
|
|
|
document.removeEventListener('keyup', this.handleKeyupEvent)
|
|
|
|
document.removeEventListener('keydown', this.handleKeydownEvent)
|
2019-01-14 17:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MediaModal
|