Make WordPress Core

Changeset 42596


Ignore:
Timestamp:
01/24/2018 09:40:09 PM (9 years ago)
Author:
SergeyBiryukov
Message:

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

Props adamsilverstein.
Merges [42595] to the 4.9 branch.
Fixes #42646.

Location:
branches/4.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/js/media-views.js

    r41937 r42596  
    89588958                        parent: this.$el,
    89598959                        onInit: function() {
    8960                                 this.parent.children().on( 'mousedown touchstart', function( e ){
    8961 
    8962                                         if ( e.shiftKey ) {
     8960
     8961                                // Store the set ratio.
     8962                                var setRatio = imgSelect.getOptions().aspectRatio;
     8963
     8964                                // On mousedown, if no ratio is set and the Shift key is down, use a 1:1 ratio.
     8965                                this.parent.children().on( 'mousedown touchstart', function( e ) {
     8966
     8967                                        // If no ratio is set and the shift key is down, use a 1:1 ratio.
     8968                                        if ( ! setRatio && e.shiftKey ) {
    89638969                                                imgSelect.setOptions( {
    89648970                                                        aspectRatio: '1:1'
    89658971                                                } );
    8966                                         } else {
    8967                                                 imgSelect.setOptions( {
    8968                                                         aspectRatio: false
    8969                                                 } );
    89708972                                        }
     8973                                } );
     8974
     8975                                this.parent.children().on( 'mouseup touchend', function( e ) {
     8976
     8977                                        // Restore the set ratio.
     8978                                        imgSelect.setOptions( {
     8979                                                aspectRatio: setRatio ? setRatio : false
     8980                                        } );
    89718981                                } );
    89728982                        }
  • branches/4.9/src/wp-includes/js/media/views/cropper.js

    r41557 r42596  
    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.