diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php
index e7b7e0f..05efe43 100644
|
|
|
final class WP_Customize_Nav_Menus { |
| 768 | 768 | ( empty( $args['fallback_cb'] ) || is_string( $args['fallback_cb'] ) ) |
| 769 | 769 | && |
| 770 | 770 | ( empty( $args['walker'] ) || is_string( $args['walker'] ) ) |
| | 771 | && |
| | 772 | ( |
| | 773 | ! empty( $args['theme_location'] ) |
| | 774 | || |
| | 775 | ( ! empty( $args['menu'] ) && ( is_numeric( $args['menu'] ) || is_object( $args['menu'] ) ) ) |
| | 776 | ) |
| 771 | 777 | ); |
| 772 | 778 | $args['can_partial_refresh'] = $can_partial_refresh; |
| 773 | 779 | |
| … |
… |
final class WP_Customize_Nav_Menus { |
| 776 | 782 | $args['walker'] = ''; |
| 777 | 783 | } |
| 778 | 784 | |
| | 785 | // Replace object menu arg with a term_id menu arg, as this exports better to JS and is easier to compare hashes. |
| | 786 | if ( ! empty( $args['menu'] ) && is_object( $args['menu'] ) ) { |
| | 787 | $args['menu'] = $args['menu']->term_id; |
| | 788 | } |
| | 789 | |
| 779 | 790 | ksort( $args ); |
| 780 | 791 | $args['args_hash'] = $this->hash_nav_menu_args( $args ); |
| 781 | 792 | |
| … |
… |
final class WP_Customize_Nav_Menus { |
| 796 | 807 | */ |
| 797 | 808 | public function filter_wp_nav_menu( $nav_menu_content, $args ) { |
| 798 | 809 | if ( ! empty( $args->can_partial_refresh ) && ! empty( $args->instance_number ) ) { |
| 799 | | $nav_menu_content = sprintf( |
| 800 | | '<div id="partial-refresh-menu-container-%1$d" class="partial-refresh-menu-container" data-instance-number="%1$d">%2$s</div>', |
| 801 | | $args->instance_number, |
| 802 | | $nav_menu_content |
| | 810 | $nav_menu_content = preg_replace( |
| | 811 | '/(?<=class=")/', |
| | 812 | sprintf( 'partial-refreshable-nav-menu partial-refreshable-nav-menu-%1$d ', $args->instance_number ), |
| | 813 | $nav_menu_content, |
| | 814 | 1 // Only update the class on the first element found, the menu container. |
| 803 | 815 | ); |
| 804 | 816 | } |
| 805 | 817 | 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..d1ce558 100644
|
|
|
wp.customize.menusPreview = ( function( $, api ) { |
| 9 | 9 | renderNonceValue: null, |
| 10 | 10 | renderNoncePostKey: null, |
| 11 | 11 | previewCustomizeNonce: null, |
| 12 | | previewReady: $.Deferred(), |
| 13 | 12 | requestUri: '/', |
| 14 | 13 | theme: { |
| 15 | 14 | active: false, |
| … |
… |
wp.customize.menusPreview = ( function( $, api ) { |
| 20 | 19 | }; |
| 21 | 20 | |
| 22 | 21 | api.bind( 'preview-ready', function() { |
| 23 | | self.previewReady.resolve(); |
| 24 | | } ); |
| 25 | | self.previewReady.done( function() { |
| 26 | | self.init(); |
| | 22 | api.preview.bind( 'active', function() { |
| | 23 | self.init(); |
| | 24 | } ); |
| 27 | 25 | } ); |
| 28 | 26 | |
| 29 | 27 | /** |
| … |
… |
wp.customize.menusPreview = ( function( $, api ) { |
| 36 | 34 | $.extend( self, _wpCustomizePreviewNavMenusExports ); |
| 37 | 35 | } |
| 38 | 36 | |
| 39 | | self.previewReady.done( function() { |
| 40 | | api.each( function( setting, id ) { |
| 41 | | setting.id = id; |
| 42 | | self.bindListener( setting ); |
| 43 | | } ); |
| | 37 | api.each( function( setting, id ) { |
| | 38 | setting.id = id; |
| | 39 | self.bindListener( setting ); |
| | 40 | } ); |
| 44 | 41 | |
| 45 | | api.preview.bind( 'setting', function( args ) { |
| 46 | | var id, value, setting; |
| 47 | | args = args.slice(); |
| 48 | | id = args.shift(); |
| 49 | | value = args.shift(); |
| 50 | | if ( ! api.has( id ) ) { |
| 51 | | // Currently customize-preview.js is not creating settings for dynamically-created settings in the pane; so we have to do it |
| 52 | | setting = api.create( id, value ); // @todo This should be in core |
| 53 | | setting.id = id; |
| 54 | | if ( self.bindListener( setting ) ) { |
| 55 | | setting.callbacks.fireWith( setting, [ setting(), setting() ] ); |
| 56 | | } |
| | 42 | api.preview.bind( 'setting', function( args ) { |
| | 43 | var id, value, setting; |
| | 44 | args = args.slice(); |
| | 45 | id = args.shift(); |
| | 46 | value = args.shift(); |
| | 47 | if ( ! api.has( id ) ) { |
| | 48 | // Currently customize-preview.js is not creating settings for dynamically-created settings in the pane; so we have to do it |
| | 49 | setting = api.create( id, value ); // @todo This should be in core |
| | 50 | setting.id = id; |
| | 51 | if ( self.bindListener( setting ) ) { |
| | 52 | setting.callbacks.fireWith( setting, [ setting(), null ] ); |
| 57 | 53 | } |
| 58 | | } ); |
| | 54 | } |
| 59 | 55 | } ); |
| 60 | 56 | }; |
| 61 | 57 | |
| … |
… |
wp.customize.menusPreview = ( function( $, api ) { |
| 163 | 159 | * @param {int} instanceNumber |
| 164 | 160 | */ |
| 165 | 161 | self.refreshMenuInstance = function( instanceNumber ) { |
| 166 | | var self = this, data, customized, container, request, wpNavArgs, instance; |
| | 162 | var self = this, data, menuId, customized, container, request, wpNavArgs, instance, containerInstanceClassName; |
| 167 | 163 | |
| 168 | 164 | if ( ! self.navMenuInstanceArgs[ instanceNumber ] ) { |
| 169 | 165 | throw new Error( 'unknown_instance_number' ); |
| 170 | 166 | } |
| 171 | 167 | instance = self.navMenuInstanceArgs[ instanceNumber ]; |
| 172 | 168 | |
| 173 | | container = $( '#partial-refresh-menu-container-' + String( instanceNumber ) ); |
| | 169 | containerInstanceClassName = 'partial-refreshable-nav-menu-' + String( instanceNumber ); |
| | 170 | container = $( '.' + containerInstanceClassName ); |
| 174 | 171 | |
| 175 | | if ( ! instance.can_partial_refresh || 0 === container.length ) { |
| | 172 | if ( _.isNumber( instance.menu ) ) { |
| | 173 | menuId = instance.menu; |
| | 174 | } else if ( instance.theme_location && api.has( 'nav_menu_locations[' + instance.theme_location + ']' ) ) { |
| | 175 | menuId = api( 'nav_menu_locations[' + instance.theme_location + ']' ).get(); |
| | 176 | } |
| | 177 | |
| | 178 | if ( ! menuId || ! instance.can_partial_refresh || 0 === container.length ) { |
| 176 | 179 | api.preview.send( 'refresh' ); |
| 177 | 180 | return; |
| 178 | 181 | } |
| | 182 | menuId = parseInt( menuId, 10 ); |
| 179 | 183 | |
| 180 | 184 | data = { |
| 181 | 185 | nonce: self.previewCustomizeNonce, // for Customize Preview |
| … |
… |
wp.customize.menusPreview = ( function( $, api ) { |
| 187 | 191 | data[ self.renderQueryVar ] = '1'; |
| 188 | 192 | customized = {}; |
| 189 | 193 | 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 ) ) { |
| | 194 | // @todo Core should propagate the dirty state into the Preview as well so we can use that here. |
| | 195 | if ( id === 'nav_menu[' + String( menuId ) + ']' || ( /^nav_menu_item\[/.test( id ) && setting() && menuId === setting().nav_menu_term_id ) ) { |
| 192 | 196 | customized[ id ] = setting.get(); |
| 193 | 197 | } |
| 194 | 198 | } ); |
| … |
… |
wp.customize.menusPreview = ( function( $, api ) { |
| 207 | 211 | url: self.requestUri |
| 208 | 212 | } ); |
| 209 | 213 | request.done( function( data ) { |
| 210 | | var eventParam; |
| 211 | | container.empty().append( $( data ) ); |
| | 214 | // If the menu is now not visible, refresh since the page layout may have changed. |
| | 215 | if ( false === data ) { |
| | 216 | api.preview.send( 'refresh' ); |
| | 217 | return; |
| | 218 | } |
| | 219 | |
| | 220 | var eventParam, previousContainer = container; |
| | 221 | container = $( data ); |
| | 222 | container.addClass( containerInstanceClassName ); |
| | 223 | container.addClass( 'partial-refreshable-nav-menu customize-partial-refreshing' ); |
| | 224 | previousContainer.replaceWith( container ); |
| 212 | 225 | eventParam = { |
| 213 | 226 | instanceNumber: instanceNumber, |
| 214 | | wpNavArgs: wpNavArgs |
| | 227 | wpNavArgs: wpNavArgs, |
| | 228 | oldContainer: previousContainer, |
| | 229 | newContainer: container |
| 215 | 230 | }; |
| 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 | 231 | container.removeClass( 'customize-partial-refreshing' ); |
| | 232 | $( document ).trigger( 'customize-preview-menu-refreshed', [ eventParam ] ); |
| 223 | 233 | } ); |
| 224 | 234 | }; |
| 225 | 235 | |