diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php
index 3d9e60f..3c19e8d 100644
|
|
|
final class WP_Customize_Nav_Menus { |
| 767 | 767 | ( empty( $args['fallback_cb'] ) || is_string( $args['fallback_cb'] ) ) |
| 768 | 768 | && |
| 769 | 769 | ( empty( $args['walker'] ) || is_string( $args['walker'] ) ) |
| | 770 | && |
| | 771 | ( |
| | 772 | ! empty( $args['theme_location'] ) |
| | 773 | || |
| | 774 | ( ! empty( $args['menu'] ) && ( is_numeric( $args['menu'] ) || is_object( $args['menu'] ) ) ) |
| | 775 | ) |
| 770 | 776 | ); |
| 771 | 777 | $args['can_partial_refresh'] = $can_partial_refresh; |
| 772 | 778 | |
| … |
… |
final class WP_Customize_Nav_Menus { |
| 775 | 781 | $args['walker'] = ''; |
| 776 | 782 | } |
| 777 | 783 | |
| | 784 | // Replace menu object with a menu_id, as this exports better to JS and is easier to compare hashes. |
| | 785 | if ( ! empty( $args['menu'] ) && is_object( $args['menu'] ) ) { |
| | 786 | $args['menu'] = $args['menu']->term_id; |
| | 787 | } |
| | 788 | |
| 778 | 789 | ksort( $args ); |
| 779 | 790 | $args['args_hash'] = $this->hash_nav_menu_args( $args ); |
| 780 | 791 | |
| … |
… |
final class WP_Customize_Nav_Menus { |
| 795 | 806 | */ |
| 796 | 807 | public function filter_wp_nav_menu( $nav_menu_content, $args ) { |
| 797 | 808 | if ( ! empty( $args->can_partial_refresh ) && ! empty( $args->instance_number ) ) { |
| 798 | | $nav_menu_content = sprintf( |
| 799 | | '<div id="partial-refresh-menu-container-%1$d" class="partial-refresh-menu-container" data-instance-number="%1$d">%2$s</div>', |
| 800 | | $args->instance_number, |
| 801 | | $nav_menu_content |
| | 809 | $nav_menu_content = preg_replace( |
| | 810 | '/(?<=class=")/', |
| | 811 | sprintf( 'partial-refreshable-nav-menu partial-refreshable-nav-menu-%1$d ', $args->instance_number ), |
| | 812 | $nav_menu_content, |
| | 813 | 1 // Only update the class on the first element found, the menu container. |
| 802 | 814 | ); |
| 803 | 815 | } |
| 804 | 816 | return $nav_menu_content; |
diff --git src/wp-includes/js/customize-preview-nav-menus.js src/wp-includes/js/customize-preview-nav-menus.js
index 2b6c994..5a22237 100644
|
|
|
wp.customize.menusPreview = ( function( $, api ) { |
| 163 | 163 | * @param {int} instanceNumber |
| 164 | 164 | */ |
| 165 | 165 | self.refreshMenuInstance = function( instanceNumber ) { |
| 166 | | var self = this, data, customized, container, request, wpNavArgs, instance; |
| | 166 | var self = this, data, menuId, customized, container, request, wpNavArgs, instance, containerInstanceClassName; |
| 167 | 167 | |
| 168 | 168 | if ( ! self.navMenuInstanceArgs[ instanceNumber ] ) { |
| 169 | 169 | throw new Error( 'unknown_instance_number' ); |
| 170 | 170 | } |
| 171 | 171 | instance = self.navMenuInstanceArgs[ instanceNumber ]; |
| 172 | 172 | |
| 173 | | container = $( '#partial-refresh-menu-container-' + String( instanceNumber ) ); |
| | 173 | containerInstanceClassName = 'partial-refreshable-nav-menu-' + String( instanceNumber ); |
| | 174 | container = $( '.' + containerInstanceClassName ); |
| 174 | 175 | |
| 175 | | if ( ! instance.can_partial_refresh || 0 === container.length ) { |
| | 176 | if ( _.isNumber( instance.menu ) ) { |
| | 177 | menuId = instance.menu; |
| | 178 | } else if ( instance.theme_location && api.has( 'nav_menu_locations[' + instance.theme_location + ']' ) ) { |
| | 179 | menuId = api( 'nav_menu_locations[' + instance.theme_location + ']' ).get(); |
| | 180 | } |
| | 181 | |
| | 182 | if ( ! menuId || ! instance.can_partial_refresh || 0 === container.length ) { |
| 176 | 183 | api.preview.send( 'refresh' ); |
| 177 | 184 | return; |
| 178 | 185 | } |
| | 186 | menuId = parseInt( menuId, 10 ); |
| 179 | 187 | |
| 180 | 188 | data = { |
| 181 | 189 | nonce: self.previewCustomizeNonce, // for Customize Preview |
| … |
… |
wp.customize.menusPreview = ( function( $, api ) { |
| 187 | 195 | data[ self.renderQueryVar ] = '1'; |
| 188 | 196 | customized = {}; |
| 189 | 197 | api.each( function( setting, id ) { |
| 190 | | // @todo We need to limit this to just the menu items that are associated with this menu/location. |
| 191 | | if ( /^(nav_menu|nav_menu_locations)/.test( id ) ) { |
| | 198 | // @todo Core should propagate the dirty state into the Preview as well so we can use that here. |
| | 199 | if ( id === 'nav_menu[' + String( menuId ) + ']' || ( /^nav_menu_item\[/.test( id ) && setting() && menuId === setting().nav_menu_term_id ) ) { |
| 192 | 200 | customized[ id ] = setting.get(); |
| 193 | 201 | } |
| 194 | 202 | } ); |
| … |
… |
wp.customize.menusPreview = ( function( $, api ) { |
| 207 | 215 | url: self.requestUri |
| 208 | 216 | } ); |
| 209 | 217 | request.done( function( data ) { |
| 210 | | var eventParam; |
| 211 | | container.empty().append( $( data ) ); |
| | 218 | // If the menu is now not visible, refresh since the page layout may have changed. |
| | 219 | if ( false === data ) { |
| | 220 | api.preview.send( 'refresh' ); |
| | 221 | return; |
| | 222 | } |
| | 223 | |
| | 224 | var eventParam, previousContainer = container; |
| | 225 | container = $( data ); |
| | 226 | container.addClass( containerInstanceClassName ); |
| | 227 | container.addClass( 'partial-refreshable-nav-menu customize-partial-refreshing' ); |
| | 228 | previousContainer.replaceWith( container ); |
| 212 | 229 | eventParam = { |
| 213 | 230 | instanceNumber: instanceNumber, |
| 214 | 231 | wpNavArgs: wpNavArgs |
| 215 | 232 | }; |
| 216 | | $( document ).trigger( 'customize-preview-menu-refreshed', [ eventParam ] ); |
| 217 | | } ); |
| 218 | | request.fail( function() { |
| 219 | | // @todo provide some indication for why |
| 220 | | } ); |
| 221 | | request.always( function() { |
| 222 | 233 | container.removeClass( 'customize-partial-refreshing' ); |
| | 234 | $( document ).trigger( 'customize-preview-menu-refreshed', [ eventParam ] ); |
| 223 | 235 | } ); |
| 224 | 236 | }; |
| 225 | 237 | |