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

thumbnailPath function can now signal to revert to default functionality #363

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dist/css/justifiedGallery.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* justifiedGallery - v3.8.1
* http://miromannino.github.io/Justified-Gallery/
* Copyright (c) 2020 Miro Mannino
/*
* Justified Gallery - v3.9.0-645d8e1
* http://miromannino.com/projects/justified-gallery/
* Copyright (c) 2019 Miro Mannino
* Licensed under the MIT license.
*/
.justified-gallery {
Expand Down
8 changes: 4 additions & 4 deletions dist/css/justifiedGallery.min.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* justifiedGallery - v3.8.1
* http://miromannino.github.io/Justified-Gallery/
* Copyright (c) 2020 Miro Mannino
/*
* Justified Gallery - v3.9.0-645d8e1
* http://miromannino.com/projects/justified-gallery/
* Copyright (c) 2019 Miro Mannino
* Licensed under the MIT license.
*/
.justified-gallery {
Expand Down
25 changes: 15 additions & 10 deletions dist/js/jquery.justifiedGallery.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* justifiedGallery - v3.8.1
* justifiedGallery - v3.9.0-645d8e1
* http://miromannino.github.io/Justified-Gallery/
* Copyright (c) 2020 Miro Mannino
* Copyright (c) 2022 Miro Mannino
* Licensed under the MIT license.
*/
(function (factory) {
Expand Down Expand Up @@ -127,16 +127,20 @@
* @returns {String} the suffix to use
*/
JustifiedGallery.prototype.newSrc = function (imageSrc, imgWidth, imgHeight, image) {
var newImageSrc;
var newImageSrc = null;

if (this.settings.thumbnailPath) {
newImageSrc = this.settings.thumbnailPath(imageSrc, imgWidth, imgHeight, image);
} else {
}

if (newImageSrc == null) {

var matchRes = imageSrc.match(this.settings.extension);
var ext = (matchRes !== null) ? matchRes[0] : '';
newImageSrc = imageSrc.replace(this.settings.extension, '');
newImageSrc = this.removeSuffix(newImageSrc, this.getUsedSuffix(newImageSrc));
newImageSrc += this.getSuffix(imgWidth, imgHeight) + ext;

}

return newImageSrc;
Expand Down Expand Up @@ -217,11 +221,12 @@
var imageSrc = $image.data('jg.src');
if (imageSrc) {
imageSrc = this.newSrc(imageSrc, imgWidth, imgHeight, $image[0]);


var self = this;
$image.one('error', function () {
this.resetImgSrc($image); //revert to the original thumbnail
self.resetImgSrc($image); //revert to the original thumbnail
});

var loadNewImage = function () {
// if (imageSrc !== newImageSrc) {
$image.attr('src', imageSrc);
Expand Down Expand Up @@ -658,7 +663,7 @@
this.insertToGallery(a);
return a;
};

/**
* Sort the array using settings.comparator as comparator
*
Expand All @@ -670,7 +675,7 @@
this.insertToGallery(a);
return a;
};

/**
* Reset the filters removing the 'jg-filtered' class from all the entries
*
Expand Down
6 changes: 3 additions & 3 deletions dist/js/jquery.justifiedGallery.min.js

Large diffs are not rendered by default.

Binary file modified dist/justifiedGallery.min.zip
Binary file not shown.
Binary file modified dist/justifiedGallery.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion src/js/jquery.justifiedGallery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Justified Gallery - v3.8.1
* Justified Gallery - v3.9.0-645d8e1
* http://miromannino.github.io/Justified-Gallery/
*
* Copyright (c) 2019 Miro Mannino
Expand Down
13 changes: 9 additions & 4 deletions src/js/justifiedGallery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Justified Gallery - v3.8.1
* Justified Gallery - v3.9.0-645d8e1
* http://miromannino.github.io/Justified-Gallery/
*
* Copyright (c) 2019 Miro Mannino
Expand Down Expand Up @@ -101,16 +101,20 @@ JustifiedGallery.prototype.getUsedSuffix = function (str) {
* @returns {String} the suffix to use
*/
JustifiedGallery.prototype.newSrc = function (imageSrc, imgWidth, imgHeight, image) {
var newImageSrc;
var newImageSrc = null;

if (this.settings.thumbnailPath) {
newImageSrc = this.settings.thumbnailPath(imageSrc, imgWidth, imgHeight, image);
} else {
}

if (newImageSrc == null) {

var matchRes = imageSrc.match(this.settings.extension);
var ext = (matchRes !== null) ? matchRes[0] : '';
newImageSrc = imageSrc.replace(this.settings.extension, '');
newImageSrc = this.removeSuffix(newImageSrc, this.getUsedSuffix(newImageSrc));
newImageSrc += this.getSuffix(imgWidth, imgHeight) + ext;

}

return newImageSrc;
Expand Down Expand Up @@ -192,8 +196,9 @@ JustifiedGallery.prototype.displayEntry = function ($entry, x, y, imgWidth, imgH
if (imageSrc) {
imageSrc = this.newSrc(imageSrc, imgWidth, imgHeight, $image[0]);

var self = this;
$image.one('error', function () {
this.resetImgSrc($image); //revert to the original thumbnail
self.resetImgSrc($image); //revert to the original thumbnail
});

var loadNewImage = function () {
Expand Down
2 changes: 1 addition & 1 deletion src/less/justifiedGallery.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Justified Gallery - 3.8.1
* Justified Gallery - v3.9.0-645d8e1
* http://miromannino.com/projects/justified-gallery/
* Copyright (c) 2019 Miro Mannino
* Licensed under the MIT license.
Expand Down