2018-08-23 04:00:53 +00:00
|
|
|
<img
|
|
|
|
class={computedClass}
|
|
|
|
aria-hidden={ariaHidden}
|
|
|
|
{alt}
|
|
|
|
{title}
|
|
|
|
{width}
|
|
|
|
{height}
|
|
|
|
src={displaySrc}
|
|
|
|
on:mouseover="onMouseOver(event)"
|
2018-08-31 23:35:26 +00:00
|
|
|
ref:node
|
2018-08-23 04:00:53 +00:00
|
|
|
/>
|
2018-02-01 02:20:30 +00:00
|
|
|
<style>
|
|
|
|
.non-autoplay-zoom-in {
|
|
|
|
cursor: zoom-in;
|
|
|
|
}
|
2018-03-17 01:48:24 +00:00
|
|
|
.non-autoplay-zoom-in.is-link {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2018-02-01 02:20:30 +00:00
|
|
|
</style>
|
|
|
|
<script>
|
2018-08-23 04:00:53 +00:00
|
|
|
import { mouseover } from '../_utils/events'
|
|
|
|
import { decodeImage } from '../_utils/decodeImage'
|
|
|
|
import { classname } from '../_utils/classname'
|
2018-12-04 07:08:38 +00:00
|
|
|
import { ONE_TRANSPARENT_PIXEL } from '../_static/media'
|
2018-08-23 04:00:53 +00:00
|
|
|
|
2018-02-01 02:20:30 +00:00
|
|
|
export default {
|
2018-08-23 04:00:53 +00:00
|
|
|
async oncreate () {
|
2019-08-03 20:49:37 +00:00
|
|
|
const { currentSrc } = this.get()
|
2018-08-23 04:00:53 +00:00
|
|
|
try {
|
2019-08-03 20:49:37 +00:00
|
|
|
const image = new Image()
|
2018-12-04 07:08:38 +00:00
|
|
|
image.src = currentSrc
|
|
|
|
await decodeImage(image)
|
|
|
|
this.set({ loaded: true })
|
2018-08-23 04:00:53 +00:00
|
|
|
this.fire('imgLoad')
|
|
|
|
} catch (e) {
|
|
|
|
this.fire('imgLoadError', e)
|
|
|
|
}
|
|
|
|
},
|
2018-02-01 02:20:30 +00:00
|
|
|
methods: {
|
2018-04-20 04:38:01 +00:00
|
|
|
onMouseOver (mouseOver) {
|
2018-08-31 23:35:26 +00:00
|
|
|
this.set({ mouseOver })
|
2018-02-01 02:20:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
mouseover
|
2018-08-23 04:00:53 +00:00
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
alt: '',
|
2018-08-31 23:35:26 +00:00
|
|
|
title: '',
|
2018-12-04 07:08:38 +00:00
|
|
|
mouseOver: false,
|
2018-12-05 06:31:46 +00:00
|
|
|
loaded: false,
|
|
|
|
ariaHidden: false
|
2018-08-23 04:00:53 +00:00
|
|
|
}),
|
|
|
|
computed: {
|
2018-08-30 04:42:57 +00:00
|
|
|
computedClass: ({ className, src, staticSrc, isLink }) => (classname(
|
2018-08-23 04:00:53 +00:00
|
|
|
className,
|
|
|
|
src !== staticSrc && 'non-autoplay-zoom-in',
|
|
|
|
isLink && 'is-link'
|
2018-08-31 23:35:26 +00:00
|
|
|
)),
|
2018-12-04 07:08:38 +00:00
|
|
|
currentSrc: ({ mouseOver, src, staticSrc }) => mouseOver ? src : staticSrc,
|
|
|
|
// using a transparent pixel as placeholder ensures broken images don't have wrong sizes
|
|
|
|
displaySrc: ({ loaded, currentSrc }) => loaded ? currentSrc : ONE_TRANSPARENT_PIXEL
|
2018-02-01 02:20:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-04 07:08:38 +00:00
|
|
|
</script>
|