Skip to content

After gallery destroy, it doesn't restore the original image from data-safe-src #394

@saas786

Description

@saas786

When the gallery stores the original image source, it checks both data-safe-src and src attributes:

However, when restoring the image during destroy, it only considers the src attribute and not the data-safe-src. Since I'm using data-safe-src to store the original image source, this results in an empty src attribute after the gallery is destroyed.

Proposed Fix:

The issue arises from how the resetImgSrc method only handles the src attribute, ignoring data-safe-src if it was used to store the original image. A fix would involve updating the method to also check for data-safe-src.

Here are the relevant parts of the code:

Code Storing the Image Source:

JustifiedGallery.prototype.extractImgSrcFromImage = function ($image) {
  var imageSrc = $image.data('safe-src');
  var imageSrcLoc = 'data-safe-src';
  if (typeof imageSrc === 'undefined') {
    imageSrc = $image.attr('src');
    imageSrcLoc = 'src';
  }
  $image.data('jg.originalSrc', imageSrc); // stored for destroy method
  $image.data('jg.src', imageSrc); // changes over time
  $image.data('jg.originalSrcLoc', imageSrcLoc); // stored for destroy method
  return imageSrc;
};

Code Restoring the Image Source:

JustifiedGallery.prototype.resetImgSrc = function ($img) {
  if ($img.data('jg.originalSrcLoc') === 'src') {
    $img.attr('src', $img.data('jg.originalSrc'));
  } else {
    $img.attr('src', '');
  }
};

The resetImgSrc method should be updated to check and restore from data-safe-src if that’s where the original image was stored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions