Make WordPress Core

Changeset 42595 for trunk


Ignore:
Timestamp:
01/24/2018 09:35:10 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Media: Store and reuse image cropper ratio settings if available, instead of overwriting.

Props adamsilverstein.
Fixes #42646.

Location:
trunk/src/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media-views.js

    r42435 r42595  
    91699169            parent: this.$el,
    91709170            onInit: function() {
    9171                 this.parent.children().on( 'mousedown touchstart', function( e ){
    9172 
    9173                     if ( e.shiftKey ) {
     9171
     9172                // Store the set ratio.
     9173                var setRatio = imgSelect.getOptions().aspectRatio;
     9174
     9175                // On mousedown, if no ratio is set and the Shift key is down, use a 1:1 ratio.
     9176                this.parent.children().on( 'mousedown touchstart', function( e ) {
     9177
     9178                    // If no ratio is set and the shift key is down, use a 1:1 ratio.
     9179                    if ( ! setRatio && e.shiftKey ) {
    91749180                        imgSelect.setOptions( {
    91759181                            aspectRatio: '1:1'
    91769182                        } );
    9177                     } else {
    9178                         imgSelect.setOptions( {
    9179                             aspectRatio: false
    9180                         } );
    91819183                    }
     9184                } );
     9185
     9186                this.parent.children().on( 'mouseup touchend', function( e ) {
     9187
     9188                    // Restore the set ratio.
     9189                    imgSelect.setOptions( {
     9190                        aspectRatio: setRatio ? setRatio : false
     9191                    } );
    91829192                } );
    91839193            }
  • trunk/src/wp-includes/js/media/views/cropper.js

    r41557 r42595  
    5656            parent: this.$el,
    5757            onInit: function() {
    58                 this.parent.children().on( 'mousedown touchstart', function( e ){
    5958
    60                     if ( e.shiftKey ) {
     59                // Store the set ratio.
     60                var setRatio = imgSelect.getOptions().aspectRatio;
     61
     62                // On mousedown, if no ratio is set and the Shift key is down, use a 1:1 ratio.
     63                this.parent.children().on( 'mousedown touchstart', function( e ) {
     64
     65                    // If no ratio is set and the shift key is down, use a 1:1 ratio.
     66                    if ( ! setRatio && e.shiftKey ) {
    6167                        imgSelect.setOptions( {
    6268                            aspectRatio: '1:1'
    6369                        } );
    64                     } else {
    65                         imgSelect.setOptions( {
    66                             aspectRatio: false
    67                         } );
    6870                    }
     71                } );
     72
     73                this.parent.children().on( 'mouseup touchend', function( e ) {
     74
     75                    // Restore the set ratio.
     76                    imgSelect.setOptions( {
     77                        aspectRatio: setRatio ? setRatio : false
     78                    } );
    6979                } );
    7080            }
Note: See TracChangeset for help on using the changeset viewer.