diff -r c7c34916027a -r 177826044cd9 wp/wp-admin/js/image-edit.js --- a/wp/wp-admin/js/image-edit.js Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-admin/js/image-edit.js Mon Oct 14 18:28:13 2019 +0200 @@ -1,10 +1,12 @@ -/* global imageEditL10n, ajaxurl, confirm */ /** - * @summary The functions necessary for editing images. + * The functions necessary for editing images. * - * @since 2.9.0 + * @since 2.9.0 + * @output wp-admin/js/image-edit.js */ + /* global imageEditL10n, ajaxurl, confirm */ + (function($) { /** @@ -19,7 +21,32 @@ _view : false, /** - * @summary Converts a value to an integer. + * Handle crop tool clicks. + */ + handleCropToolClick: function( postid, nonce, cropButton ) { + var img = $( '#image-preview-' + postid ), + selection = this.iasapi.getSelection(); + + // Ensure selection is available, otherwise reset to full image. + if ( isNaN( selection.x1 ) ) { + this.setCropSelection( postid, { 'x1': 0, 'y1': 0, 'x2': img.innerWidth(), 'y2': img.innerHeight(), 'width': img.innerWidth(), 'height': img.innerHeight() } ); + selection = this.iasapi.getSelection(); + } + + // If we don't already have a selection, select the entire image. + if ( 0 === selection.x1 && 0 === selection.y1 && 0 === selection.x2 && 0 === selection.y2 ) { + this.iasapi.setSelection( 0, 0, img.innerWidth(), img.innerHeight(), true ); + this.iasapi.setOptions( { show: true } ); + this.iasapi.update(); + } else { + + // Otherwise, perform the crop. + imageEdit.crop( postid, nonce , cropButton ); + } + }, + + /** + * Converts a value to an integer. * * @memberof imageEdit * @since 2.9.0 @@ -37,8 +64,7 @@ }, /** - * @summary Adds the disabled attribute and class to a single form element - * or a field set. + * Adds the disabled attribute and class to a single form element or a field set. * * @memberof imageEdit * @since 2.9.0 @@ -67,7 +93,7 @@ }, /** - * @summary Initializes the image editor. + * Initializes the image editor. * * @memberof imageEdit * @since 2.9.0 @@ -110,7 +136,7 @@ }, /** - * @summary Toggles the wait/load icon in the editor. + * Toggles the wait/load icon in the editor. * * @memberof imageEdit * @since 2.9.0 @@ -131,7 +157,7 @@ }, /** - * @summary Shows or hides the image edit help box. + * Shows or hides the image edit help box. * * @memberof imageEdit * @since 2.9.0 @@ -150,7 +176,7 @@ }, /** - * @summary Gets the value from the image edit target. + * Gets the value from the image edit target. * * The image edit target contains the image sizes where the (possible) changes * have to be applied to. @@ -168,7 +194,7 @@ }, /** - * @summary Recalculates the height or width and keeps the original aspect ratio. + * Recalculates the height or width and keeps the original aspect ratio. * * If the original image size is exceeded a red exclamation mark is shown. * @@ -206,7 +232,7 @@ }, /** - * @summary Gets the selected aspect ratio. + * Gets the selected aspect ratio. * * @memberof imageEdit * @since 2.9.0 @@ -232,7 +258,7 @@ }, /** - * @summary Removes the last action from the image edit history + * Removes the last action from the image edit history. * The history consist of (edit) actions performed on the image. * * @memberof imageEdit @@ -296,7 +322,7 @@ return ''; }, /** - * @summary Binds the necessary events to the image. + * Binds the necessary events to the image. * * When the image source is reloaded the image will be reloaded. * @@ -351,7 +377,6 @@ t.hold.sizer = max1 > max2 ? max2 / max1 : 1; t.initCrop(postid, img, parent); - t.setCropSelection(postid, 0); if ( (typeof callback !== 'undefined') && callback !== null ) { callback(); @@ -372,7 +397,7 @@ .attr('src', ajaxurl + '?' + $.param(data)); }, /** - * @summary Performs an image edit action. + * Performs an image edit action. * * @memberof imageEdit * @since 2.9.0 @@ -439,7 +464,7 @@ }, /** - * @summary Stores the changes that are made to the image. + * Stores the changes that are made to the image. * * @memberof imageEdit * @since 2.9.0 @@ -504,7 +529,7 @@ }, /** - * @summary Creates the image edit window. + * Creates the image edit window. * * @memberof imageEdit * @since 2.9.0 @@ -561,7 +586,7 @@ }, /** - * @summary Initializes the cropping tool and sets a default cropping selection. + * Initializes the cropping tool and sets a default cropping selection. * * @memberof imageEdit * @since 2.9.0 @@ -579,14 +604,15 @@ } this.initCrop(postid, img, parent); - this.setCropSelection(postid, 0); + this.setCropSelection( postid, { 'x1': 0, 'y1': 0, 'x2': 0, 'y2': 0, 'width': img.innerWidth(), 'height': img.innerHeight() } ); + this.toggleEditor(postid, 0); // Editor is ready, move focus to the first focusable element. $( '.imgedit-wrap .imgedit-help-toggle' ).eq( 0 ).focus(); }, /** - * @summary Initializes the cropping tool. + * Initializes the cropping tool. * * @memberof imageEdit * @since 2.9.0 @@ -612,7 +638,9 @@ minHeight: 3, /** - * @summary Sets the CSS styles and binds events for locking the aspect ratio. + * Sets the CSS styles and binds events for locking the aspect ratio. + * + * @ignore * * @param {jQuery} img The preview image. */ @@ -623,7 +651,7 @@ $img.next().css( 'position', 'absolute' ) .nextAll( '.imgareaselect-outer' ).css( 'position', 'absolute' ); /** - * @summary Binds mouse down event to the cropping container. + * Binds mouse down event to the cropping container. * * @returns {void} */ @@ -643,7 +671,9 @@ }, /** - * @summary Event triggered when starting a selection. + * Event triggered when starting a selection. + * + * @ignore * * @returns {void} */ @@ -651,7 +681,9 @@ imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1); }, /** - * @summary Event triggered when the selection is ended. + * Event triggered when the selection is ended. + * + * @ignore * * @param {object} img jQuery object representing the image. * @param {object} c The selection. @@ -663,7 +695,9 @@ }, /** - * @summary Event triggered when the selection changes. + * Event triggered when the selection changes. + * + * @ignore * * @param {object} img jQuery object representing the image. * @param {object} c The selection. @@ -679,7 +713,7 @@ }, /** - * @summary Stores the current crop selection. + * Stores the current crop selection. * * @memberof imageEdit * @since 2.9.0 @@ -695,8 +729,8 @@ c = c || 0; if ( !c || ( c.width < 3 && c.height < 3 ) ) { - this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0); - this.setDisabled($('#imgedit-crop-sel-' + postid), 0); + this.setDisabled( $( '.imgedit-crop', '#imgedit-panel-' + postid ), 1 ); + this.setDisabled( $( '#imgedit-crop-sel-' + postid ), 1 ); $('#imgedit-sel-width-' + postid).val(''); $('#imgedit-sel-height-' + postid).val(''); $('#imgedit-selection-' + postid).val(''); @@ -710,7 +744,7 @@ /** - * @summary Closes the image editor. + * Closes the image editor. * * @memberof imageEdit * @since 2.9.0 @@ -751,7 +785,7 @@ }, /** - * @summary Checks if the image edit history is saved. + * Checks if the image edit history is saved. * * @memberof imageEdit * @since 2.9.0 @@ -775,7 +809,7 @@ }, /** - * @summary Adds an image edit action to the history. + * Adds an image edit action to the history. * * @memberof imageEdit * @since 2.9.0 @@ -808,7 +842,7 @@ }, /** - * @summary Rotates the image. + * Rotates the image. * * @memberof imageEdit * @since 2.9.0 @@ -829,7 +863,7 @@ }, /** - * @summary Flips the image. + * Flips the image. * * @memberof imageEdit * @since 2.9.0 @@ -850,7 +884,7 @@ }, /** - * @summary Crops the image. + * Crops the image. * * @memberof imageEdit * @since 2.9.0 @@ -879,7 +913,7 @@ }, /** - * @summary Undoes an image edit action. + * Undoes an image edit action. * * @memberof imageEdit * @since 2.9.0 @@ -942,7 +976,7 @@ }, /** - * @summary Sets the selection for the height and width in pixels. + * Sets the selection for the height and width in pixels. * * @memberof imageEdit * @since 2.9.0