Problem/Motivation

When multiple breakpoints were set, the JS iterator only processed the first one, breaking the logic for all other breakpoints. Additionally, the implementation seems overly complex.

Proposed resolution

Make it simple and fix the problem with multiple elements.

Issue fork sis-3517127

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    1 hidden branch
  • 3517127 Comparechanges, plain diff MR !1

Comments

stomusic created an issue. See original summary.

stomusic’s picture

Priority: Normal » Major
Status: Active » Needs review

Done, check please.

abhishek@kumar’s picture

Simplified Iterator Approach

(function (Drupal) {
  Drupal.behaviors.smartImagingStyles = {
    attach: function (context, settings) {
      // Process all picture elements
      const pictures = once('smart-imaging-styles', 'picture', context);
      
      pictures.forEach(picture => {
        // Process all source elements within each picture
        const sources = picture.querySelectorAll('source');
        
        sources.forEach(source => {
          // Your processing logic for each source
          const srcset = source.getAttribute('srcset');
          if (srcset) {
            // Apply transformations to each srcset
            const transformedSrcset = this.transformSrcset(srcset);
            source.setAttribute('srcset', transformedSrcset);
          }
        });
      });
    },
    
    transformSrcset: function(srcset) {
      // Your srcset transformation logic here
      return srcset; // Return modified srcset
    }
  };
})(Drupal);

  • sjerdo committed 3707a7b2 on 8.x-1.x
    [#3517127] fix: JS iterator works bad with picture that use multiple...

sjerdo’s picture

Status: Needs review » Fixed

Thanks! Committed and will create a new release

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.