Changeset 59197
- Timestamp:
- 10/08/2024 10:27:44 PM (4 months ago)
- Location:
- trunk/src/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/wp/customize/controls.js
r58146 r59197 4603 4603 */ 4604 4604 calculateImageSelectOptions: function( attachment, controller ) { 4605 var control = controller.get( 'control' ), 4606 flexWidth = !! parseInt( control.params.flex_width, 10 ), 4607 flexHeight = !! parseInt( control.params.flex_height, 10 ), 4608 realWidth = attachment.get( 'width' ), 4609 realHeight = attachment.get( 'height' ), 4610 xInit = parseInt( control.params.width, 10 ), 4611 yInit = parseInt( control.params.height, 10 ), 4612 ratio = xInit / yInit, 4613 xImg = xInit, 4614 yImg = yInit, 4605 var control = controller.get( 'control' ), 4606 flexWidth = !! parseInt( control.params.flex_width, 10 ), 4607 flexHeight = !! parseInt( control.params.flex_height, 10 ), 4608 realWidth = attachment.get( 'width' ), 4609 realHeight = attachment.get( 'height' ), 4610 xInit = parseInt( control.params.width, 10 ), 4611 yInit = parseInt( control.params.height, 10 ), 4612 requiredRatio = xInit / yInit, 4613 realRatio = realWidth / realHeight, 4614 xImg = xInit, 4615 yImg = yInit, 4615 4616 x1, y1, imgSelectOptions; 4616 4617 4618 controller.set( 'hasRequiredAspectRatio', control.hasRequiredAspectRatio( requiredRatio, realRatio ) ); 4619 controller.set( 'suggestedCropSize', { width: realWidth, height: realHeight, x1: 0, y1: 0, x2: xInit, y2: yInit } ); 4617 4620 controller.set( 'canSkipCrop', ! control.mustBeCropped( flexWidth, flexHeight, xInit, yInit, realWidth, realHeight ) ); 4618 4621 4619 if ( real Width / realHeight > ratio ) {4622 if ( realRatio > requiredRatio ) { 4620 4623 yInit = realHeight; 4621 xInit = yInit * r atio;4624 xInit = yInit * requiredRatio; 4622 4625 } else { 4623 4626 xInit = realWidth; 4624 yInit = xInit / r atio;4627 yInit = xInit / requiredRatio; 4625 4628 } 4626 4629 … … 4663 4666 * Return whether the image must be cropped, based on required dimensions. 4664 4667 * 4665 * @param {boolean} flexW 4666 * @param {boolean} flexH 4667 * @param {number} dstW 4668 * @param {number} dstH 4669 * @param {number} imgW 4670 * @param {number} imgH 4671 * @return {boolean} 4668 * @param {boolean} flexW Width is flexible. 4669 * @param {boolean} flexH Height is flexible. 4670 * @param {number} dstW Required width. 4671 * @param {number} dstH Required height. 4672 * @param {number} imgW Provided image's width. 4673 * @param {number} imgH Provided image's height. 4674 * @return {boolean} Whether cropping is required. 4672 4675 */ 4673 4676 mustBeCropped: function( flexW, flexH, dstW, dstH, imgW, imgH ) { … … 4693 4696 4694 4697 return true; 4698 }, 4699 4700 /** 4701 * Check if the image's aspect ratio essentially matches the required aspect ratio. 4702 * 4703 * Floating point precision is low, so this allows a small tolerance. This 4704 * tolerance allows for images over 100,000 px on either side to still trigger 4705 * the cropping flow. 4706 * 4707 * @param {number} requiredRatio Required image ratio. 4708 * @param {number} realRatio Provided image ratio. 4709 * @return {boolean} Whether the image has the required aspect ratio. 4710 */ 4711 hasRequiredAspectRatio: function ( requiredRatio, realRatio ) { 4712 if ( Math.abs( requiredRatio - realRatio ) < 0.000001 ) { 4713 return true; 4714 } 4715 4716 return false; 4695 4717 }, 4696 4718 -
trunk/src/js/media/controllers/cropper.js
r46800 r59197 94 94 */ 95 95 createCropToolbar: function() { 96 var canSkipCrop, toolbarOptions;96 var canSkipCrop, hasRequiredAspectRatio, suggestedCropSize, toolbarOptions; 97 97 98 canSkipCrop = this.get('canSkipCrop') || false; 98 suggestedCropSize = this.get( 'suggestedCropSize' ); 99 hasRequiredAspectRatio = this.get( 'hasRequiredAspectRatio' ); 100 canSkipCrop = this.get( 'canSkipCrop' ) || false; 99 101 100 102 toolbarOptions = { … … 128 130 }; 129 131 130 if ( canSkipCrop ) {132 if ( canSkipCrop || hasRequiredAspectRatio ) { 131 133 _.extend( toolbarOptions.items, { 132 134 skip: { … … 136 138 requires: { library: false, selection: false }, 137 139 click: function() { 138 var selection = this.controller.state().get('selection').first(); 139 this.controller.state().cropperView.remove(); 140 this.controller.trigger('skippedcrop', selection); 141 this.controller.close(); 140 var controller = this.controller, 141 selection = controller.state().get( 'selection' ).first(); 142 143 controller.state().cropperView.remove(); 144 145 // Apply the suggested crop size. 146 if ( hasRequiredAspectRatio && !canSkipCrop ) { 147 selection.set({cropDetails: suggestedCropSize}); 148 controller.state().doCrop( selection ).done( function( croppedImage ) { 149 controller.trigger( 'cropped', croppedImage ); 150 controller.close(); 151 }).fail( function() { 152 controller.trigger( 'content:error:crop' ); 153 }); 154 return; 155 } 156 157 // Skip the cropping process. 158 controller.trigger( 'skippedcrop', selection ); 159 controller.close(); 142 160 } 143 161 }
Note: See TracChangeset
for help on using the changeset viewer.