Make WordPress Core

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

File 21785-doCrop-move.3.diff, 3.0 KB (added by gcorne, 11 years ago)
  • src/wp-includes/js/media-models.js

    diff --git src/wp-includes/js/media-models.js src/wp-includes/js/media-models.js
    index 53eefdf..d3009b1 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 97dd232..9724db6 100644
     
    12991299                activate: function() {
    13001300                        this.frame.on( 'content:create:crop', this.createCropContent, this );
    13011301                        this.frame.on( 'close', this.removeCropper, this );
    1302                         this.set('selection', new Backbone.Collection(this.frame._selection.single));
     1302                        this.set('selection', new media.model.Selection(this.frame._selection.single));
    13031303                },
    13041304
    13051305                deactivate: function() {
     
    13081308
    13091309                createCropContent: function() {
    13101310                        this.cropperView = new wp.media.view.Cropper({controller: this,
    1311                                         attachment: this.get('selection').first() });
     1311                                        attachment: this.get('selection').single() });
    13121312                        this.cropperView.on('image-loaded', this.createCropToolbar, this);
    13131313                        this.frame.content.set(this.cropperView);
    13141314
     
    13351335
    13361336                                                click: function() {
    13371337                                                        var self = this,
    1338                                                                 selection = this.controller.state().get('selection').first();
    1339 
    1340                                                         selection.set({cropDetails: this.controller.state().imgSelect.getSelection()});
     1338                                                                cropDetails = this.controller.state().imgSelect.getSelection(),
     1339                                                                selection = this.controller.state().get('selection').single();
    13411340
    13421341                                                        this.$el.text(l10n.cropping);
    13431342                                                        this.$el.attr('disabled', true);
    1344                                                         this.controller.state().doCrop( selection ).done( function( croppedImage ) {
     1343                                                        selection.crop(cropDetails).done( function( croppedImage ) {
    13451344                                                                self.controller.trigger('cropped', croppedImage );
    13461345                                                                self.controller.close();
    13471346                                                        }).fail( function() {
     
    13601359                                                priority:   70,
    13611360                                                requires:   { library: false, selection: false },
    13621361                                                click:      function() {
    1363                                                         var selection = this.controller.state().get('selection').first();
     1362                                                        var selection = this.controller.state().get('selection').single();
    13641363                                                        this.controller.state().cropperView.remove();
    13651364                                                        this.controller.trigger('skippedcrop', selection);
    13661365                                                        this.controller.close();
     
    13701369                        }
    13711370
    13721371                        this.frame.toolbar.set( new wp.media.view.Toolbar(toolbarOptions) );
    1373                 },
    1374 
    1375                 doCrop: function( attachment ) {
    1376                         return wp.ajax.post( 'custom-header-crop', {
    1377                                 nonce: attachment.get('nonces').edit,
    1378                                 id: attachment.get('id'),
    1379                                 cropDetails: attachment.get('cropDetails')
    1380                         } );
    13811372                }
    13821373        });
    13831374