From 52d50a6ce9f917230e7f984e0777d4e53905ecd0 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 6 Mar 2016 01:44:53 +0000 Subject: [PATCH] Customize: Fix image cropping when doing live preview of theme switches. Ensure that the Customizer gets bootstrapped with the pre-activated `theme` supplied in the `custom-header-crop` admin ajax requests. Props faishal, rittesh.patel. Fixes #32783. git-svn-id: https://develop.svn.wordpress.org/trunk@36866 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 4 ++++ src/wp-includes/js/media-views.js | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index f514cf7632..a22aa76bba 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -2346,6 +2346,10 @@ api.HeaderTool.UploadsList, api.HeaderTool.DefaultsList ]); + + // Ensure custom-header-crop Ajax requests bootstrap the Customizer to activate the previewed theme. + wp.media.controller.Cropper.prototype.defaults.doCropArgs.wp_customize = 'on'; + wp.media.controller.Cropper.prototype.defaults.doCropArgs.theme = api.settings.theme.stylesheet; }, /** diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index f9c5555049..015ec23527 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -282,8 +282,10 @@ Cropper = wp.media.controller.State.extend({ toolbar: 'crop', content: 'crop', router: false, + canSkipCrop: false, - canSkipCrop: false + // Default doCrop Ajax arguments to allow the Customizer (for example) to inject state. + doCropArgs: {} }, activate: function() { @@ -367,11 +369,15 @@ Cropper = wp.media.controller.State.extend({ }, doCrop: function( attachment ) { - return wp.ajax.post( 'custom-header-crop', { - nonce: attachment.get('nonces').edit, - id: attachment.get('id'), - cropDetails: attachment.get('cropDetails') - } ); + return wp.ajax.post( 'custom-header-crop', _.extend( + {}, + this.defaults.doCropArgs, + { + nonce: attachment.get( 'nonces' ).edit, + id: attachment.get( 'id' ), + cropDetails: attachment.get( 'cropDetails' ) + } + ) ); } });