Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saas786 opened this issue Oct 12, 2024 · 0 comments

Comments

@saas786
Copy link

saas786 commented Oct 12, 2024

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.

saas786 added a commit to saas786/Justified-Gallery that referenced this issue Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant