From 5c1eb9f4f85edb702160d8c54916b09646feebec Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Mon, 13 Apr 2015 22:09:35 +0000 Subject: [PATCH] Customizer Theme Switcher: Don't re-render a theme control if it has already been rendered. Move initialization of `$customizeSidebar` to `api.ThemesSection.initialize()` to prevent cases where the result can be undefined. props westonruter, ocean90. fixes #31793. git-svn-id: https://develop.svn.wordpress.org/trunk@32119 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index aeee50f227..e211a41ff7 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -554,7 +554,14 @@ template: '', screenshotQueue: null, $window: $( window ), - $customizeSidebar: $( '.wp-full-overlay-sidebar-content:first' ), + + /** + * @since 4.2.0 + */ + initialize: function () { + this.$customizeSidebar = $( '.wp-full-overlay-sidebar-content:first' ); + return api.Section.prototype.initialize.apply( this, arguments ); + }, /** * @since 4.2.0 @@ -1951,6 +1958,7 @@ api.ThemeControl = api.Control.extend({ touchDrag: false, + isRendered: false, /** * Defer rendering the theme control until the section is displayed. @@ -1961,13 +1969,15 @@ var control = this, renderContentArgs = arguments; - api.section( control.section(), function ( section ) { + api.section( control.section(), function( section ) { if ( section.expanded() ) { api.Control.prototype.renderContent.apply( control, renderContentArgs ); + control.isRendered = true; } else { - section.expanded.bind( function ( expanded ) { - if ( expanded ) { + section.expanded.bind( function( expanded ) { + if ( expanded && ! control.isRendered ) { api.Control.prototype.renderContent.apply( control, renderContentArgs ); + control.isRendered = true; } } ); }