From 8894171c45766b8d733b8f8421094ad50f635974 Mon Sep 17 00:00:00 2001
From: Ryan Kienstra <ryan.kienstra@xwp.co>
Date: Fri, 4 Mar 2016 01:48:11 -0300
Subject: [PATCH 1/6] Customize : Remove extra space at bottom of Customizer
 panel.

Before, non-active sections and panels still occupied space in the DOM.
So the active panel had a 'margin-top' property to move it to the top.
So set the height of the non-active sections to 0.
And don't add a margin-top value to the active panel's content.

Fixes #35947.
---
 src/wp-admin/css/customize-controls.css | 8 ++++++++
 src/wp-admin/js/customize-controls.js   | 1 -
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/wp-admin/css/customize-controls.css b/src/wp-admin/css/customize-controls.css
index 82132e3..32d5827 100644
--- a/src/wp-admin/css/customize-controls.css
+++ b/src/wp-admin/css/customize-controls.css
@@ -430,6 +430,14 @@ h3.customize-section-title {
 	width: 300px;
 }
 
+.in-sub-panel #customize-info {
+	height: 0;
+}
+
+.in-sub-panel #customize-theme-controls > ul > .control-section:not(.current-panel) {
+	height: 0;
+}
+
 .in-sub-panel #customize-theme-controls .accordion-section.current-panel {
 	width: 100%;
 }
diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js
index 8fcf08b..1c1acfd 100644
--- a/src/wp-admin/js/customize-controls.js
+++ b/src/wp-admin/js/customize-controls.js
@@ -1363,7 +1363,6 @@
 					content.parent().show();
 					position = content.offset().top;
 					scroll = container.scrollTop();
-					content.css( 'margin-top', ( headerActionsHeight - position - scroll ) );
 					accordionSection.addClass( 'current-panel' );
 					overlay.addClass( 'in-sub-panel' );
 					container.scrollTop( 0 );

From 200b497d271bedc324f21262465487210164433e Mon Sep 17 00:00:00 2001
From: Ryan Kienstra <ryan.kienstra@xwp.co>
Date: Fri, 4 Mar 2016 02:16:23 -0300
Subject: [PATCH 2/6] Customize : Remove variables that were deleted in commit
 8894171.

These are no longer used in the function in which they're defined.
They were deleted as part of a commit to remove the 'margin-top' value.

Fixes #35947.
---
 src/wp-admin/js/customize-controls.js | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js
index 1c1acfd..086472b 100644
--- a/src/wp-admin/js/customize-controls.js
+++ b/src/wp-admin/js/customize-controls.js
@@ -1333,8 +1333,7 @@
 			}
 
 			// Note: there is a second argument 'args' passed
-			var position, scroll,
-				panel = this,
+			var panel = this,
 				accordionSection = panel.container.closest( '.accordion-section' ),
 				overlay = accordionSection.closest( '.wp-full-overlay' ),
 				container = accordionSection.closest( '.wp-full-overlay-sidebar-content' ),
@@ -1342,8 +1341,7 @@
 				topPanel = overlay.find( '#customize-theme-controls > ul > .accordion-section > .accordion-section-title' ),
 				backBtn = accordionSection.find( '.customize-panel-back' ),
 				panelTitle = accordionSection.find( '.accordion-section-title' ).first(),
-				content = accordionSection.find( '.control-panel-content' ),
-				headerActionsHeight = $( '#customize-header-actions' ).height();
+				content = accordionSection.find( '.control-panel-content' );
 
 			if ( expanded ) {
 
@@ -1361,8 +1359,6 @@
 
 				content.show( 0, function() {
 					content.parent().show();
-					position = content.offset().top;
-					scroll = container.scrollTop();
 					accordionSection.addClass( 'current-panel' );
 					overlay.addClass( 'in-sub-panel' );
 					container.scrollTop( 0 );

From c00e5eaf37284881a363aecefcc4b06e636ca1ba Mon Sep 17 00:00:00 2001
From: Ryan Kienstra <ryan.kienstra@xwp.co>
Date: Sat, 5 Mar 2016 01:00:12 -0300
Subject: [PATCH 3/6] Fix issue with widget's contents being too high on
 clicking in preview.

When clicking a widget in the preview, the 'onChangeExpanded' method is called.
This included a jQuery method that adds a 'margin-top' value.
Remove this method call, as it caused a spacing issue.
The inactive panels no longer occupy space, from commit 8894171c.
So there's no adjustment needed for the controls to appear properly.

Fixes #34747.
---
 src/wp-admin/js/customize-controls.js | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js
index 086472b..7fd2b54 100644
--- a/src/wp-admin/js/customize-controls.js
+++ b/src/wp-admin/js/customize-controls.js
@@ -648,8 +648,7 @@
 				overlay = section.container.closest( '.wp-full-overlay' ),
 				backBtn = section.container.find( '.customize-section-back' ),
 				sectionTitle = section.container.find( '.accordion-section-title' ).first(),
-				headerActionsHeight = $( '#customize-header-actions' ).height(),
-				resizeContentHeight, expand, position, scroll;
+				resizeContentHeight, expand;
 
 			if ( expanded && ! section.container.hasClass( 'open' ) ) {
 
@@ -671,9 +670,6 @@
 					expand = function() {
 						section.container.addClass( 'open' );
 						overlay.addClass( 'section-open' );
-						position = content.offset().top;
-						scroll = container.scrollTop();
-						content.css( 'margin-top', ( headerActionsHeight - position - scroll ) );
 						resizeContentHeight();
 						sectionTitle.attr( 'tabindex', '-1' );
 						backBtn.attr( 'tabindex', '0' );

From 334473cb0975541e7b46935caa50061ec235fd45 Mon Sep 17 00:00:00 2001
From: Piotr Delawski <piotr.delawski@xwp.co>
Date: Sat, 5 Mar 2016 16:44:44 +0100
Subject: [PATCH 4/6] Remove horizontal gap next to scrollbar when opening a
 panel (reverts previous changes by @kienstra).

---
 src/wp-admin/css/customize-controls.css |  8 --------
 src/wp-admin/js/customize-controls.js   | 27 ++++++++++++++++++---------
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/wp-admin/css/customize-controls.css b/src/wp-admin/css/customize-controls.css
index 32d5827..82132e3 100644
--- a/src/wp-admin/css/customize-controls.css
+++ b/src/wp-admin/css/customize-controls.css
@@ -430,14 +430,6 @@ h3.customize-section-title {
 	width: 300px;
 }
 
-.in-sub-panel #customize-info {
-	height: 0;
-}
-
-.in-sub-panel #customize-theme-controls > ul > .control-section:not(.current-panel) {
-	height: 0;
-}
-
 .in-sub-panel #customize-theme-controls .accordion-section.current-panel {
 	width: 100%;
 }
diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js
index 7fd2b54..3a89bb7 100644
--- a/src/wp-admin/js/customize-controls.js
+++ b/src/wp-admin/js/customize-controls.js
@@ -1329,7 +1329,8 @@
 			}
 
 			// Note: there is a second argument 'args' passed
-			var panel = this,
+			var position, scroll,
+				panel = this,
 				accordionSection = panel.container.closest( '.accordion-section' ),
 				overlay = accordionSection.closest( '.wp-full-overlay' ),
 				container = accordionSection.closest( '.wp-full-overlay-sidebar-content' ),
@@ -1337,7 +1338,8 @@
 				topPanel = overlay.find( '#customize-theme-controls > ul > .accordion-section > .accordion-section-title' ),
 				backBtn = accordionSection.find( '.customize-panel-back' ),
 				panelTitle = accordionSection.find( '.accordion-section-title' ).first(),
-				content = accordionSection.find( '.control-panel-content' );
+				content = accordionSection.find( '.control-panel-content' ),
+				headerActionsHeight = $( '#customize-header-actions' ).height();
 
 			if ( expanded ) {
 
@@ -1355,17 +1357,24 @@
 
 				content.show( 0, function() {
 					content.parent().show();
+					position = content.offset().top;
+					scroll = container.scrollTop();
+					content.css( 'margin-top', ( headerActionsHeight - position - scroll ) );
 					accordionSection.addClass( 'current-panel' );
 					overlay.addClass( 'in-sub-panel' );
 					container.scrollTop( 0 );
-					if ( args.completeCallback ) {
-						args.completeCallback();
-					}
+					_.defer( function() {
+						panel._recalculateTopMargin();
+						topPanel.attr( 'tabindex', '-1' );
+						backBtn.attr( 'tabindex', '0' );
+					});
+					_.delay( function() {
+						backBtn.focus();
+						if ( args.completeCallback ) {
+							args.completeCallback();
+						}
+					}, 180 );
 				} );
-				topPanel.attr( 'tabindex', '-1' );
-				backBtn.attr( 'tabindex', '0' );
-				backBtn.focus();
-				panel._recalculateTopMargin();
 			} else {
 				siblings.removeClass( 'open' );
 				accordionSection.removeClass( 'current-panel' );

From f0266c082fee227cf81c7d8c775e68449fe7102b Mon Sep 17 00:00:00 2001
From: Piotr Delawski <piotr.delawski@xwp.co>
Date: Sat, 5 Mar 2016 16:58:51 +0100
Subject: [PATCH 5/6] Revert c00e5ea and remove `_.defer` as it seems not be
 needed now.

---
 src/wp-admin/js/customize-controls.js | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js
index b945ce2..dbda12b 100644
--- a/src/wp-admin/js/customize-controls.js
+++ b/src/wp-admin/js/customize-controls.js
@@ -648,7 +648,8 @@
 				overlay = section.container.closest( '.wp-full-overlay' ),
 				backBtn = section.container.find( '.customize-section-back' ),
 				sectionTitle = section.container.find( '.accordion-section-title' ).first(),
-				resizeContentHeight, expand;
+				headerActionsHeight = $( '#customize-header-actions' ).height(),
+				resizeContentHeight, expand, position, scroll;
 
 			if ( expanded && ! section.container.hasClass( 'open' ) ) {
 
@@ -670,6 +671,9 @@
 					expand = function() {
 						section.container.addClass( 'open' );
 						overlay.addClass( 'section-open' );
+						position = content.offset().top;
+						scroll = container.scrollTop();
+						content.css( 'margin-top', ( headerActionsHeight - position - scroll ) );
 						resizeContentHeight();
 						sectionTitle.attr( 'tabindex', '-1' );
 						backBtn.attr( 'tabindex', '0' );
@@ -1363,11 +1367,9 @@
 					accordionSection.addClass( 'current-panel' );
 					overlay.addClass( 'in-sub-panel' );
 					container.scrollTop( 0 );
-					_.defer( function() {
-						panel._recalculateTopMargin();
-						topPanel.attr( 'tabindex', '-1' );
-						backBtn.attr( 'tabindex', '0' );
-					});
+					topPanel.attr( 'tabindex', '-1' );
+					backBtn.attr( 'tabindex', '0' );
+					panel._recalculateTopMargin();
 					_.delay( function() {
 						backBtn.focus();
 						if ( args.completeCallback ) {

From 89591f9e3c3ae42b6b1c40b350f30c51c90892fa Mon Sep 17 00:00:00 2001
From: Piotr Delawski <piotr.delawski@xwp.co>
Date: Sun, 6 Mar 2016 22:44:00 +0100
Subject: [PATCH 6/6] Remove vertical gap below list of panels when there is a
 lot of panels registered.

---
 src/wp-admin/css/customize-controls.css | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/wp-admin/css/customize-controls.css b/src/wp-admin/css/customize-controls.css
index c3b6e01..84e29f3 100644
--- a/src/wp-admin/css/customize-controls.css
+++ b/src/wp-admin/css/customize-controls.css
@@ -428,10 +428,12 @@ h3.customize-section-title {
 .in-sub-panel #customize-theme-controls > ul > .accordion-section {
 	left: -300px;
 	width: 300px;
+	height: 0;
 }
 
 .in-sub-panel #customize-theme-controls .accordion-section.current-panel {
 	width: 100%;
+	height: auto;
 }
 
 #customize-theme-controls .control-section.current-panel {
