File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
src/block-components/image Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ class ImageOptimizerPolyfill {
1212 init = ( ) => {
1313 const imgs = document . querySelectorAll ( '.stk-block img' )
1414
15+ let updateCount = 0
1516 // Use Mutation Observer because the src and/or srcset attributes may change if using dynamic content
1617 const MO = new MutationObserver ( mutations => {
1718 mutations . forEach ( mutation => {
@@ -33,12 +34,24 @@ class ImageOptimizerPolyfill {
3334 img . setAttribute ( 'srcset' , srcset )
3435 }
3536
37+ if ( img . getAttribute ( 'data-src' ) . indexOf ( '&fit' ) !== - 1 ) {
38+ const src = img . getAttribute ( 'data-src' )
39+ const index = src . indexOf ( '&fit' )
40+ const newSrc = src . slice ( 0 , index )
41+ img . setAttribute ( 'data-src' , newSrc )
42+ }
43+
3644 if ( img . getAttribute ( 'src' ) . indexOf ( '&fit' ) !== - 1 ) {
3745 const src = img . getAttribute ( 'src' )
3846 const index = src . indexOf ( '&fit' )
3947 const newSrc = src . slice ( 0 , index )
4048 img . setAttribute ( 'src' , newSrc )
4149 }
50+
51+ updateCount ++
52+ if ( updateCount === imgs . length ) {
53+ MO . disconnect ( )
54+ }
4255 } )
4356 } )
4457
You can’t perform that action at this time.
0 commit comments