2018-01-29 10:47:26 +03:00
|
|
|
const StillImage = {
|
|
|
|
|
props: [
|
|
|
|
|
'src',
|
|
|
|
|
'referrerpolicy',
|
2019-02-02 14:11:36 -05:00
|
|
|
'mimetype',
|
2019-10-18 16:04:17 -04:00
|
|
|
'imageLoadError',
|
2019-02-18 05:03:26 +00:00
|
|
|
'imageLoadHandler',
|
2022-02-03 22:50:32 +02:00
|
|
|
'alt',
|
|
|
|
|
'height',
|
2022-01-08 01:35:16 -05:00
|
|
|
'width',
|
2022-12-24 12:43:30 -05:00
|
|
|
'dataSrc',
|
2026-01-06 16:22:52 +02:00
|
|
|
'loading',
|
2018-01-29 10:47:26 +03:00
|
|
|
],
|
2026-01-06 16:22:52 +02:00
|
|
|
data() {
|
2018-03-12 02:31:33 +03:00
|
|
|
return {
|
2022-01-08 01:35:16 -05:00
|
|
|
// for lazy loading, see loadLazy()
|
|
|
|
|
realSrc: this.src,
|
2026-01-06 16:22:52 +02:00
|
|
|
stopGifs: this.$store.getters.mergedConfig.stopGifs,
|
2018-03-12 02:31:33 +03:00
|
|
|
}
|
|
|
|
|
},
|
2018-01-29 10:47:26 +03:00
|
|
|
computed: {
|
2026-01-06 16:22:52 +02:00
|
|
|
animated() {
|
2022-01-08 01:35:16 -05:00
|
|
|
if (!this.realSrc) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
return (
|
|
|
|
|
this.stopGifs &&
|
|
|
|
|
(this.mimetype === 'image/gif' || this.realSrc.endsWith('.gif'))
|
|
|
|
|
)
|
2022-02-03 22:50:32 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
style() {
|
|
|
|
|
const appendPx = (str) => (/\d$/.test(str) ? str + 'px' : str)
|
2022-02-03 22:50:32 +02:00
|
|
|
return {
|
|
|
|
|
height: this.height ? appendPx(this.height) : null,
|
2026-01-06 16:22:52 +02:00
|
|
|
width: this.width ? appendPx(this.width) : null,
|
2022-02-03 22:50:32 +02:00
|
|
|
}
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
2018-01-29 10:47:26 +03:00
|
|
|
},
|
|
|
|
|
methods: {
|
2026-01-06 16:22:52 +02:00
|
|
|
loadLazy() {
|
2022-01-08 01:35:16 -05:00
|
|
|
if (this.dataSrc) {
|
|
|
|
|
this.realSrc = this.dataSrc
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
onLoad() {
|
2022-01-08 01:35:16 -05:00
|
|
|
if (!this.realSrc) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-09-29 10:18:37 +00:00
|
|
|
const image = this.$refs.src
|
|
|
|
|
if (!image) return
|
|
|
|
|
this.imageLoadHandler && this.imageLoadHandler(image)
|
2018-01-29 10:47:26 +03:00
|
|
|
const canvas = this.$refs.canvas
|
|
|
|
|
if (!canvas) return
|
2020-09-29 10:18:37 +00:00
|
|
|
const width = image.naturalWidth
|
|
|
|
|
const height = image.naturalHeight
|
2018-08-27 22:40:30 +03:00
|
|
|
canvas.width = width
|
|
|
|
|
canvas.height = height
|
2020-09-29 10:18:37 +00:00
|
|
|
canvas.getContext('2d').drawImage(image, 0, 0, width, height)
|
2019-02-05 17:17:50 +02:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
onError() {
|
2019-02-05 17:17:50 +02:00
|
|
|
this.imageLoadError && this.imageLoadError()
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
2022-01-17 23:41:11 -05:00
|
|
|
},
|
|
|
|
|
watch: {
|
2026-01-06 16:22:52 +02:00
|
|
|
src() {
|
2022-01-17 23:41:11 -05:00
|
|
|
this.realSrc = this.src
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
dataSrc() {
|
2022-01-17 23:41:11 -05:00
|
|
|
this.$el.removeAttribute('data-loaded')
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
|
|
|
|
},
|
2018-01-29 10:47:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default StillImage
|