pinafore/routes/_components/LazyImage.html
Nolan Lawson 92edb3d835
fix(firefox): fix firefox with blocked images (#718)
* fix(firefox): fix firefox with blocked images

* remove excessive perf marks

* fixup

* fix lint
2018-12-03 23:08:38 -08:00

52 lines
1 KiB
HTML

<div class="lazy-image" style={computedStyle} >
<img
class={className}
aria-hidden={ariaHidden}
{alt}
{title}
{width}
{height}
src={displaySrc}
ref:node
/>
</div>
<style>
.lazy-image {
overflow: hidden;
}
</style>
<script>
import { decodeImage } from '../_utils/decodeImage'
export default {
async oncreate () {
try {
await decodeImage(this.refs.node)
} catch (e) {
this.set({ error: true })
}
},
data: () => ({
error: false,
fallback: void 0,
background: '',
width: void 0,
height: void 0,
className: '',
ariaHidden: '',
alt: '',
title: ''
}),
computed: {
computedStyle: ({ width, height, background }) => {
return [
width && `width: ${width}px;`,
height && `height: ${height}px;`,
background && `background: ${background};`
].filter(Boolean).join('')
},
displaySrc: ({ error, src, fallback }) => ((error && fallback) || src)
}
}
</script>