From 4092c5a37e5028522821df869bba8f6c31985edc Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 12 Jun 2015 22:27:51 +0000 Subject: [PATCH] Fix regressions from [32649] wrt Customizer `expanded` and `active` state changes for sections. The `args.completeCallback` was not always called when `onChangeExpanded()` was called. And when a section became inactive (`active` state goes to `false`) and it was currently `expanded`, the Customizer panel would then becomes blank as the section was hidden; it needed to `collapse()` the section first before hiding the element. See #31336. git-svn-id: https://develop.svn.wordpress.org/trunk@32743 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 32 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 5d0b30bb4b..1a088cab84 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -284,17 +284,27 @@ * @param {Object} args.completeCallback */ onChangeActive: function ( active, args ) { - var duration = ( 'resolved' === api.previewer.deferred.active.state() ? args.duration : 0 ); - if ( ! $.contains( document, this.container ) ) { + var duration, construct = this; + duration = ( 'resolved' === api.previewer.deferred.active.state() ? args.duration : 0 ); + if ( ! $.contains( document, construct.container[0] ) ) { // jQuery.fn.slideUp is not hiding an element if it is not in the DOM - this.container.toggle( active ); + construct.container.toggle( active ); if ( args.completeCallback ) { args.completeCallback(); } } else if ( active ) { - this.container.stop( true, true ).slideDown( duration, args.completeCallback ); + construct.container.stop( true, true ).slideDown( duration, args.completeCallback ); } else { - this.container.stop( true, true ).slideUp( duration, args.completeCallback ); + if ( construct.expanded() ) { + construct.collapse({ + duration: duration, + completeCallback: function() { + construct.container.stop( true, true ).slideUp( duration, args.completeCallback ); + } + }); + } else { + construct.container.stop( true, true ).slideUp( duration, args.completeCallback ); + } } }, @@ -596,6 +606,9 @@ position = content.offset().top; scroll = container.scrollTop(); content.css( 'margin-top', ( 45 - position - scroll ) ); + if ( args.completeCallback ) { + args.completeCallback(); + } }; } @@ -616,12 +629,19 @@ expand(); } - } else if ( section.container.hasClass( 'open' ) ) { + } else if ( ! expanded && section.container.hasClass( 'open' ) ) { section.container.removeClass( 'open' ); overlay.removeClass( 'section-open' ); content.css( 'margin-top', 'inherit' ); container.scrollTop( 0 ); section.container.find( '.accordion-section-title' ).focus(); + if ( args.completeCallback ) { + args.completeCallback(); + } + } else { + if ( args.completeCallback ) { + args.completeCallback(); + } } } });