From 556ec207f12da71aca788a1d3d98b317c97407d9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 27 Jun 2015 19:58:41 +0000 Subject: [PATCH] Customizer: Improve previewing setting changes for `show_on_front`, `page_on_front`, and `page_for_posts`. When changing the `page_on_front` setting (with `show_on_front`), change the previewed URL to be the home URL so that the effect can be seen. When changing `page_for_posts`, change the previewed URL to be the selected page. Props valendesigns, westonruter. Fixes #30677. git-svn-id: https://develop.svn.wordpress.org/trunk@32976 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 1a088cab84..5d3b635175 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -3210,6 +3210,27 @@ }); }); + // Change previewed URL to the homepage when changing the page_on_front. + api( 'show_on_front', 'page_on_front', function( showOnFront, pageOnFront ) { + var updatePreviewUrl = function() { + if ( showOnFront() === 'page' && parseInt( pageOnFront(), 10 ) > 0 ) { + api.previewer.previewUrl.set( api.settings.url.home ); + } + }; + showOnFront.bind( updatePreviewUrl ); + pageOnFront.bind( updatePreviewUrl ); + }); + + // Change the previewed URL to the selected page when changing the page_for_posts. + api( 'page_for_posts', function( setting ) { + setting.bind(function( pageId ) { + pageId = parseInt( pageId, 10 ); + if ( pageId > 0 ) { + api.previewer.previewUrl.set( api.settings.url.home + '?page_id=' + pageId ); + } + }); + }); + api.trigger( 'ready' ); // Make sure left column gets focus