From ccbd8550211d87108a8df470cc1aa6178c6059ac Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 8 Jul 2015 20:41:18 +0000 Subject: [PATCH] Customizer: Defer listening to nav menu setting changes until active. Defer the preview starting to listen to setting changes until after the Customizer has synced settings into the preview. This ensures that any differences between the JS and PHP representations of the settings won't cause an infinite refresh. See #32911. Fixes #32894. git-svn-id: https://develop.svn.wordpress.org/trunk@33134 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/customize-preview-nav-menus.js | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/wp-includes/js/customize-preview-nav-menus.js b/src/wp-includes/js/customize-preview-nav-menus.js index 2b6c9949fe..ce962d63f4 100644 --- a/src/wp-includes/js/customize-preview-nav-menus.js +++ b/src/wp-includes/js/customize-preview-nav-menus.js @@ -9,7 +9,6 @@ wp.customize.menusPreview = ( function( $, api ) { renderNonceValue: null, renderNoncePostKey: null, previewCustomizeNonce: null, - previewReady: $.Deferred(), requestUri: '/', theme: { active: false, @@ -20,10 +19,9 @@ wp.customize.menusPreview = ( function( $, api ) { }; api.bind( 'preview-ready', function() { - self.previewReady.resolve(); - } ); - self.previewReady.done( function() { - self.init(); + api.preview.bind( 'active', function() { + self.init(); + } ); } ); /** @@ -36,26 +34,24 @@ wp.customize.menusPreview = ( function( $, api ) { $.extend( self, _wpCustomizePreviewNavMenusExports ); } - self.previewReady.done( function() { - api.each( function( setting, id ) { - setting.id = id; - self.bindListener( setting ); - } ); + api.each( function( setting, id ) { + setting.id = id; + self.bindListener( setting ); + } ); - api.preview.bind( 'setting', function( args ) { - var id, value, setting; - args = args.slice(); - id = args.shift(); - value = args.shift(); - if ( ! api.has( id ) ) { - // Currently customize-preview.js is not creating settings for dynamically-created settings in the pane; so we have to do it - setting = api.create( id, value ); // @todo This should be in core - setting.id = id; - if ( self.bindListener( setting ) ) { - setting.callbacks.fireWith( setting, [ setting(), setting() ] ); - } + api.preview.bind( 'setting', function( args ) { + var id, value, setting; + args = args.slice(); + id = args.shift(); + value = args.shift(); + if ( ! api.has( id ) ) { + // Currently customize-preview.js is not creating settings for dynamically-created settings in the pane; so we have to do it + setting = api.create( id, value ); // @todo This should be in core + setting.id = id; + if ( self.bindListener( setting ) ) { + setting.callbacks.fireWith( setting, [ setting(), null ] ); } - } ); + } } ); };