diff options
| author | shpuld <shp@cock.li> | 2019-01-26 17:45:03 +0200 |
|---|---|---|
| committer | shpuld <shp@cock.li> | 2019-01-26 17:45:03 +0200 |
| commit | 3978aaef84cc023908155343af76983f2715cf90 (patch) | |
| tree | 0776b181029151d45450e472d1540715040bcab0 /src/components/attachment/attachment.js | |
| parent | 8761e039d04ff26944c87339ef55d2951a42696c (diff) | |
Redo everything in the MR
Diffstat (limited to 'src/components/attachment/attachment.js')
| -rw-r--r-- | src/components/attachment/attachment.js | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/components/attachment/attachment.js b/src/components/attachment/attachment.js index d16e5086..0ae8f71a 100644 --- a/src/components/attachment/attachment.js +++ b/src/components/attachment/attachment.js @@ -1,4 +1,5 @@ import StillImage from '../still-image/still-image.vue' +import VideoAttachment from '../video_attachment/video_attachment.vue' import nsfwImage from '../../assets/nsfw.png' import fileTypeService from '../../services/file_type/file_type.service.js' @@ -8,6 +9,7 @@ const Attachment = { 'nsfw', 'statusId', 'size', + 'allowPlay', 'setMedia' ], data () { @@ -16,11 +18,14 @@ const Attachment = { hideNsfwLocal: this.$store.state.config.hideNsfw, preloadImage: this.$store.state.config.preloadImage, loading: false, - modalOpen: false + img: fileTypeService.fileType(this.attachment.mimetype) === 'image' && document.createElement('img'), + modalOpen: false, + showHidden: false } }, components: { - StillImage + StillImage, + VideoAttachment }, computed: { usePlaceHolder () { @@ -33,7 +38,7 @@ const Attachment = { return fileTypeService.fileType(this.attachment.mimetype) }, hidden () { - return this.nsfw && this.hideNsfwLocal + return this.nsfw && this.hideNsfwLocal && !this.showHidden }, isEmpty () { return (this.type === 'html' && !this.attachment.oembed) || this.type === 'unknown' @@ -51,14 +56,38 @@ const Attachment = { window.open(target.href, '_blank') } }, - toggleModal (event) { - if (this.type !== 'image' && this.type !== 'video') { + openModal (event) { + const modalTypes = this.$store.state.config.playVideosInline + ? ['image'] + : ['image', 'video'] + if (fileTypeService.fileMatchesSomeType(modalTypes, this.attachment) || + this.usePlaceHolder + ) { + event.stopPropagation() + event.preventDefault() + this.setMedia() + this.$store.dispatch('setCurrent', this.attachment) + } + }, + toggleHidden (event) { + if (this.$store.state.config.useOneClickNsfw && !this.showHidden) { + this.openModal(event) return } - event.stopPropagation() - event.preventDefault() - this.setMedia() - this.$store.dispatch('setCurrent', this.attachment) + if (this.img && !this.preloadImage) { + if (this.img.onload) { + this.img.onload() + } else { + this.loading = true + this.img.src = this.attachment.url + this.img.onload = () => { + this.loading = false + this.showHidden = !this.showHidden + } + } + } else { + this.showHidden = !this.showHidden + } } } } |
