@@ -133,24 +133,25 @@ export function initImageDiff() {
133
133
$container . find ( '.bounds-info-before .bounds-info-height' ) . text ( `${ sizes . image2 [ 0 ] . naturalHeight } px` ) . addClass ( heightChanged ? 'red' : '' ) ;
134
134
}
135
135
136
- sizes . image1 . css ( {
137
- width : sizes . size1 . width * factor ,
138
- height : sizes . size1 . height * factor
139
- } ) ;
140
- sizes . image1 . parent ( ) . css ( {
141
- margin : `10px auto` ,
142
- width : sizes . size1 . width * factor + 2 ,
143
- height : sizes . size1 . height * factor + 2
144
- } ) ;
145
- sizes . image2 . css ( {
146
- width : sizes . size2 . width * factor ,
147
- height : sizes . size2 . height * factor
148
- } ) ;
149
- sizes . image2 . parent ( ) . css ( {
150
- margin : `10px auto` ,
151
- width : sizes . size2 . width * factor + 2 ,
152
- height : sizes . size2 . height * factor + 2
153
- } ) ;
136
+ const image1 = sizes . image1 [ 0 ] ;
137
+ if ( image1 ) {
138
+ const container = image1 . parentNode ;
139
+ image1 . style . width = `${ sizes . size1 . width * factor } px` ;
140
+ image1 . style . height = `${ sizes . size1 . height * factor } px` ;
141
+ container . style . margin = '10px auto' ;
142
+ container . style . width = `${ sizes . size1 . width * factor + 2 } px` ;
143
+ container . style . height = `${ sizes . size1 . height * factor + 2 } px` ;
144
+ }
145
+
146
+ const image2 = sizes . image2 [ 0 ] ;
147
+ if ( image2 ) {
148
+ const container = image2 . parentNode ;
149
+ image2 . style . width = `${ sizes . size2 . width * factor } px` ;
150
+ image2 . style . height = `${ sizes . size2 . height * factor } px` ;
151
+ container . style . margin = '10px auto' ;
152
+ container . style . width = `${ sizes . size2 . width * factor + 2 } px` ;
153
+ container . style . height = `${ sizes . size2 . height * factor + 2 } px` ;
154
+ }
154
155
}
155
156
156
157
function initSwipe ( sizes ) {
@@ -159,36 +160,39 @@ export function initImageDiff() {
159
160
factor = ( diffContainerWidth - 12 ) / sizes . max . width ;
160
161
}
161
162
162
- sizes . image1 . css ( {
163
- width : sizes . size1 . width * factor ,
164
- height : sizes . size1 . height * factor
165
- } ) ;
166
- sizes . image1 . parent ( ) . css ( {
167
- margin : `0px ${ sizes . ratio [ 0 ] * factor } px` ,
168
- width : sizes . size1 . width * factor + 2 ,
169
- height : sizes . size1 . height * factor + 2
170
- } ) ;
171
- sizes . image1 . parent ( ) . parent ( ) . css ( {
172
- padding : `${ sizes . ratio [ 1 ] * factor } px 0 0 0` ,
173
- width : sizes . max . width * factor + 2
174
- } ) ;
175
- sizes . image2 . css ( {
176
- width : sizes . size2 . width * factor ,
177
- height : sizes . size2 . height * factor
178
- } ) ;
179
- sizes . image2 . parent ( ) . css ( {
180
- margin : `${ sizes . ratio [ 3 ] * factor } px ${ sizes . ratio [ 2 ] * factor } px` ,
181
- width : sizes . size2 . width * factor + 2 ,
182
- height : sizes . size2 . height * factor + 2
183
- } ) ;
184
- sizes . image2 . parent ( ) . parent ( ) . css ( {
185
- width : sizes . max . width * factor + 2 ,
186
- height : sizes . max . height * factor + 2
187
- } ) ;
188
- $container . find ( '.diff-swipe' ) . css ( {
189
- width : sizes . max . width * factor + 2 ,
190
- height : sizes . max . height * factor + 30 /* extra height for inner "position: absolute" elements */ ,
191
- } ) ;
163
+ const image1 = sizes . image1 [ 0 ] ;
164
+ if ( image1 ) {
165
+ const container = image1 . parentNode ;
166
+ const swipeFrame = container . parentNode ;
167
+ image1 . style . width = `${ sizes . size1 . width * factor } px` ;
168
+ image1 . style . height = `${ sizes . size1 . height * factor } px` ;
169
+ container . style . margin = `0px ${ sizes . ratio [ 0 ] * factor } px` ;
170
+ container . style . width = `${ sizes . size1 . width * factor + 2 } px` ;
171
+ container . style . height = `${ sizes . size1 . height * factor + 2 } px` ;
172
+ swipeFrame . style . padding = `${ sizes . ratio [ 1 ] * factor } px 0 0 0` ;
173
+ swipeFrame . style . width = `${ sizes . max . width * factor + 2 } px` ;
174
+ }
175
+
176
+ const image2 = sizes . image2 [ 0 ] ;
177
+ if ( image2 ) {
178
+ const container = image2 . parentNode ;
179
+ const swipeFrame = container . parentNode ;
180
+ image2 . style . width = `${ sizes . size2 . width * factor } px` ;
181
+ image2 . style . height = `${ sizes . size2 . height * factor } px` ;
182
+ container . style . margin = `${ sizes . ratio [ 3 ] * factor } px ${ sizes . ratio [ 2 ] * factor } px` ;
183
+ container . style . width = `${ sizes . size2 . width * factor + 2 } px` ;
184
+ container . style . height = `${ sizes . size2 . height * factor + 2 } px` ;
185
+ swipeFrame . style . width = `${ sizes . max . width * factor + 2 } px` ;
186
+ swipeFrame . style . height = `${ sizes . max . height * factor + 2 } px` ;
187
+ }
188
+
189
+ // extra height for inner "position: absolute" elements
190
+ const swipe = $container . find ( '.diff-swipe' ) [ 0 ] ;
191
+ if ( swipe ) {
192
+ swipe . style . width = `${ sizes . max . width * factor + 2 } px` ;
193
+ swipe . style . height = `${ sizes . max . height * factor + 30 } px` ;
194
+ }
195
+
192
196
$container . find ( '.swipe-bar' ) . on ( 'mousedown' , function ( e ) {
193
197
e . preventDefault ( ) ;
194
198
@@ -200,13 +204,9 @@ export function initImageDiff() {
200
204
e2 . preventDefault ( ) ;
201
205
202
206
const value = Math . max ( 0 , Math . min ( e2 . clientX - $swipeFrame . offset ( ) . left , width ) ) ;
207
+ $swipeBar [ 0 ] . style . left = `${ value } px` ;
208
+ $container . find ( '.swipe-container' ) [ 0 ] . style . width = `${ $swipeFrame . width ( ) - value } px` ;
203
209
204
- $swipeBar . css ( {
205
- left : value
206
- } ) ;
207
- $container . find ( '.swipe-container' ) . css ( {
208
- width : $swipeFrame . width ( ) - value
209
- } ) ;
210
210
$ ( document ) . on ( 'mouseup.diff-swipe' , ( ) => {
211
211
$ ( document ) . off ( '.diff-swipe' ) ;
212
212
} ) ;
0 commit comments