mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
combine duplicate image uploader methods after merge
This commit is contained in:
parent
6aecbd6c6d
commit
7d7b35d069
@ -55,7 +55,6 @@ export default {
|
|||||||
file: null,
|
file: null,
|
||||||
showCropper: false,
|
showCropper: false,
|
||||||
isLoadingImage: false,
|
isLoadingImage: false,
|
||||||
imageAspectRatio: null,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -78,46 +77,29 @@ export default {
|
|||||||
imageElement.src = URL.createObjectURL(file)
|
imageElement.src = URL.createObjectURL(file)
|
||||||
this.cropper = new Cropper(imageElement, { zoomable: false, autoCropArea: 0.9 })
|
this.cropper = new Cropper(imageElement, { zoomable: false, autoCropArea: 0.9 })
|
||||||
},
|
},
|
||||||
|
deleteImage() {
|
||||||
|
this.clearImages()
|
||||||
|
},
|
||||||
cropImage() {
|
cropImage() {
|
||||||
this.isLoadingImage = true
|
this.isLoadingImage = true
|
||||||
|
if (this.file.type === 'image/jpeg') {
|
||||||
const canvas = this.cropper.getCroppedCanvas()
|
const canvas = this.cropper.getCroppedCanvas()
|
||||||
canvas.toBlob(blob => {
|
canvas.toBlob(blob => {
|
||||||
const imageAspectRatio = canvas.width / canvas.height
|
const imageAspectRatio = canvas.width / canvas.height
|
||||||
const croppedImageFile = new File([blob], this.file.name, { type: this.file.type })
|
const croppedImageFile = new File([blob], this.file.name, { type: this.file.type })
|
||||||
this.$emit('addTeaserImage', croppedImageFile)
|
this.$emit('addTeaserImage', croppedImageFile)
|
||||||
this.$emit('addImageAspectRatio', imageAspectRatio)
|
this.$emit('addImageAspectRatio', imageAspectRatio)
|
||||||
|
this.$emit('cropInProgress', false)
|
||||||
this.setupPreview(canvas.toDataURL())
|
this.setupPreview(canvas.toDataURL())
|
||||||
})
|
|
||||||
},
|
|
||||||
deleteImage() {
|
|
||||||
this.clearImages()
|
|
||||||
},
|
|
||||||
cropImage() {
|
|
||||||
this.showCropper = false
|
|
||||||
if (this.file.type === 'image/jpeg') {
|
|
||||||
this.uploadJpeg()
|
|
||||||
} else {
|
|
||||||
this.uploadOtherImageType()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
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')
|
}, 'image/jpeg')
|
||||||
|
} else {
|
||||||
|
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)
|
||||||
|
}
|
||||||
this.closeCropper()
|
this.closeCropper()
|
||||||
},
|
},
|
||||||
setupPreview(url) {
|
setupPreview(url) {
|
||||||
@ -129,20 +111,11 @@ export default {
|
|||||||
this.showCropper = false
|
this.showCropper = false
|
||||||
this.cropper.destroy()
|
this.cropper.destroy()
|
||||||
},
|
},
|
||||||
setupPreview() {
|
|
||||||
this.image.classList.add('thumbnail-preview')
|
|
||||||
this.thumbnailElement.appendChild(this.image)
|
|
||||||
},
|
|
||||||
cancelCrop() {
|
cancelCrop() {
|
||||||
if (this.oldImage) this.thumbnailElement.appendChild(this.oldImage)
|
if (this.oldImage) this.thumbnailElement.appendChild(this.oldImage)
|
||||||
this.showCropper = false
|
this.showCropper = false
|
||||||
this.$emit('cropInProgress', false)
|
this.$emit('cropInProgress', false)
|
||||||
},
|
},
|
||||||
emitImageData(imageFile) {
|
|
||||||
this.$emit('addTeaserImage', imageFile)
|
|
||||||
this.$emit('addImageAspectRatio', this.imageAspectRatio)
|
|
||||||
this.$emit('cropInProgress', false)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user