aboutsummaryrefslogtreecommitdiff
path: root/src/components/media_modal/media_modal.js
blob: 95c3b4a95fe37626ac06ccc0b3887a2789ec5dca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import StillImage from '../still-image/still-image.vue'
import fileTypeService from '../../services/file_type/file_type.service.js'

const MediaModal = {
  data () {
    return {
      loopVideo: this.$store.state.config.loopVideo
    }
  },
  components: {
    StillImage
  },
  computed: {
    showing () {
      return this.$store.state.mediaViewer.activated
    },
    currentIndex () {
      return this.$store.state.mediaViewer.currentIndex
    },
    currentMedia () {
      return this.$store.state.mediaViewer.media[this.currentIndex]
    },
    type () {
      return this.currentMedia ? fileTypeService.fileType(this.currentMedia.mimetype) : null
    }
  },
  created () {
    document.addEventListener('keyup', e => {
      if (e.keyCode === 27 && this.showing) { // escape
        this.hide()
      }
    })
  },
  methods: {
    hide () {
      this.$store.dispatch('closeMediaViewer')
    },
    onVideoDataLoad (e) {
      if (!e.srcElement) {
        return
      }
      if (typeof e.srcElement.webkitAudioDecodedByteCount !== 'undefined') {
        // non-zero if video has audio track
        if (e.srcElement.webkitAudioDecodedByteCount > 0) {
          this.loopVideo = this.$store.state.config.loopVideo && !this.$store.state.config.loopVideoSilentOnly
        }
      } else if (typeof e.srcElement.mozHasAudio !== 'undefined') {
        // true if video has audio track
        if (e.srcElement.mozHasAudio) {
          this.loopVideo = this.$store.state.config.loopVideo && !this.$store.state.config.loopVideoSilentOnly
        }
      } else if (typeof e.srcElement.audioTracks !== 'undefined') {
        if (e.srcElement.audioTracks.length > 0) {
          this.loopVideo = this.$store.state.config.loopVideo && !this.$store.state.config.loopVideoSilentOnly
        }
      }
    }
  }
}

export default MediaModal