Customizer: retain aspect ration when cropping media w/ shift+click/drag.

Enforce a 1:1 ratio when holding the shift key and dragging in the image cropping tool in the customizer context.

Props melchoyce, mikeschroder.
Fixes #40211.

Built from https://develop.svn.wordpress.org/trunk@41557


git-svn-id: http://core.svn.wordpress.org/trunk@41390 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Adam Silverstein 2017-09-21 22:45:44 +00:00
parent 220d5aec74
commit 43eb51d4a6
3 changed files with 25 additions and 7 deletions

View File

@ -4523,14 +4523,32 @@ Cropper = View.extend(/** @lends wp.media.view.Cropper.prototype */{
};
},
onImageLoad: function() {
var imgOptions = this.controller.get('imgSelectOptions');
var imgOptions = this.controller.get('imgSelectOptions'),
imgSelect;
if (typeof imgOptions === 'function') {
imgOptions = imgOptions(this.options.attachment, this.controller);
}
imgOptions = _.extend(imgOptions, {parent: this.$el});
imgOptions = _.extend(imgOptions, {
parent: this.$el,
onInit: function() {
this.parent.children().on( 'mousedown touchstart', function( e ){
if ( e.shiftKey ) {
imgSelect.setOptions( {
aspectRatio: '1:1'
} );
} else {
imgSelect.setOptions( {
aspectRatio: false
} );
}
} );
}
} );
this.trigger('image-loaded');
this.controller.imgSelect = this.$image.imgAreaSelect(imgOptions);
imgSelect = this.controller.imgSelect = this.$image.imgAreaSelect(imgOptions);
},
onError: function() {
var filename = this.options.attachment.get('filename');

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41556';
$wp_version = '4.9-alpha-41557';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.