logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

still-image.js (1595B)


  1. const StillImage = {
  2. props: [
  3. 'src',
  4. 'referrerpolicy',
  5. 'mimetype',
  6. 'imageLoadError',
  7. 'imageLoadHandler',
  8. 'alt',
  9. 'height',
  10. 'width',
  11. 'dataSrc',
  12. 'loading'
  13. ],
  14. data () {
  15. return {
  16. // for lazy loading, see loadLazy()
  17. realSrc: this.src,
  18. stopGifs: this.$store.getters.mergedConfig.stopGifs
  19. }
  20. },
  21. computed: {
  22. animated () {
  23. if (!this.realSrc) {
  24. return false
  25. }
  26. return this.stopGifs && (this.mimetype === 'image/gif' || this.realSrc.endsWith('.gif'))
  27. },
  28. style () {
  29. const appendPx = (str) => /\d$/.test(str) ? str + 'px' : str
  30. return {
  31. height: this.height ? appendPx(this.height) : null,
  32. width: this.width ? appendPx(this.width) : null
  33. }
  34. }
  35. },
  36. methods: {
  37. loadLazy () {
  38. if (this.dataSrc) {
  39. this.realSrc = this.dataSrc
  40. }
  41. },
  42. onLoad () {
  43. if (!this.realSrc) {
  44. return
  45. }
  46. const image = this.$refs.src
  47. if (!image) return
  48. this.imageLoadHandler && this.imageLoadHandler(image)
  49. const canvas = this.$refs.canvas
  50. if (!canvas) return
  51. const width = image.naturalWidth
  52. const height = image.naturalHeight
  53. canvas.width = width
  54. canvas.height = height
  55. canvas.getContext('2d').drawImage(image, 0, 0, width, height)
  56. },
  57. onError () {
  58. this.imageLoadError && this.imageLoadError()
  59. }
  60. },
  61. watch: {
  62. src () {
  63. this.realSrc = this.src
  64. },
  65. dataSrc () {
  66. this.$el.removeAttribute('data-loaded')
  67. }
  68. }
  69. }
  70. export default StillImage