Make WordPress Core

Ticket #21785: 21785-doCrop-move.2.diff

File 21785-doCrop-move.2.diff, 2.7 KB (added by ehg, 11 years ago)

updated doCrop refactor

  • src/wp-includes/js/media-models.js

    diff --git src/wp-includes/js/media-models.js src/wp-includes/js/media-models.js
    index 19e9021..f024b08 100644
    window.wp = window.wp || {}; 
    322322                        }, data ) ).done( function( resp, status, xhr ) {
    323323                                model.set( model.parse( resp, xhr ), options );
    324324                        });
     325                },
     326                crop: function( cropDetails ) {
     327                        var model = this;
     328
     329                        return wp.ajax.post( 'custom-header-crop', {
     330                                nonce: this.get('nonces').edit,
     331                                id: this.get('id'),
     332                                cropDetails: cropDetails
     333                        } ).done( function( resp, status, xhr ) {
     334                                model.set( model.parse( resp, xhr ) );
     335                        });
    325336                }
    326337        }, {
    327338                /**
  • src/wp-includes/js/media-views.js

    diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
    index be0ee8f..6f73bfb 100644
     
    12871287                activate: function() {
    12881288                        this.frame.on( 'content:create:crop', this.createCropContent, this );
    12891289                        this.frame.on( 'close', this.removeCropper, this );
    1290                         this.set('selection', new Backbone.Collection(this.frame._selection.single));
     1290                        this.set('selection', new media.model.Selection(this.frame._selection.single));
    12911291                },
    12921292
    12931293                deactivate: function() {
     
    13231323
    13241324                                                click: function() {
    13251325                                                        var self = this,
    1326                                                                 selection = this.controller.state().get('selection').first();
    1327 
    1328                                                         selection.set({cropDetails: this.controller.state().imgSelect.getSelection()});
     1326                                                                cropDetails = this.controller.state().imgSelect.getSelection(),
     1327                                                                selection = this.controller.state().get('selection').single();
    13291328
    13301329                                                        this.$el.text(l10n.cropping);
    13311330                                                        this.$el.attr('disabled', true);
    1332                                                         this.controller.state().doCrop( selection ).done( function( croppedImage ) {
     1331                                                        selection.crop(cropDetails).done( function( croppedImage ) {
    13331332                                                                self.controller.trigger('cropped', croppedImage );
    13341333                                                                self.controller.close();
    13351334                                                        });
     
    13461345                                                priority:   70,
    13471346                                                requires:   { library: false, selection: false },
    13481347                                                click:      function() {
    1349                                                         var selection = this.controller.state().get('selection').first();
     1348                                                        var selection = this.controller.state().get('selection').single();
    13501349                                                        this.controller.state().cropperView.remove();
    13511350                                                        this.controller.trigger('skippedcrop', selection);
    13521351                                                        this.controller.close();
     
    13561355                        }
    13571356
    13581357                        this.frame.toolbar.set( new wp.media.view.Toolbar(toolbarOptions) );
    1359                 },
    1360 
    1361                 doCrop: function( attachment ) {
    1362                         return wp.ajax.post( 'custom-header-crop', {
    1363                                 nonce: attachment.get('nonces').edit,
    1364                                 id: attachment.get('id'),
    1365                                 cropDetails: attachment.get('cropDetails')
    1366                         } );
    13671358                }
    13681359        });
    13691360