Fixes issue in uploader when one of the dimensions is auto

This commit is contained in:
Samuel Georges 2016-01-16 15:13:42 +11:00
parent d34350a7b1
commit 2855a4e344
1 changed files with 36 additions and 0 deletions

View File

@ -124,6 +124,8 @@
this.uploaderOptions.thumbnailHeight = this.options.thumbnailHeight
? this.options.thumbnailHeight : null
this.uploaderOptions.resize = this.onResizeFileInfo
/*
* Add CSRF token to headers
*/
@ -139,6 +141,40 @@
this.dropzone.on('error', this.proxy(this.onUploadError))
}
FileUpload.prototype.onResizeFileInfo = function(file) {
var info,
targetWidth,
targetHeight
if (!this.options.thumbnailWidth && !this.options.thumbnailWidth) {
targetWidth = targetHeight = 100
}
else if (this.options.thumbnailWidth) {
targetWidth = this.options.thumbnailWidth
targetHeight = this.options.thumbnailWidth * file.height / file.width
}
else if (this.options.thumbnailHeight) {
targetWidth = this.options.thumbnailHeight * file.height / file.width
targetHeight = this.options.thumbnailHeight
}
// drawImage(image, srcX, srcY, srcWidth, srcHeight, trgX, trgY, trgWidth, trgHeight) takes an image, clips it to
// the rectangle (srcX, srcY, srcWidth, srcHeight), scales it to dimensions (trgWidth, trgHeight), and draws it
// on the canvas at coordinates (trgX, trgY).
info = {
srcX: 0,
srcY: 0,
srcWidth: file.width,
srcHeight: file.height,
trgX: 0,
trgY: 0,
trgWidth: targetWidth,
trgHeight: targetHeight
}
return info
}
FileUpload.prototype.onUploadAddedFile = function(file) {
var $object = $(file.previewElement).data('dzFileObject', file)