Commit 6b48e2eb authored by Jonny Bradley's avatar Jonny Bradley

[REF] files: Reformat disturbingly badly formatted JavaScript

parent 33e77ea8
Pipeline #50337913 failed with stages
in 29 minutes and 15 seconds
...@@ -188,60 +188,59 @@ ...@@ -188,60 +188,59 @@
sendData.data.append('image_max_size_x', image_max_size_x); sendData.data.append('image_max_size_x', image_max_size_x);
sendData.data.append('image_max_size_y', image_max_size_y); sendData.data.append('image_max_size_y', image_max_size_y);
sendData.data.append('ticket', ticket); sendData.data.append('ticket', ticket);
sendData.data.append('name',file.name); sendData.data.append('name', file.name);
var waiting=false; var waiting = false;
//checking if image is uploaded to call resize function and resizing options are set by tracker field creator //checking if image is uploaded to call resize function and resizing options are set by tracker
if(file.type.substring(0,6) == 'image/' && (image_max_size_x!='' || image_max_size_y!='')) { // field creator
waiting=true; if (file.type.substring(0, 6) == 'image/' && (image_max_size_x || image_max_size_y)) {
waiting = true;
var imageData; var imageData;
var picFile = e.target; var picFile = e.target;
imageData = picFile.result; imageData = picFile.result;
var img = new Image(); var img = new Image();
var blobImage=null; var blobImage = null;
img.src=imageData; img.src = imageData;
img.onload = function(){ img.onload = function () {
var width = parseInt(image_max_size_x); var width = parseInt(image_max_size_x);
var height = parseInt(image_max_size_y); var height = parseInt(image_max_size_y);
var image_x = parseInt(image_max_size_x); var image_x = parseInt(image_max_size_x);
var image_y = parseInt(image_max_size_y); var image_y = parseInt(image_max_size_y);
var ratio; var ratio;
if (img.width > image_x || img.height > image_y) { if (img.width > image_x || img.height > image_y) {
if (img.width > image_x) { if (img.width > image_x) {
width = image_x; width = image_x;
ratio = image_x / img.width; ratio = image_x / img.width;
height = Math.round(img.height * ratio); height = Math.round(img.height * ratio);
} }
if (height >image_y) { if (height > image_y) {
height =image_y; height = image_y;
ratio = image_y / img.height; ratio = image_y / img.height;
width = Math.round(img.width * ratio); width = Math.round(img.width * ratio);
} }
} } else {
else width = img.width;
{ height = img.height;
width=img.width; }
height=img.height; var canvas = $("<canvas/>").get(0);
} canvas.width = width;
var canvas = $("<canvas/>").get(0); canvas.height = height;
canvas.width = width; var context = canvas.getContext('2d');
canvas.height = height; context.drawImage(img, 0, 0, width, height);
var context = canvas.getContext('2d'); var resizedImage = restoreExif(imageData, canvas.toDataURL('image/jpeg'));
context.drawImage(img, 0, 0, width, height); blobImage = dataURItoBlob(resizedImage);
var resizedImage = restoreExif(imageData, canvas.toDataURL('image/jpeg')); sendData.data.append('data', blobImage, file.name);
blobImage = dataURItoBlob(resizedImage); $.ajax(sendData);
sendData.data.append('data',blobImage,file.name); }
$.ajax(sendData);
} } else {
sendData.data.append('data', file);
} }
else
sendData.data.append('data', file);
} else { } else {
data = e.target.result; data = e.target.result;
sendData.data = { sendData.data = {
...@@ -250,19 +249,21 @@ ...@@ -250,19 +249,21 @@
type: file.type, type: file.type,
data: data.substr(data.indexOf('base64') + 7), data: data.substr(data.indexOf('base64') + 7),
galleryId: galleryId, galleryId: galleryId,
image_max_size_x:image_max_size_x, image_max_size_x: image_max_size_x,
image_max_size_y:image_max_size_y image_max_size_y: image_max_size_y
}; };
} }
if (accept) { if (accept) {
valid = file.type.match(new RegExp( ".?(" + accept.replace('*', '.*') + ")$", "i")); valid = file.type.match(new RegExp(".?(" + accept.replace('*', '.*') + ")$", "i"));
} }
if (valid && !waiting) { if (valid && !waiting) {
$.ajax(sendData); $.ajax(sendData);
} else if(!valid) { } else {
sendData.error(null); if (!valid) {
sendData.error(null);
}
} }
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment