|
| 1 | +<template> |
| 2 | + <div v-if="lqip && lqip.active"> |
| 3 | + <Intersect @enter="lqipSrc = imageAttrs.src" @leave="lqipSrc = lqipImage.src"> |
| 4 | + <img class="=ik-image" ref="imageRef" v-bind:src="lqipSrc" /> |
| 5 | + </Intersect> |
| 6 | + </div> |
| 7 | + <div v-else> |
| 8 | + <img class="=ik-image" ref="imageRef" v-bind="imageAttrs" /> |
| 9 | + </div> |
| 10 | +</template> |
| 11 | + |
| 12 | +<script> |
| 13 | +import Intersect from "./Intersect"; |
| 14 | +import { generateUrl } from "../helpers/urlGenerators"; |
| 15 | +
|
| 16 | +import Vue from "vue"; |
| 17 | +export default Vue.extend({ |
| 18 | + name: "IKImage", |
| 19 | + inject: { configurations: { default: "" } }, |
| 20 | + data() { |
| 21 | + return { |
| 22 | + lqipSrc: "" |
| 23 | + }; |
| 24 | + }, |
| 25 | + components: { Intersect }, |
| 26 | + props: { |
| 27 | + publicKey: { type: String, default: "", required: false }, |
| 28 | + urlEndpoint: { type: String, default: "", required: false }, |
| 29 | + path: { type: String, default: "", required: false }, |
| 30 | + src: { type: String, default: "", required: false }, |
| 31 | + transformation: { type: Array, required: false }, |
| 32 | + lqip: { type: Object, required: false } |
| 33 | + }, |
| 34 | + computed: { |
| 35 | + imageAttrs() { |
| 36 | + const { configurations } = this; |
| 37 | + let src = generateUrl({ |
| 38 | + publicKey: |
| 39 | + configurations && configurations.publicKey |
| 40 | + ? configurations.publicKey |
| 41 | + : this.publicKey, |
| 42 | + urlEndpoint: |
| 43 | + configurations && configurations.urlEndpoint |
| 44 | + ? configurations.urlEndpoint |
| 45 | + : this.urlEndpoint, |
| 46 | + src: this.src, |
| 47 | + path: this.path, |
| 48 | + transformation: this.transformation |
| 49 | + }); |
| 50 | +
|
| 51 | + return { |
| 52 | + src |
| 53 | + }; |
| 54 | + }, |
| 55 | + lqipImage() { |
| 56 | + const { lqip, path } = this; |
| 57 | + let { src } = this; |
| 58 | + if (lqip !== undefined && lqip.active) { |
| 59 | + const quality = lqip.quality; |
| 60 | + if (path !== "") { |
| 61 | + let newUrl = src.split("tr:"); |
| 62 | + if (newUrl[0] === src) { |
| 63 | + let newUrl = src.split("/"); |
| 64 | + newUrl = `${newUrl[0]}//${newUrl[2]}/${ |
| 65 | + newUrl[3] |
| 66 | + }/tr:q-${quality}/${newUrl[4]}`; |
| 67 | + src = `${newUrl}`; |
| 68 | + } else { |
| 69 | + newUrl = `${newUrl[0]}tr:q-${quality}${newUrl[1]}`; |
| 70 | + src = `${newUrl}`; |
| 71 | + } |
| 72 | + } else { |
| 73 | + src = `${src}?tr=q-${quality}`; |
| 74 | + } |
| 75 | + } |
| 76 | +
|
| 77 | + return { |
| 78 | + src |
| 79 | + }; |
| 80 | + } |
| 81 | + }, |
| 82 | + mounted: function() {} |
| 83 | +}); |
| 84 | +</script> |
0 commit comments