I installed the module on a fresh Drupal 10.1.4 version and I add the field format on a image field under Article content type. When check the content created, I get into console log the fallowing error:

Uncaught TypeError: $(...).once is not a function

After inspecting I see that the file triggering this error is "drupal.imagefieldzoom.js" having the fallowing code:

    $('.image-zoom-container img.original-image').each(function () {
        $(this).once('init').parent('.image-zoom').zoom({
          url: original_urls[$(this).attr('fid')],
          on: drupalSettings.imageFieldZoom.image_zoom_style,
          touch: drupalSettings.imageFieldZoom.image_touchscreen_compatible,
          magnify: drupalSettings.imageFieldZoom.image_magnify,
          duration: drupalSettings.imageFieldZoom.image_fade_duration
        });
      }

As far as I know due to this change record https://www.drupal.org/node/3158256 we need to remove jQuery dependency from the once feature in order to have this working.

Is there anyone working on this?
Thank you!

Comments

ioana apetri created an issue. See original summary.

sarwan_verma’s picture

Status: Active » Needs review
StatusFileSize
new796 bytes

Hi @ioana apetri,
I have fixed issue once function and also attached patch.
Please review and verify.

ioana apetri’s picture

Status: Needs review » Needs work

Quick fix:

My image is now zoomed in and out with the fallowing code in the "drupal.imagefieldzoom.js" file.

        $(once('init', this)). parent( '.image-zoom'). zoom({
            url: original_urls[$(this).attr('fid')],
            on: drupalSettings.imageFieldZoom.image_zoom_style,
            touch: drupalSettings.imageFieldZoom.image_touchscreen_compatible,
            magnify: drupalSettings.imageFieldZoom.image_magnify,
            duration: drupalSettings.imageFieldZoom.image_fade_duration
          });

Also I modified the dependencies library to be the fallowing:
- core/jquery
- core/drupal
- core/once
- core/drupalSettings

ioana apetri’s picture

I think also this part $(this).once('init') needs to be changed according the documentation.

sarwan_verma’s picture

Status: Needs work » Needs review
StatusFileSize
new1.22 KB

This is a updated patch.

ioana apetri’s picture

Status: Needs review » Needs work

In case JQuery is used, than we need to replase $ sign with JQuery word.If you want to use $ sign you have to use this:
(function ($, Drupal,once, drupalSettings) {

sarwan_verma’s picture

Status: Needs work » Needs review
StatusFileSize
new1.22 KB

This is a new updated patch.

nofue’s picture

Thanks for the patch #7, @sarwan_verma, works for me.