@@ -110,29 +110,40 @@ export function initImageDiff() {
110
110
const $imagesAfter = imageInfos [ 0 ] . $images ;
111
111
const $imagesBefore = imageInfos [ 1 ] . $images ;
112
112
113
- initSideBySide ( createContext ( $imagesAfter [ 0 ] , $imagesBefore [ 0 ] ) ) ;
113
+ initSideBySide ( this , createContext ( $imagesAfter [ 0 ] , $imagesBefore [ 0 ] ) ) ;
114
114
if ( $imagesAfter . length > 0 && $imagesBefore . length > 0 ) {
115
115
initSwipe ( createContext ( $imagesAfter [ 1 ] , $imagesBefore [ 1 ] ) ) ;
116
116
initOverlay ( createContext ( $imagesAfter [ 2 ] , $imagesBefore [ 2 ] ) ) ;
117
117
}
118
118
119
- $container . find ( ' > .image-diff-tabs') . removeClass ( 'is-loading' ) ;
119
+ this . querySelector ( ':scope > .image-diff-tabs') ?. classList . remove ( 'is-loading' ) ;
120
120
121
- function initSideBySide ( sizes ) {
121
+ function initSideBySide ( container , sizes ) {
122
122
let factor = 1 ;
123
123
if ( sizes . max . width > ( diffContainerWidth - 24 ) / 2 ) {
124
124
factor = ( diffContainerWidth - 24 ) / 2 / sizes . max . width ;
125
125
}
126
126
127
127
const widthChanged = sizes . $image1 . length !== 0 && sizes . $image2 . length !== 0 && sizes . $image1 [ 0 ] . naturalWidth !== sizes . $image2 [ 0 ] . naturalWidth ;
128
128
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' ) ;
132
137
}
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' ) ;
136
147
}
137
148
138
149
const image1 = sizes . $image1 [ 0 ] ;
0 commit comments