Skip to content

Commit cd0c694

Browse files
committed
v1.2.0-beta2
Fixed Do not resize if naturalWidth is greater than maxImageWidth and less than postbodyWidth
1 parent 4d1a61b commit cd0c694

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@
217217
*/
218218
const imcgerImgUpload = {
219219
initialImage: function() {
220+
const maxImageWidth = '{{ IUL_IMG_MAXWIDTH }}';
221+
220222
// Return if no content is displayed
221223
if (!document.getElementsByClassName("content").length) {
222224
return;
@@ -226,9 +228,9 @@
226228
postbodyWidth = window.getComputedStyle(document.getElementsByClassName("content")[0]).width;
227229

228230
postImageArray.forEach((image) => {
229-
if (parseInt(image.naturalWidth) > parseInt(postbodyWidth)) {
231+
if (parseInt(image.naturalWidth) > parseInt(postbodyWidth) || parseInt(image.naturalWidth) > parseInt(maxImageWidth)) {
230232
image.style.width = '100%';
231-
image.style.maxWidth = '{{ IUL_IMG_MAXWIDTH }}';
233+
image.style.maxWidth = maxImageWidth;
232234
} else {
233235
image.style.width = 'auto';
234236
image.style.maxWidth = 'none';
@@ -242,10 +244,12 @@
242244
let postImageArray = document.querySelectorAll(".content img.postimage");
243245
postImageArray.forEach((image) => {
244246
image.onload = (event) => {
245-
let postbodyWidth = window.getComputedStyle(document.getElementsByClassName("content")[0]).width;
246-
if (parseInt(image.naturalWidth) > parseInt(postbodyWidth)) {
247+
const maxImageWidth = '{{ IUL_IMG_MAXWIDTH }}';
248+
let postbodyWidth = window.getComputedStyle(document.getElementsByClassName("content")[0]).width;
249+
250+
if (parseInt(image.naturalWidth) > parseInt(postbodyWidth) || parseInt(image.naturalWidth) > parseInt(maxImageWidth)) {
247251
image.style.width = '100%';
248-
image.style.maxWidth = '{{ IUL_IMG_MAXWIDTH }}';
252+
image.style.maxWidth = maxImageWidth;
249253
} else {
250254
image.style.width = 'auto';
251255
image.style.maxWidth = 'none';

0 commit comments

Comments
 (0)