Skip to content
Snippets Groups Projects
attachment.js 1.15 KiB
Newer Older
lain's avatar
lain committed
import nsfwImage from '../../assets/nsfw.png'
dtluna's avatar
dtluna committed
import fileTypeService from '../../services/file_type/file_type.service.js'

const Attachment = {
  props: [
    'attachment',
lain's avatar
lain committed
    'nsfw',
    'statusId'
  data () {
    return {
      nsfwImage,
      hideNsfwLocal: this.$store.state.config.hideNsfw,
      showHidden: false,
      loading: false,
      img: document.createElement('img')
  computed: {
    type () {
dtluna's avatar
dtluna committed
      return fileTypeService.fileType(this.attachment.mimetype)
lain's avatar
lain committed
    },
    hidden () {
      return this.nsfw && this.hideNsfwLocal && !this.showHidden
      return (this.type === 'html' && !this.attachment.oembed) || this.type === 'unknown'
    }
  },
  methods: {
    linkClicked ({target}) {
      if (target.tagName === 'A') {
        window.open(target.href, '_blank')
      }
    },
lain's avatar
lain committed
    toggleHidden () {
      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
        }
lain's avatar
lain committed
export default Attachment