|
10 | 10 | <script>
|
11 | 11 |
|
12 | 12 | /**
|
13 |
| - * imcger object for pphpBB. |
| 13 | + * @var imcger object for pphpBB. |
14 | 14 | */
|
15 | 15 | if (typeof imcger != 'object') {
|
16 | 16 | var imcger = {};
|
|
20 | 20 |
|
21 | 21 | 'use strict';
|
22 | 22 |
|
23 |
| - // imcger object for pphpBB extension Image upload use ImageMagick |
| 23 | + /** |
| 24 | + * @var imgUpload object for pphpBB extension Image upload use ImageMagick |
| 25 | + */ |
24 | 26 | imcger.imgUpload = {};
|
25 | 27 |
|
26 | 28 | /**
|
|
238 | 240 | if (json.status < 3) {
|
239 | 241 | imcger.imgUpload.updateAttId(json.oldAttachId, json.newAttachId);
|
240 | 242 | imcger.imgUpload.image.imgOrientationValue[index] = 0;
|
| 243 | + imcger.imgUpload.image.setImgSize(json.newAttachId); |
241 | 244 |
|
242 | 245 | // Display a message when a warning occurs
|
243 | 246 | if (json.message) {
|
|
261 | 264 | $(button).find('>:first-child').attr('class', 'icon fa-save fa-fw');
|
262 | 265 | $('.imcger-iupl-button button').prop('disabled', false).css('cursor','pointer');
|
263 | 266 | });
|
| 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 | + }); |
264 | 302 | }
|
265 | 303 | }
|
266 | 304 |
|
|
535 | 573 | }
|
536 | 574 |
|
537 | 575 | $(this).css('margin-top', ((maxImgHeight - parseInt(imgHeight)) / 2));
|
| 576 | + |
| 577 | + imcger.imgUpload.image.setImgSize(attach.attach_id); |
538 | 578 | });
|
539 | 579 | } else {
|
540 | 580 | $link.attr('href', url).html(attach.real_filename);
|
|
0 commit comments