Custom cropper class to remove wp_customize.
This commit is contained in:
parent
218ecb5296
commit
c47569912d
|
@ -6,7 +6,8 @@ export default {
|
|||
initFrame: function() {
|
||||
|
||||
wp.media.view.settings.post = {
|
||||
id: this.params.relatedPostId
|
||||
id: this.params.relatedPostId,
|
||||
wp_customize: 'off'
|
||||
}
|
||||
|
||||
this.frame = wp.media({
|
||||
|
@ -57,11 +58,41 @@ export default {
|
|||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
}),
|
||||
|
||||
// CroppedImageControl, with presets for thumbnail dimensions
|
||||
thumbnailControl: wp.customize.CroppedImageControl.extend({
|
||||
|
||||
initFrame: function() {
|
||||
|
||||
var MyCustomizeImageCropper = wp.media.controller.Cropper.extend({
|
||||
|
||||
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: 'off',
|
||||
nonce: attachment.get( 'nonces' ).edit,
|
||||
id: attachment.get( 'id' ),
|
||||
context: control.id,
|
||||
cropDetails: cropDetails
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var l10n = _wpMediaViewsL10n;
|
||||
|
||||
wp.media.view.settings.post = {
|
||||
|
@ -96,7 +127,7 @@ export default {
|
|||
suggestedHeight: this.params.height,
|
||||
uploadedTo: this.params.relatedPostId
|
||||
}),
|
||||
new wp.media.controller.CustomizeImageCropper({
|
||||
new MyCustomizeImageCropper({
|
||||
imgSelectOptions: this.calculateImageSelectOptions,
|
||||
control: this
|
||||
})
|
||||
|
@ -193,7 +224,7 @@ export default {
|
|||
initFrame: function() {
|
||||
|
||||
wp.media.view.settings.post = {
|
||||
id: this.params.relatedPostId
|
||||
id: this.params.relatedPostId
|
||||
}
|
||||
|
||||
this.frame = wp.media({
|
||||
|
|
Loading…
Reference in New Issue