Archived
Uncomment minify images function to get a working image upload.
References #137
This commit is contained in:
@@ -1295,66 +1295,66 @@ $(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// minify images before upload, approach taken from https://github.com/joelvardy/javascript-image-upload/
|
// minify images before upload, approach taken from https://github.com/joelvardy/javascript-image-upload/
|
||||||
if ($('#uploadform').length > 0) {
|
// if ($('#uploadform').length > 0) {
|
||||||
$('#uploadform').submit(function(event) {
|
// $('#uploadform').submit(function(event) {
|
||||||
event.preventDefault();
|
// event.preventDefault();
|
||||||
$('.uploadform_userfile').each(function() {
|
// $('.uploadform_userfile').each(function() {
|
||||||
var files = this.files;
|
// var files = this.files;
|
||||||
for (var i = 0; i < files.length; i++) {
|
// for (var i = 0; i < files.length; i++) {
|
||||||
var reader = new FileReader();
|
// var reader = new FileReader();
|
||||||
var file = files[i];
|
// var file = files[i];
|
||||||
reader.onload = function(readerEvent) {
|
// reader.onload = function(readerEvent) {
|
||||||
var image = new Image();
|
// var image = new Image();
|
||||||
image.onload = function (imageEvent) {
|
// image.onload = function (imageEvent) {
|
||||||
// Resize image
|
// // Resize image
|
||||||
var canvas = document.createElement('canvas'),
|
// var canvas = document.createElement('canvas'),
|
||||||
max_size = 1200,
|
// max_size = 1200,
|
||||||
width = image.width,
|
// width = image.width,
|
||||||
height = image.height;
|
// height = image.height;
|
||||||
if (width > height) {
|
// if (width > height) {
|
||||||
if (width > max_size) {
|
// if (width > max_size) {
|
||||||
height *= max_size / width;
|
// height *= max_size / width;
|
||||||
width = max_size;
|
// width = max_size;
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if (height > max_size) {
|
// if (height > max_size) {
|
||||||
width *= max_size / height;
|
// width *= max_size / height;
|
||||||
height = max_size;
|
// height = max_size;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
canvas.width = width;
|
// canvas.width = width;
|
||||||
canvas.height = height;
|
// canvas.height = height;
|
||||||
canvas.getContext('2d').drawImage(image, 0, 0, width, height);
|
// canvas.getContext('2d').drawImage(image, 0, 0, width, height);
|
||||||
var data = new FormData();
|
// var data = new FormData();
|
||||||
data.append('serendipity[action]', 'admin');
|
// data.append('serendipity[action]', 'admin');
|
||||||
data.append('serendipity[adminModule]', 'media');
|
// data.append('serendipity[adminModule]', 'media');
|
||||||
data.append('serendipity[adminAction]', 'add');
|
// data.append('serendipity[adminAction]', 'add');
|
||||||
data.append('serendipity[token]', $('input[name*="serendipity[token]"]').val());
|
// data.append('serendipity[token]', $('input[name*="serendipity[token]"]').val());
|
||||||
data.append('serendipity[target_filename][1]', file.name);
|
// data.append('serendipity[target_filename][1]', file.name);
|
||||||
canvas.toBlob(function(blob) {
|
// canvas.toBlob(function(blob) {
|
||||||
data.append('serendipity[userfile][1]', blob, file.name);
|
// data.append('serendipity[userfile][1]', blob, file.name);
|
||||||
var jqxhr = $.ajax({
|
// var jqxhr = $.ajax({
|
||||||
type: 'post',
|
// type: 'post',
|
||||||
url: $('#uploadform').attr('action'),
|
// url: $('#uploadform').attr('action'),
|
||||||
data: data,
|
// data: data,
|
||||||
cache: false,
|
// cache: false,
|
||||||
processData: false,
|
// processData: false,
|
||||||
contentType: false
|
// contentType: false
|
||||||
}).done(function(data) {
|
// }).done(function(data) {
|
||||||
alert('success');
|
// alert('success');
|
||||||
}).fail(function(data) {
|
// }).fail(function(data) {
|
||||||
alert("fail:" + data.statusText);
|
// alert("fail:" + data.statusText);
|
||||||
});
|
// });
|
||||||
|
|
||||||
}, file.type);
|
// }, file.type);
|
||||||
}
|
// }
|
||||||
image.src = readerEvent.target.result;
|
// image.src = readerEvent.target.result;
|
||||||
}
|
// }
|
||||||
reader.readAsDataURL(file);
|
// reader.readAsDataURL(file);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
// reopen detail element after spamblock action
|
// reopen detail element after spamblock action
|
||||||
if ($('#serendipity_comments_list').length > 0 && window.location.hash && $('#' + window.location.hash.replace('#', '')).length > 0) {
|
if ($('#serendipity_comments_list').length > 0 && window.location.hash && $('#' + window.location.hash.replace('#', '')).length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user