From 7d7b35d069c61504d40da884b260d6d30180f424 Mon Sep 17 00:00:00 2001 From: Alina Beck Date: Wed, 19 Feb 2020 10:46:27 +0100 Subject: [PATCH] combine duplicate image uploader methods after merge --- webapp/components/TeaserImage/TeaserImage.vue | 59 +++++-------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/webapp/components/TeaserImage/TeaserImage.vue b/webapp/components/TeaserImage/TeaserImage.vue index 90c23dc93..1899a39c7 100644 --- a/webapp/components/TeaserImage/TeaserImage.vue +++ b/webapp/components/TeaserImage/TeaserImage.vue @@ -55,7 +55,6 @@ export default { file: null, showCropper: false, isLoadingImage: false, - imageAspectRatio: null, } }, methods: { @@ -78,46 +77,29 @@ export default { imageElement.src = URL.createObjectURL(file) this.cropper = new Cropper(imageElement, { zoomable: false, autoCropArea: 0.9 }) }, - cropImage() { - this.isLoadingImage = true - const canvas = this.cropper.getCroppedCanvas() - canvas.toBlob(blob => { - const imageAspectRatio = canvas.width / canvas.height - const croppedImageFile = new File([blob], this.file.name, { type: this.file.type }) - this.$emit('addTeaserImage', croppedImageFile) - this.$emit('addImageAspectRatio', imageAspectRatio) - this.setupPreview(canvas.toDataURL()) - }) - }, deleteImage() { this.clearImages() }, cropImage() { - this.showCropper = false + this.isLoadingImage = true if (this.file.type === 'image/jpeg') { - this.uploadJpeg() + const canvas = this.cropper.getCroppedCanvas() + canvas.toBlob(blob => { + const imageAspectRatio = canvas.width / canvas.height + const croppedImageFile = new File([blob], this.file.name, { type: this.file.type }) + this.$emit('addTeaserImage', croppedImageFile) + this.$emit('addImageAspectRatio', imageAspectRatio) + this.$emit('cropInProgress', false) + this.setupPreview(canvas.toDataURL()) + }, 'image/jpeg') } else { - this.uploadOtherImageType() + const imageAspectRatio = this.file.width / this.file.height || 1.0 + const croppedImageFile = this.file + this.setupPreview(this.file.dataURL) + this.$emit('addTeaserImage', croppedImageFile) + this.$emit('addImageAspectRatio', imageAspectRatio) + this.$emit('cropInProgress', false) } - }, - uploadOtherImageType() { - this.imageAspectRatio = this.file.width / this.file.height || 1.0 - this.image = new Image() - this.image.src = this.file.dataURL - this.setupPreview() - this.emitImageData(this.file) - }, - uploadJpeg() { - const canvas = this.cropper.getCroppedCanvas() - canvas.toBlob(blob => { - this.imageAspectRatio = canvas.width / canvas.height - this.image = new Image() - this.image.src = canvas.toDataURL() - this.setupPreview() - const croppedImageFile = new File([blob], this.file.name, { type: this.file.type }) - this.emitImageData(croppedImageFile) - }, 'image/jpeg') - this.closeCropper() }, setupPreview(url) { @@ -129,20 +111,11 @@ export default { this.showCropper = false this.cropper.destroy() }, - setupPreview() { - this.image.classList.add('thumbnail-preview') - this.thumbnailElement.appendChild(this.image) - }, cancelCrop() { if (this.oldImage) this.thumbnailElement.appendChild(this.oldImage) this.showCropper = false this.$emit('cropInProgress', false) }, - emitImageData(imageFile) { - this.$emit('addTeaserImage', imageFile) - this.$emit('addImageAspectRatio', this.imageAspectRatio) - this.$emit('cropInProgress', false) - }, }, }