diff options
Diffstat (limited to 'app/assets/javascripts/design_management/components/image.vue')
-rw-r--r-- | app/assets/javascripts/design_management/components/image.vue | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/assets/javascripts/design_management/components/image.vue b/app/assets/javascripts/design_management/components/image.vue index 8ab94cd2c4b..5354c7756f5 100644 --- a/app/assets/javascripts/design_management/components/image.vue +++ b/app/assets/javascripts/design_management/components/image.vue @@ -57,6 +57,7 @@ export default { methods: { onImgLoad() { requestIdleCallback(this.setBaseImageSize, { timeout: 1000 }); + requestIdleCallback(this.setImageNaturalScale, { timeout: 1000 }); performanceMarkAndMeasure({ measures: [ { @@ -79,6 +80,27 @@ export default { }; this.onResize({ width: this.baseImageSize.width, height: this.baseImageSize.height }); }, + setImageNaturalScale() { + const { contentImg } = this.$refs; + + if (!contentImg) { + return; + } + + const { naturalHeight, naturalWidth } = contentImg; + + // In case image 404s + if (naturalHeight === 0 || naturalWidth === 0) { + return; + } + + const { height, width } = this.baseImageSize; + + this.$parent.$emit( + 'setMaxScale', + Math.round(((height + width) / (naturalHeight + naturalWidth)) * 100) / 100, + ); + }, onResize({ width, height }) { this.$emit('resize', { width, height }); }, |