logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git
commit: b77259a9a0c353ede8ff1d6bf5c13ae91ca7fc7c
parent c93da0b865e9a14c6fa952e63c4c4f77f34943bc
Author: Tusooa Zhu <tusooa@kazv.moe>
Date:   Sat,  8 Jan 2022 01:35:16 -0500

Use StillImage to render emojis in emoji picker

Diffstat:

Msrc/components/emoji_picker/emoji_picker.js15+++++++++++++--
Msrc/components/emoji_picker/emoji_picker.vue5+++--
Msrc/components/still-image/still-image.js19+++++++++++++++++--
Msrc/components/still-image/still-image.vue5+++--
4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/src/components/emoji_picker/emoji_picker.js b/src/components/emoji_picker/emoji_picker.js @@ -118,8 +118,19 @@ const EmojiPicker = { }, initializeLazyLoad () { this.destroyLazyLoad() - this.$lozad = lozad('img', {}) - this.$lozad.observe() + this.$nextTick(() => { + this.$lozad = lozad('.still-image.emoji-picker-emoji', { + load: el => { + const vn = el.__vue__ + if (!vn) { + return + } + + vn.loadLazy() + } + }) + this.$lozad.observe() + }) }, waitForDomAndInitializeLazyLoad () { this.$nextTick(() => this.initializeLazyLoad()) diff --git a/src/components/emoji_picker/emoji_picker.vue b/src/components/emoji_picker/emoji_picker.vue @@ -89,10 +89,11 @@ @click.stop.prevent="onEmoji(emoji)" > <span v-if="!emoji.imageUrl">{{ emoji.replacement }}</span> - <img + <still-image v-else + class="emoji-picker-emoji" :data-src="emoji.imageUrl" - > + /> </span> <span :ref="'group-end-' + group.id" /> </div> diff --git a/src/components/still-image/still-image.js b/src/components/still-image/still-image.js @@ -7,16 +7,23 @@ const StillImage = { 'imageLoadHandler', 'alt', 'height', - 'width' + 'width', + 'dataSrc' ], data () { return { + // for lazy loading, see loadLazy() + realSrc: this.src, stopGifs: this.$store.getters.mergedConfig.stopGifs } }, computed: { animated () { - return this.stopGifs && (this.mimetype === 'image/gif' || this.src.endsWith('.gif')) + if (!this.realSrc) { + return false + } + + return this.stopGifs && (this.mimetype === 'image/gif' || this.realSrc.endsWith('.gif')) }, style () { const appendPx = (str) => /\d$/.test(str) ? str + 'px' : str @@ -27,7 +34,15 @@ const StillImage = { } }, methods: { + loadLazy () { + if (this.dataSrc) { + this.realSrc = this.dataSrc + } + }, onLoad () { + if (!this.realSrc) { + return + } const image = this.$refs.src if (!image) return this.imageLoadHandler && this.imageLoadHandler(image) diff --git a/src/components/still-image/still-image.vue b/src/components/still-image/still-image.vue @@ -11,10 +11,11 @@ <!-- NOTE: key is required to force to re-render img tag when src is changed --> <img ref="src" - :key="src" + :key="realSrc" :alt="alt" :title="alt" - :src="src" + :data-src="dataSrc" + :src="realSrc" :referrerpolicy="referrerpolicy" @load="onLoad" @error="onError"