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-01-15 04:23:13 +11:00
|
|
|
import fileTypeService from '../../services/file_type/file_type.service.js'
|
|
|
|
|
|
|
|
const MediaModal = {
|
|
|
|
components: {
|
2019-01-27 02:45:03 +11:00
|
|
|
StillImage,
|
|
|
|
VideoAttachment
|
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
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
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
|