refactored tranformImage to remove dupication

- styled confirm button
- added locale translations
- added dropzoneDrop method to handle scenario where users drag and drop an image whilst in the cropper interface.

- co-authored-by: mattwr18 <mattwr18@gmail.com>
This commit is contained in:
Brent Vardy 2019-09-26 14:27:01 +01:00 committed by mattwr18
parent b089e82434
commit 227db5f13a
9 changed files with 48 additions and 32 deletions

View File

@ -7,6 +7,7 @@
:use-custom-slot="true"
@vdropzone-error="verror"
@vdropzone-thumbnail="transformImage"
@vdropzone-drop="dropzoneDrop"
>
<div class="dz-message">
<div
@ -76,44 +77,28 @@ export default {
this.$emit('addTeaserImage', file[0])
return ''
},
thumbnail: (file, dataUrl) => {
let thumbnailElement, contributionImage, uploadArea, thumbnailPreview, image
if (file.previewElement) {
thumbnailElement = document.querySelectorAll('#postdropzone')[0]
contributionImage = document.querySelectorAll('.contribution-image')[0]
thumbnailPreview = document.querySelectorAll('.thumbnail-preview')[0]
if (contributionImage) {
uploadArea = document.querySelectorAll('.hc-attachments-upload-area-update-post')[0]
uploadArea.removeChild(contributionImage)
uploadArea.classList.remove('hc-attachments-upload-area-update-post')
}
image = new Image()
image.src = dataUrl
image.classList.add('thumbnail-preview')
if (thumbnailPreview) return thumbnailElement.replaceChild(image, thumbnailPreview)
thumbnailElement.appendChild(image)
}
},
transformImage(file) {
let thumbnailElement, editor, confirm
let thumbnailElement, editor, confirm, thumbnailPreview, contributionImage
// Create the image editor overlay
editor = document.createElement('div')
thumbnailElement = document.querySelectorAll('.dz-image')[0]
// dataDzThumbnail = document.querySelectorAll('[data-dz-thumbnail-bg]')[0]
// thumbnailPreview = document.querySelectorAll('.thumbnail-preview')[0]
thumbnailPreview = document.querySelectorAll('.thumbnail-preview')[0]
if (thumbnailPreview) thumbnailPreview.remove()
contributionImage = document.querySelectorAll('.contribution-image')[0]
if (contributionImage) contributionImage.remove()
editor.classList.add('crop-overlay')
// elementToReplace = thumbnailPreview || dataDzThumbnail
thumbnailElement.appendChild(editor)
// Create the confirm button
confirm = document.createElement('button')
confirm.classList.add('crop-confirm')
confirm.textContent = 'Confirm'
confirm.classList.add('crop-confirm', 'ds-button', 'ds-button-primary')
confirm.textContent = this.$t('contribution.teaserImage.cropperConfirm')
confirm.addEventListener('click', () => {
// Get the canvas with image data from Cropper.js
let canvas = cropper.getCroppedCanvas()
this.thumbnail(file, canvas.toDataURL())
image = new Image()
image.src = canvas.toDataURL()
image.classList.add('thumbnail-preview')
thumbnailElement.appendChild(image)
// Remove the editor from view
editor.parentNode.removeChild(editor)
})
@ -123,12 +108,13 @@ export default {
let image = new Image()
image.src = URL.createObjectURL(file)
editor.appendChild(image)
// Append the editor to the page
// document.body.appendChild(editor)
// Create Cropper.js and pass image
let cropper = new Cropper(image, {})
},
dropzoneDrop() {
let cropOverlay = document.querySelectorAll('.crop-overlay')[0]
if (cropOverlay) cropOverlay.remove()
},
},
}
</script>

View File

@ -562,6 +562,9 @@
"it-internet-data-privacy": "IT, Internet & Datenschutz",
"art-culture-sport": "Kunst, Kultur & Sport"
}
},
"teaserImage": {
"cropperConfirm": "Bestätigen"
}
},
"code-of-conduct": {

View File

@ -563,6 +563,9 @@
"it-internet-data-privacy": "IT, Internet & Data Privacy",
"art-culture-sport": "Art, Culture, & Sport"
}
},
"teaserImage": {
"cropperConfirm": "Confirm"
}
},
"code-of-conduct": {

View File

@ -292,6 +292,11 @@
"message": "¿Realmente quieres liberar el comentario de \"<b>{name}</b>\"?"
}
},
"contribution": {
"teaserImage": {
"cropperConfirm": "Confirmar"
}
},
"user": {
"avatar": {
"submitted": "Carga con éxito"

View File

@ -287,6 +287,11 @@
"message": "Voulez-vous vraiment publier le commentaire de \"<b>{name}</b>\"?"
}
},
"contribution": {
"teaserImage": {
"cropperConfirm": "Confirmer"
}
},
"user": {
"avatar": {
"submitted": "Téléchargement réussi"

View File

@ -140,5 +140,10 @@
"save": "Salva",
"edit": "Modifica",
"delete": "Cancella"
},
"contribution": {
"teaserImage": {
"cropperConfirm": "Confermare"
}
}
}

View File

@ -158,7 +158,10 @@
},
"contribution": {
"edit": "Bijdrage bewerken",
"delete": "Bijdrage verwijderen"
"delete": "Bijdrage verwijderen",
"teaserImage": {
"cropperConfirm": "Bevestigen"
}
},
"comment": {
"edit": "Commentaar bewerken",

View File

@ -362,6 +362,9 @@
"languageSelectLabel": "Język",
"categories": {
"infoSelectedNoOfMaxCategories": "{chosen} z {max} wybrane kategorie"
},
"teaserImage": {
"cropperConfirm": "Potwierdzać"
}
}
}

View File

@ -203,7 +203,10 @@
},
"contribution": {
"edit": "Editar Contribuição",
"delete": "Apagar Contribuição"
"delete": "Apagar Contribuição",
"teaserImage": {
"cropperConfirm": "Confirmar"
}
},
"comment": {
"content": {