Skip to content

Commit 099eacf

Browse files
refactor: upload single image as fallback image
1 parent 4cd201f commit 099eacf

1 file changed

Lines changed: 9 additions & 26 deletions

File tree

js/feedzy-setup-wizard.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -374,37 +374,20 @@ jQuery(function ($) {
374374
button: {
375375
text: feedzySetupWizardData.mediaUploadText.iframeButton
376376
},
377-
multiple: true
377+
multiple: false
378378
} ).on( 'select', function() { // it also has "open" and "close" events
379379
const selectedAttachments = wp_media_uploader.state().get( 'selection' );
380-
const countSelected = selectedAttachments?.toJSON()?.length;
381380
button.parents( '.fz-form-group' ).find( '.feedzy-media-preview' ).remove();
382381
// Display image preview when a single image is selected.
383-
if ( 1 === countSelected ) {
384-
const attachment = selectedAttachments.first().toJSON();
385-
let attachmentUrl = attachment.url;
386-
if ( attachment.sizes.thumbnail ) {
387-
attachmentUrl = attachment.sizes.thumbnail.url;
388-
}
389-
if ( $( '.feedzy-media-preview' ).length ) {
390-
$( '.feedzy-media-preview' ).find( 'img' ).attr( 'src', attachmentUrl );
391-
} else {
392-
$( '<div class="fz-form-group mb-20 feedzy-media-preview"><img src="' + attachmentUrl + '"></div>' ).insertBefore( button.parent() );
393-
}
382+
const attachment = selectedAttachments.first().toJSON();
383+
let attachmentUrl = attachment.url;
384+
if ( attachment.sizes.thumbnail ) {
385+
attachmentUrl = attachment.sizes.thumbnail.url;
386+
}
387+
if ( $( '.feedzy-media-preview' ).length ) {
388+
$( '.feedzy-media-preview' ).find( 'img' ).attr( 'src', attachmentUrl );
394389
} else {
395-
$(
396-
'<div class="fz-form-group mb-20 feedzy-media-preview fz-fallback-images pb-8">' +
397-
selectedAttachments
398-
?.toJSON()
399-
?.map(({ url, sizes }) => {
400-
if (sizes?.thumbnail) {
401-
url = sizes.thumbnail.url;
402-
}
403-
return `<img width="150" height="150" src="${url}" class="attachment-thumbnail size-thumbnail" alt="" decoding="async" loading="lazy">`;
404-
})
405-
.join('') +
406-
'</div>'
407-
).insertBefore(button.parent());
390+
$( '<div class="fz-form-group mb-20 feedzy-media-preview"><img src="' + attachmentUrl + '"></div>' ).insertBefore( button.parent() );
408391
}
409392
// Get all selected attachment ids.
410393
const ids = selectedAttachments.map( function( image ) {

0 commit comments

Comments
 (0)