Skip to content

Commit 1ba6108

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Remove jQuery class from the image diff (go-gitea#30140)
2 parents 6b9952d + 849eee8 commit 1ba6108

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

web_src/js/features/imagediff.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,40 @@ export function initImageDiff() {
110110
const $imagesAfter = imageInfos[0].$images;
111111
const $imagesBefore = imageInfos[1].$images;
112112

113-
initSideBySide(createContext($imagesAfter[0], $imagesBefore[0]));
113+
initSideBySide(this, createContext($imagesAfter[0], $imagesBefore[0]));
114114
if ($imagesAfter.length > 0 && $imagesBefore.length > 0) {
115115
initSwipe(createContext($imagesAfter[1], $imagesBefore[1]));
116116
initOverlay(createContext($imagesAfter[2], $imagesBefore[2]));
117117
}
118118

119-
$container.find('> .image-diff-tabs').removeClass('is-loading');
119+
this.querySelector(':scope > .image-diff-tabs')?.classList.remove('is-loading');
120120

121-
function initSideBySide(sizes) {
121+
function initSideBySide(container, sizes) {
122122
let factor = 1;
123123
if (sizes.max.width > (diffContainerWidth - 24) / 2) {
124124
factor = (diffContainerWidth - 24) / 2 / sizes.max.width;
125125
}
126126

127127
const widthChanged = sizes.$image1.length !== 0 && sizes.$image2.length !== 0 && sizes.$image1[0].naturalWidth !== sizes.$image2[0].naturalWidth;
128128
const heightChanged = sizes.$image1.length !== 0 && sizes.$image2.length !== 0 && sizes.$image1[0].naturalHeight !== sizes.$image2[0].naturalHeight;
129-
if (sizes.$image1.length !== 0) {
130-
$container.find('.bounds-info-after .bounds-info-width').text(`${sizes.$image1[0].naturalWidth}px`).addClass(widthChanged ? 'green' : '');
131-
$container.find('.bounds-info-after .bounds-info-height').text(`${sizes.$image1[0].naturalHeight}px`).addClass(heightChanged ? 'green' : '');
129+
if (sizes.$image1?.length) {
130+
const boundsInfoAfterWidth = container.querySelector('.bounds-info-after .bounds-info-width');
131+
boundsInfoAfterWidth.textContent = `${sizes.$image1[0].naturalWidth}px`;
132+
if (widthChanged) boundsInfoAfterWidth.classList.add('green');
133+
134+
const boundsInfoAfterHeight = container.querySelector('.bounds-info-after .bounds-info-height');
135+
boundsInfoAfterHeight.textContent = `${sizes.$image1[0].naturalHeight}px`;
136+
if (heightChanged) boundsInfoAfterHeight.classList.add('green');
132137
}
133-
if (sizes.$image2.length !== 0) {
134-
$container.find('.bounds-info-before .bounds-info-width').text(`${sizes.$image2[0].naturalWidth}px`).addClass(widthChanged ? 'red' : '');
135-
$container.find('.bounds-info-before .bounds-info-height').text(`${sizes.$image2[0].naturalHeight}px`).addClass(heightChanged ? 'red' : '');
138+
139+
if (sizes.$image2?.length) {
140+
const boundsInfoBeforeWidth = container.querySelector('.bounds-info-before .bounds-info-width');
141+
boundsInfoBeforeWidth.textContent = `${sizes.$image2[0].naturalWidth}px`;
142+
if (widthChanged) boundsInfoBeforeWidth.classList.add('red');
143+
144+
const boundsInfoBeforeHeight = container.querySelector('.bounds-info-before .bounds-info-height');
145+
boundsInfoBeforeHeight.textContent = `${sizes.$image2[0].naturalHeight}px`;
146+
if (heightChanged) boundsInfoBeforeHeight.classList.add('red');
136147
}
137148

138149
const image1 = sizes.$image1[0];

0 commit comments

Comments
 (0)