|
141 | 141 | }, |
142 | 142 |
|
143 | 143 | /** |
144 | | - * Subroutine for converting the file size into a string |
| 144 | + * Converting the file size into a string and update the row |
145 | 145 | * |
| 146 | + * @param int attach_id attach id from image |
146 | 147 | * @param int fileSize file size in byte |
147 | | - * |
148 | | - * @return string strFileSize file size as byte, KiB or MiB |
149 | 148 | */ |
150 | | - sizeToString: function(fileSize) { |
| 149 | + updateImgFileSize: function(attach_id, fileSize) { |
151 | 150 | let strFileSize = ''; |
152 | 151 |
|
153 | | - fileSize = parseInt(fileSize); |
| 152 | + if (isNaN(fileSize)) { |
| 153 | + return; |
| 154 | + } |
154 | 155 |
|
155 | 156 | if (fileSize < 1024) { |
156 | 157 | strFileSize = fileSize + ' {{ lang("BYTES_SHORT")|e("js") }}'; |
|
160 | 161 | strFileSize = Math.round(fileSize / 10485.76) / 100 + ' {{ lang("MIB")|e("js") }}'; |
161 | 162 | } |
162 | 163 |
|
163 | | - return(strFileSize); |
| 164 | + if (strFileSize) { |
| 165 | + $('.attach-row[data-attach-id="' + attach_id + '"] .file-size').html(strFileSize); |
| 166 | + } |
164 | 167 | }, |
165 | 168 |
|
166 | 169 | /** |
|
236 | 239 | '&form_token=' + $('input[name="form_token"]').val(); |
237 | 240 |
|
238 | 241 | let ajaxReq = $.ajax({ |
239 | | - // The url of the request |
240 | 242 | url: url, |
241 | | - |
242 | | - // The data to send |
243 | 243 | data: requestData, |
244 | | - |
245 | | - // Whether this is a POST or GET request |
246 | 244 | type: 'POST', |
247 | | - |
248 | | - // The type of data we expect back |
249 | 245 | dataType: "json", |
250 | | - |
251 | | - // Set a timeout (in milliseconds) for the request |
252 | 246 | timeout: 10000, |
253 | | - |
254 | | - // Code to run before the request is send |
255 | 247 | beforeSend: function(xhr, settings) { |
256 | 248 | $(button).find('>:first-child').attr('class', 'icon fa-refresh fa-spin fa-fw'); |
257 | 249 | $('.imcger-iupl-button button').prop('disabled', true).css('cursor','not-allowed'); |
|
269 | 261 | if (response.status < 3) { |
270 | 262 | imcger.imgUpload.updateAttId(response.oldAttachId, response.newAttachId); |
271 | 263 | imcger.imgUpload.image.imgOrientationValue[index] = 0; |
272 | | - |
273 | | - // Update row with new image size |
274 | | - if (response.fileSize) { |
275 | | - let strFileSize = imcger.imgUpload.image.sizeToString(response.fileSize); |
276 | | - |
277 | | - if (strFileSize) { |
278 | | - $('.attach-row[data-attach-id="' + response.newAttachId + '"] .file-size').html(strFileSize); |
279 | | - } |
280 | | - } |
| 264 | + imcger.imgUpload.image.updateImgFileSize(response.newAttachId, response.fileSize); |
281 | 265 |
|
282 | 266 | // Display a message when a warning occurs |
283 | 267 | if (response.message) { |
|
322 | 306 | }); |
323 | 307 |
|
324 | 308 | ajaxReq.done(function(response, status, xhr) { |
325 | | - let strFileSize = imcger.imgUpload.image.sizeToString(xhr.getResponseHeader('Content-Length')); |
326 | | - |
327 | | - if (strFileSize) { |
328 | | - $('.attach-row[data-attach-id="' + attach_id + '"] .file-size').html(strFileSize); |
329 | | - } |
| 309 | + imcger.imgUpload.image.updateImgFileSize(attach_id, xhr.getResponseHeader('Content-Length')); |
330 | 310 | }); |
331 | 311 | }, |
332 | 312 | } |
333 | 313 |
|
334 | 314 | /** |
335 | 315 | * Remove attachment in preview when insert as img BBcode in message |
336 | 316 | * AddOn for editor.js |
337 | | - * |
338 | | - * @var array notDisplayedAttachments Attachments that insert in the message |
339 | | - * @var bool notDisplayAttachmentBox Don't show any attachment |
340 | 317 | */ |
341 | 318 | imcger.imgUpload.showAttachImage = function() { |
| 319 | + // Attachments that insert in the message |
342 | 320 | const notDisplayedAttachments = {{ IUL_NOT_DISPLAYED_ATTACHMENTS }}, |
| 321 | + // If true don't show the attachment box |
343 | 322 | notDisplayAttachmentBox = {{ IUL_NOT_DISPLAY_ATTACHMENTBOX }}; |
344 | 323 |
|
345 | 324 | // Return when no attachments present |
|
449 | 428 | /** |
450 | 429 | * Update the relevant elements and hidden data for |
451 | 430 | * an attachment when page load. |
452 | | - * |
453 | | - * @param void |
454 | 431 | */ |
455 | 432 | imcger.imgUpload.updateRow = function() { |
456 | 433 | $('.file-name.ellipsis-text a').each(function() { |
|
513 | 490 | $('#img-' + attach_id).on('load', function(e) { |
514 | 491 | let imgHeight = maxImgHeight; |
515 | 492 |
|
516 | | - // The $(this) element work not all time |
517 | | - if (e.target.height < e.target.width) { |
| 493 | + // $(this).height() don't work all time |
| 494 | + if (e.target.height < maxImgHeight) { |
| 495 | + imgHeight = e.target.height; |
| 496 | + } else if (e.target.height < e.target.width) { |
518 | 497 | imgHeight = maxImgHeight / e.target.width * e.target.height; |
519 | 498 | } |
520 | 499 |
|
|
598 | 577 | $('#img-' + attach.attach_id).on('load', function(e) { |
599 | 578 | let imgHeight = maxImgHeight; |
600 | 579 |
|
601 | | - // The $(this) element work not all time |
602 | | - if (e.target.height < e.target.width) { |
| 580 | + // $(this).height() don't work all time |
| 581 | + if (e.target.height < maxImgHeight) { |
| 582 | + imgHeight = e.target.height; |
| 583 | + } else if (e.target.height < e.target.width) { |
603 | 584 | imgHeight = maxImgHeight / e.target.width * e.target.height; |
604 | 585 | } |
605 | 586 |
|
|
0 commit comments