|
10 | 10 |
|
11 | 11 | ( function ( $ ) {
|
12 | 12 | var $chooseButton = $( '#activitypub-choose-from-library-button' ),
|
13 |
| - $headerImagePreviewWrapper = $( '#activitypub-header-image-preview-wrapper' ), |
| 13 | + $headerImagePreviewWrapper = $( |
| 14 | + '#activitypub-header-image-preview-wrapper' |
| 15 | + ), |
14 | 16 | $headerImagePreview = $( '#activitypub-header-image-preview' ),
|
15 | 17 | $hiddenDataField = $( '#activitypub_header_image' ),
|
16 | 18 | $removeButton = $( '#activitypub-remove-header-image' ),
|
|
22 | 24 | * for users who don't have the 'customize' capability.
|
23 | 25 | * See https://github.com/Automattic/wordpress-activitypub/issues/846
|
24 | 26 | */
|
25 |
| - ImageCropperNoCustomizer = wp.media.controller.CustomizeImageCropper.extend( { |
26 |
| - doCrop: function( attachment ) { |
27 |
| - var cropDetails = attachment.get( 'cropDetails' ), |
28 |
| - control = this.get( 'control' ), |
29 |
| - ratio = cropDetails.width / cropDetails.height; |
| 27 | + ImageCropperNoCustomizer = wp.media.controller.CustomizeImageCropper.extend( |
| 28 | + { |
| 29 | + doCrop: function ( attachment ) { |
| 30 | + var cropDetails = attachment.get( 'cropDetails' ), |
| 31 | + control = this.get( 'control' ), |
| 32 | + ratio = cropDetails.width / cropDetails.height; |
30 | 33 |
|
31 |
| - // Use crop measurements when flexible in both directions. |
32 |
| - if ( control.params.flex_width && control.params.flex_height ) { |
33 |
| - cropDetails.dst_width = cropDetails.width; |
34 |
| - cropDetails.dst_height = cropDetails.height; |
| 34 | + // Use crop measurements when flexible in both directions. |
| 35 | + if ( control.params.flex_width && control.params.flex_height ) { |
| 36 | + cropDetails.dst_width = cropDetails.width; |
| 37 | + cropDetails.dst_height = cropDetails.height; |
35 | 38 |
|
36 |
| - // Constrain flexible side based on image ratio and size of the fixed side. |
37 |
| - } else { |
38 |
| - cropDetails.dst_width = control.params.flex_width ? control.params.height * ratio : control.params.width; |
39 |
| - cropDetails.dst_height = control.params.flex_height ? control.params.width / ratio : control.params.height; |
40 |
| - } |
| 39 | + // Constrain flexible side based on image ratio and size of the fixed side. |
| 40 | + } else { |
| 41 | + cropDetails.dst_width = control.params.flex_width |
| 42 | + ? control.params.height * ratio |
| 43 | + : control.params.width; |
| 44 | + cropDetails.dst_height = control.params.flex_height |
| 45 | + ? control.params.width / ratio |
| 46 | + : control.params.height; |
| 47 | + } |
41 | 48 |
|
42 |
| - return wp.ajax.post( 'crop-image', { |
43 |
| - // where wp_customize: 'on' would be in Core, for no good reason I understand. |
44 |
| - nonce: attachment.get( 'nonces' ).edit, |
45 |
| - id: attachment.get( 'id' ), |
46 |
| - context: control.id, |
47 |
| - cropDetails: cropDetails |
48 |
| - } ); |
| 49 | + return wp.ajax.post( 'crop-image', { |
| 50 | + // where wp_customize: 'on' would be in Core, for no good reason I understand. |
| 51 | + nonce: attachment.get( 'nonces' ).edit, |
| 52 | + id: attachment.get( 'id' ), |
| 53 | + context: control.id, |
| 54 | + cropDetails: cropDetails, |
| 55 | + } ); |
| 56 | + }, |
49 | 57 | }
|
50 |
| - } ); |
51 |
| - |
52 |
| - |
| 58 | + ); |
53 | 59 |
|
54 | 60 | /**
|
55 | 61 | * Calculate image selection options based on the attachment dimensions.
|
|
158 | 164 | // Grab the selected attachment.
|
159 | 165 | var attachment = frame.state().get( 'selection' ).first(),
|
160 | 166 | targetRatio = $el.data( 'width' ) / $el.data( 'height' ),
|
161 |
| - currentRatio = attachment.attributes.width / attachment.attributes.height, |
| 167 | + currentRatio = |
| 168 | + attachment.attributes.width / attachment.attributes.height, |
162 | 169 | alreadyCropped = false;
|
163 | 170 |
|
164 | 171 | // Check if the image already has the correct aspect ratio (with a small tolerance).
|
165 | 172 | if ( Math.abs( currentRatio - targetRatio ) < 0.01 ) {
|
166 | 173 | // Check if this is the same image that was already selected.
|
167 |
| - if ( attachment.id !== parseInt( $hiddenDataField.val(), 10 ) ) { |
| 174 | + if ( |
| 175 | + attachment.id !== parseInt( $hiddenDataField.val(), 10 ) |
| 176 | + ) { |
168 | 177 | // This is a new image with the correct aspect ratio.
|
169 | 178 | $hiddenDataField.val( attachment.id );
|
170 | 179 | }
|
|
0 commit comments