Skip to content

Commit

Permalink
Fix bug when image sizes don't have thumbnail size
Browse files Browse the repository at this point in the history
  • Loading branch information
puleeno committed Nov 28, 2019
1 parent fce999e commit f011ae3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions assets/js/wallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jQuery(
'.select-image-box',
function (e) {
var wallery_element = $( this ).parent( '.wallery' );
var wallery_id = $(wallery_element).attr('id');
var wallery_id = $( wallery_element ).attr( 'id' );
e.preventDefault();
if (file_frame) {
file_frame.close();
Expand All @@ -27,11 +27,11 @@ jQuery(
selection = file_frame.state().get( 'selection' );
selection.map(
function (attachment, i) {
attachment = attachment.toJSON(),
index = listIndex + (i + 1);

attachment = attachment.toJSON();
index = listIndex + (i + 1);
firstImage = attachment.sizes.thumbnail ? attachment.sizes.thumbnail : _.head( Object.values( attachment.sizes ) );
$( wallery_element ).find( '.images-list' ).append(
'<div class="wallery-image image"><div class="image-inner"><input type="hidden" name="' + wallery_id + '[' + index + ']" value="' + attachment.id + '"><img class="image-preview" src="' + attachment.sizes.thumbnail.url + '"><a class="wallary-action change-image" href="#" data-uploader-title="Change image" data-uploader-button-text="Change image"><span class="wallery-retweet"></span></a><br><a class="wallary-action remove-image" href="#"><span class="wallery-trash"></span></a></div></div>'
'<div class="wallery-image image"><div class="image-inner"><input type="hidden" name="' + wallery_id + '[' + index + ']" value="' + attachment.id + '"><img class="image-preview" src="' + firstImage.url + '"><a class="wallary-action change-image" href="#" data-uploader-title="Change image" data-uploader-button-text="Change image"><span class="wallery-retweet"></span></a><br><a class="wallary-action remove-image" href="#"><span class="wallery-trash"></span></a></div></div>'
);
}
);
Expand Down Expand Up @@ -65,9 +65,9 @@ jQuery(
'select',
function () {
attachment = file_frame.state().get( 'selection' ).first().toJSON();

firstImage = attachment.sizes.thumbnail ? attachment.sizes.thumbnail : _.head( Object.values( attachment.sizes ) );
that.parent().find( 'input:hidden' ).attr( 'value', attachment.id );
that.parent().find( 'img.image-preview' ).attr( 'src', attachment.sizes.thumbnail.url );
that.parent().find( 'img.image-preview' ).attr( 'src', firstImage.url );
}
);
file_frame.open();
Expand All @@ -77,7 +77,7 @@ jQuery(
function resetIndex() {
$( '.images-list .image' ).each(
function (i) {
var wallery_id = $(this).parents('.images-list').parent().attr('id');
var wallery_id = $( this ).parents( '.images-list' ).parent().attr( 'id' );
$( this ).find( 'input:hidden' ).attr( 'name', wallery_id + '[' + i + ']' );
}
);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "puleeno/wallery",
"description": "WordPress gallery for meta box and frontend post",
"version": "1.0.5",
"type": "library",
"license": "MIT",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion src/Wallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Wallery
{

const VERSION = '1.0.0';
const VERSION = '1.0.5';
const LIB_NAME = 'wallery';
const DEFAULT_IMAGE_LAYOUT = 'thumbnail';

Expand Down

0 comments on commit f011ae3

Please sign in to comment.