Skip to content

Commit 9595be4

Browse files
committed
JS: Update format to follow WP standards
1 parent d22fffc commit 9595be4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1272
-759
lines changed

assets/js/activitypub-admin.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
jQuery( function( $ ) {
1+
jQuery( function ( $ ) {
22
// Accordion handling in various areas.
3-
$( '.activitypub-settings-accordion' ).on( 'click', '.activitypub-settings-accordion-trigger', function() {
4-
var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );
3+
$( '.activitypub-settings-accordion' ).on(
4+
'click',
5+
'.activitypub-settings-accordion-trigger',
6+
function () {
7+
var isExpanded = 'true' === $( this ).attr( 'aria-expanded' );
58

6-
if ( isExpanded ) {
7-
$( this ).attr( 'aria-expanded', 'false' );
8-
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true );
9-
} else {
10-
$( this ).attr( 'aria-expanded', 'true' );
11-
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false );
9+
if ( isExpanded ) {
10+
$( this ).attr( 'aria-expanded', 'false' );
11+
$( '#' + $( this ).attr( 'aria-controls' ) ).attr(
12+
'hidden',
13+
true
14+
);
15+
} else {
16+
$( this ).attr( 'aria-expanded', 'true' );
17+
$( '#' + $( this ).attr( 'aria-controls' ) ).attr(
18+
'hidden',
19+
false
20+
);
21+
}
1222
}
13-
} );
14-
15-
$(document).on( 'wp-plugin-install-success', function( event, response ) {
16-
setTimeout( function() {
17-
$( '.activate-now' ).removeClass( 'thickbox open-plugin-details-modal' );
18-
}, 1200 );
19-
} );
23+
);
2024

25+
$( document ).on(
26+
'wp-plugin-install-success',
27+
function ( event, response ) {
28+
setTimeout( function () {
29+
$( '.activate-now' ).removeClass(
30+
'thickbox open-plugin-details-modal'
31+
);
32+
}, 1200 );
33+
}
34+
);
2135
} );

assets/js/activitypub-header-image.js

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
( function ( $ ) {
1212
var $chooseButton = $( '#activitypub-choose-from-library-button' ),
13-
$headerImagePreviewWrapper = $( '#activitypub-header-image-preview-wrapper' ),
13+
$headerImagePreviewWrapper = $(
14+
'#activitypub-header-image-preview-wrapper'
15+
),
1416
$headerImagePreview = $( '#activitypub-header-image-preview' ),
1517
$hiddenDataField = $( '#activitypub_header_image' ),
1618
$removeButton = $( '#activitypub-remove-header-image' ),
@@ -22,34 +24,38 @@
2224
* for users who don't have the 'customize' capability.
2325
* See https://github.com/Automattic/wordpress-activitypub/issues/846
2426
*/
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;
3033

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;
3538

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+
}
4148

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+
},
4957
}
50-
} );
51-
52-
58+
);
5359

5460
/**
5561
* Calculate image selection options based on the attachment dimensions.
@@ -158,13 +164,16 @@
158164
// Grab the selected attachment.
159165
var attachment = frame.state().get( 'selection' ).first(),
160166
targetRatio = $el.data( 'width' ) / $el.data( 'height' ),
161-
currentRatio = attachment.attributes.width / attachment.attributes.height,
167+
currentRatio =
168+
attachment.attributes.width / attachment.attributes.height,
162169
alreadyCropped = false;
163170

164171
// Check if the image already has the correct aspect ratio (with a small tolerance).
165172
if ( Math.abs( currentRatio - targetRatio ) < 0.01 ) {
166173
// 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+
) {
168177
// This is a new image with the correct aspect ratio.
169178
$hiddenDataField.val( attachment.id );
170179
}

0 commit comments

Comments
 (0)