-
Notifications
You must be signed in to change notification settings - Fork 301
Description
When the gallery stores the original image source, it checks both data-safe-src and src attributes:
- Reference: Code storing original src
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.
- Reference: Code restoring original src
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.