blob: 06346a95f844f3ba646f5eb6ca2cc2d81154515a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
var Controller = wp.media.controller,
CustomizeImageCropper;
/**
* A state for cropping an image in the customizer.
*
* @since 4.3.0
*
* @constructs wp.media.controller.CustomizeImageCropper
* @memberOf wp.media.controller
* @augments wp.media.controller.CustomizeImageCropper.Cropper
* @inheritDoc
*/
CustomizeImageCropper = Controller.Cropper.extend(/** @lends wp.media.controller.CustomizeImageCropper.prototype */{
/**
* Posts the crop details to the admin.
*
* Uses crop measurements when flexible in both directions.
* Constrains flexible side based on image ratio and size of the fixed side.
*
* @since 4.3.0
*
* @param {Object} attachment The attachment to crop.
*
* @return {$.promise} A jQuery promise that represents the crop image request.
*/
doCrop: function( attachment ) {
var cropDetails = attachment.get( 'cropDetails' ),
control = this.get( 'control' ),
ratio = cropDetails.width / cropDetails.height;
// Use crop measurements when flexible in both directions.
if ( control.params.flex_width && control.params.flex_height ) {
cropDetails.dst_width = cropDetails.width;
cropDetails.dst_height = cropDetails.height;
// Constrain flexible side based on image ratio and size of the fixed side.
} else {
cropDetails.dst_width = control.params.flex_width ? control.params.height * ratio : control.params.width;
cropDetails.dst_height = control.params.flex_height ? control.params.width / ratio : control.params.height;
}
return wp.ajax.post( 'crop-image', {
wp_customize: 'on',
nonce: attachment.get( 'nonces' ).edit,
id: attachment.get( 'id' ),
context: control.id,
cropDetails: cropDetails
} );
}
});
module.exports = CustomizeImageCropper;
|