2019-01-15 04:23:13 +11:00
|
|
|
import StillImage from '../still-image/still-image.vue'
|
2019-01-27 02:45:03 +11:00
|
|
|
import VideoAttachment from '../video_attachment/video_attachment.vue'
|
2019-10-18 22:05:01 +11:00
|
|
|
import Modal from '../modal/modal.vue'
|
2019-01-15 04:23:13 +11:00
|
|
|
import fileTypeService from '../../services/file_type/file_type.service.js'
|
2019-11-08 17:16:26 +11:00
|
|
|
import GestureService from '../../services/gesture_service/gesture_service'
|
2019-01-15 04:23:13 +11:00
|
|
|
|
|
|
|
const MediaModal = {
|
|
|
|
components: {
|
2019-01-27 02:45:03 +11:00
|
|
|
StillImage,
|
2019-10-18 22:05:01 +11:00
|
|
|
VideoAttachment,
|
|
|
|
Modal
|
2019-01-15 04:23:13 +11:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
showing () {
|
|
|
|
return this.$store.state.mediaViewer.activated
|
|
|
|
},
|
2019-02-11 05:23:01 +11:00
|
|
|
media () {
|
|
|
|
return this.$store.state.mediaViewer.media
|
|
|
|
},
|
2019-01-15 04:23:13 +11:00
|
|
|
currentIndex () {
|
|
|
|
return this.$store.state.mediaViewer.currentIndex
|
|
|
|
},
|
|
|
|
currentMedia () {
|
2019-02-11 05:23:01 +11:00
|
|
|
return this.media[this.currentIndex]
|
|
|
|
},
|
|
|
|
canNavigate () {
|
|
|
|
return this.media.length > 1
|
2019-01-15 04:23:13 +11:00
|
|
|
},
|
|
|
|
type () {
|
|
|
|
return this.currentMedia ? fileTypeService.fileType(this.currentMedia.mimetype) : null
|
|
|
|
}
|
|
|
|
},
|
2019-11-08 17:16:26 +11:00
|
|
|
created () {
|
|
|
|
this.mediaSwipeGestureRight = GestureService.swipeGesture(
|
|
|
|
GestureService.DIRECTION_RIGHT,
|
|
|
|
this.goPrev,
|
|
|
|
50
|
|
|
|
)
|
|
|
|
this.mediaSwipeGestureLeft = GestureService.swipeGesture(
|
|
|
|
GestureService.DIRECTION_LEFT,
|
|
|
|
this.goNext,
|
|
|
|
50
|
|
|
|
)
|
|
|
|
},
|
2019-01-15 04:23:13 +11:00
|
|
|
methods: {
|
2019-11-08 17:16:26 +11:00
|
|
|
mediaTouchStart (e) {
|
|
|
|
GestureService.beginSwipe(e, this.mediaSwipeGestureRight)
|
|
|
|
GestureService.beginSwipe(e, this.mediaSwipeGestureLeft)
|
|
|
|
},
|
|
|
|
mediaTouchMove (e) {
|
|
|
|
GestureService.updateSwipe(e, this.mediaSwipeGestureRight)
|
|
|
|
GestureService.updateSwipe(e, this.mediaSwipeGestureLeft)
|
|
|
|
},
|
2019-01-15 04:23:13 +11:00
|
|
|
hide () {
|
|
|
|
this.$store.dispatch('closeMediaViewer')
|
2019-02-11 05:23:01 +11:00
|
|
|
},
|
|
|
|
goPrev () {
|
|
|
|
if (this.canNavigate) {
|
|
|
|
const prevIndex = this.currentIndex === 0 ? this.media.length - 1 : (this.currentIndex - 1)
|
|
|
|
this.$store.dispatch('setCurrent', this.media[prevIndex])
|
|
|
|
}
|
|
|
|
},
|
|
|
|
goNext () {
|
|
|
|
if (this.canNavigate) {
|
|
|
|
const nextIndex = this.currentIndex === this.media.length - 1 ? 0 : (this.currentIndex + 1)
|
|
|
|
this.$store.dispatch('setCurrent', this.media[nextIndex])
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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-15 04:23:13 +11:00
|
|
|
}
|
2019-02-11 05:23:01 +11:00
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
document.addEventListener('keyup', this.handleKeyupEvent)
|
|
|
|
document.addEventListener('keydown', this.handleKeydownEvent)
|
|
|
|
},
|
|
|
|
destroyed () {
|
|
|
|
document.removeEventListener('keyup', this.handleKeyupEvent)
|
|
|
|
document.removeEventListener('keydown', this.handleKeydownEvent)
|
2019-01-15 04:23:13 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MediaModal
|