Skip to content

Commit f7f53ca

Browse files
committed
Added change filesize after upload or rotated
1 parent d626e2e commit f7f53ca

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

imcger/imgupload/styles/all/template/event/overall_footer_body_after.html

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script>
1111

1212
/**
13-
* imcger object for pphpBB.
13+
* @var imcger object for pphpBB.
1414
*/
1515
if (typeof imcger != 'object') {
1616
var imcger = {};
@@ -20,7 +20,9 @@
2020

2121
'use strict';
2222

23-
// imcger object for pphpBB extension Image upload use ImageMagick
23+
/**
24+
* @var imgUpload object for pphpBB extension Image upload use ImageMagick
25+
*/
2426
imcger.imgUpload = {};
2527

2628
/**
@@ -238,6 +240,7 @@
238240
if (json.status < 3) {
239241
imcger.imgUpload.updateAttId(json.oldAttachId, json.newAttachId);
240242
imcger.imgUpload.image.imgOrientationValue[index] = 0;
243+
imcger.imgUpload.image.setImgSize(json.newAttachId);
241244

242245
// Display a message when a warning occurs
243246
if (json.message) {
@@ -261,6 +264,41 @@
261264
$(button).find('>:first-child').attr('class', 'icon fa-save fa-fw');
262265
$('.imcger-iupl-button button').prop('disabled', false).css('cursor','pointer');
263266
});
267+
},
268+
269+
/**
270+
* Send a request to the Server to get the image filesize
271+
* and update the row with it
272+
*
273+
* @param int attach_id attach id from attach image
274+
*/
275+
setImgSize: function(attach_id) {
276+
let imgURL = $('#img-' + attach_id).attr('src').replace('&t=1', ''),
277+
ajaxReq = $.ajax({
278+
url: imgURL,
279+
data: null,
280+
async: false,
281+
type: 'HEAD',
282+
dataType: "json",
283+
timeout: 5000,
284+
});
285+
286+
ajaxReq.done(function(json) {
287+
let fileSize = ajaxReq.getResponseHeader('Content-Length'),
288+
strFileSize = '';
289+
290+
if (fileSize < 1024) {
291+
strFileSize = fileSize + ' {{ lang("BYTES_SHORT")|e("js") }}';
292+
} else if (fileSize < 1048576) {
293+
strFileSize = Math.round(fileSize / 10.24) / 100 + ' {{ lang("KIB")|e("js") }}';
294+
} else {
295+
strFileSize = Math.round(fileSize / 10485.76) / 100 + ' {{ lang("MIB")|e("js") }}';
296+
}
297+
298+
if (strFileSize) {
299+
$('.attach-row[data-attach-id="' + attach_id + '"] .file-size').html(strFileSize);
300+
}
301+
});
264302
}
265303
}
266304

@@ -535,6 +573,8 @@
535573
}
536574

537575
$(this).css('margin-top', ((maxImgHeight - parseInt(imgHeight)) / 2));
576+
577+
imcger.imgUpload.image.setImgSize(attach.attach_id);
538578
});
539579
} else {
540580
$link.attr('href', url).html(attach.real_filename);

0 commit comments

Comments
 (0)