Skip to content
Open
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
36 changes: 28 additions & 8 deletions src/js/_enqueues/admin/site-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,37 @@
// When an image is selected, run a callback.
frame.on( 'select', function () {
// Grab the selected attachment.
var attachment = frame.state().get( 'selection' ).first();
var attachment = frame.state().get( 'selection' ).first(),
size = $el.data( 'size' );

if (
attachment.attributes.height === $el.data( 'size' ) &&
$el.data( 'size' ) === attachment.attributes.width
attachment.attributes.height === size &&
size === attachment.attributes.width
) {
switchToUpdate( attachment.attributes );
frame.close();

// Set the value of the hidden input to the attachment id.
$hiddenDataField.val( attachment.id );
/*
* The image doesn't need cropping, but it still goes through the crop
* request so that the site icon and its additional sizes are created.
*/
wp.ajax
.post( 'crop-image', {
nonce: attachment.get( 'nonces' ).edit,
id: attachment.id,
context: 'site-icon',
cropDetails: {
x1: 0,
y1: 0,
width: size,
height: size,
dst_width: size,
dst_height: size,
},
} )
.done( function ( croppedImage ) {
frame.trigger( 'cropped', croppedImage );
} )
.fail( function () {
frame.trigger( 'content:error:crop' );
} );
} else {
frame.setState( 'cropper' );
}
Expand Down
Loading