Make WordPress Core

Ticket #30155: 30155.4.diff

File 30155.4.diff, 3.4 KB (added by adamsilverstein, 8 years ago)
  • src/wp-admin/includes/image-edit.php

    diff --git src/wp-admin/includes/image-edit.php src/wp-admin/includes/image-edit.php
    index d9cf6048f2..49cb370d3e 100644
    function wp_image_editor($post_id, $msg = false) { 
    182182        <div class="imgedit-panel-content wp-clearfix">
    183183                <?php echo $note; ?>
    184184                <div class="imgedit-menu wp-clearfix">
    185                         <button type="button" onclick="imageEdit.crop(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-crop button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Crop' ); ?></span></button><?php
     185                        <button type="button" onclick="imageEdit.handleCropToolClick( <?php echo "$post_id, '$nonce'"; ?>, this )" class="imgedit-crop button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Crop' ); ?></span></button><?php
    186186
    187187                // On some setups GD library does not provide imagerotate() - Ticket #11536
    188188                if ( wp_image_editor_supports( array( 'mime_type' => get_post_mime_type( $post_id ), 'methods' => array( 'rotate' ) ) ) ) {
  • src/wp-admin/js/image-edit.js

    diff --git src/wp-admin/js/image-edit.js src/wp-admin/js/image-edit.js
    index 0d8eaf081f..ae2b8d950a 100644
     
    1919        _view : false,
    2020
    2121        /**
     22         * Handle crop tool clicks.
     23         */
     24        handleCropToolClick: function( postid, nonce, cropButton ) {
     25                var img = $( '#image-preview-' + postid ),
     26                        selection = this.iasapi.getSelection();
     27
     28                // Ensure selection is available, otherwise reset to full image.
     29                if ( isNaN( selection.x1 ) ) {
     30                        this.setCropSelection( postid, { 'x1': 0, 'y1': 0, 'x2': img.innerWidth(), 'y2': img.innerHeight(), 'width': img.innerWidth(), 'height': img.innerHeight() } );
     31                        selection = this.iasapi.getSelection();
     32                }
     33
     34                // If we don't already have a selection, select the entire image.
     35                if ( 0 === selection.x1 && 0 === selection.y1 && 0 === selection.x2 && 0 === selection.y2 ) {
     36                        this.iasapi.setSelection( 0, 0, img.innerWidth(), img.innerHeight(), true );
     37                        this.iasapi.setOptions( { show: true } );
     38                        this.iasapi.update();
     39                } else {
     40
     41                        // Otherwise, perform the crop.
     42                        imageEdit.crop( postid, nonce , cropButton );
     43                }
     44        },
     45
     46        /**
    2247         * @summary Converts a value to an integer.
    2348         *
    2449         * @memberof imageEdit
     
    351376                                t.hold.sizer = max1 > max2 ? max2 / max1 : 1;
    352377
    353378                                t.initCrop(postid, img, parent);
    354                                 t.setCropSelection(postid, 0);
    355379
    356380                                if ( (typeof callback !== 'undefined') && callback !== null ) {
    357381                                        callback();
     
    579603                }
    580604
    581605                this.initCrop(postid, img, parent);
    582                 this.setCropSelection(postid, 0);
     606                this.setCropSelection( postid, { 'x1': 0, 'y1': 0, 'x2': 0, 'y2': 0, 'width': img.innerWidth(), 'height': img.innerHeight() } );
     607
    583608                this.toggleEditor(postid, 0);
    584609                // Editor is ready, move focus to the first focusable element.
    585610                $( '.imgedit-wrap .imgedit-help-toggle' ).eq( 0 ).focus();
     
    695720                c = c || 0;
    696721
    697722                if ( !c || ( c.width < 3 && c.height < 3 ) ) {
    698                         this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0);
    699                         this.setDisabled($('#imgedit-crop-sel-' + postid), 0);
     723                        this.setDisabled( $( '.imgedit-crop', '#imgedit-panel-' + postid ), 1 );
     724                        this.setDisabled( $( '#imgedit-crop-sel-' + postid ), 1 );
    700725                        $('#imgedit-sel-width-' + postid).val('');
    701726                        $('#imgedit-sel-height-' + postid).val('');
    702727                        $('#imgedit-selection-' + postid).val('');