Customize: Fix visible edit shortcuts for wp_nav_menu() instances using the menu arg (such as in the Custom Menu widget) instead of the theme_location arg.

Also fix logic for `focus-control-for-setting` handler to focus on the first control (lowest `priority` value) associated with a given setting instead of the last control encountered when iterating over all controls, as this ensures the first control in a `nav_menu` section is focused rather than the last one.

Props westonruter, sirbrillig.
See #27403.
Fixes #39101.

Built from https://develop.svn.wordpress.org/trunk@39622


git-svn-id: http://core.svn.wordpress.org/trunk@39562 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2016-12-20 22:05:43 +00:00
parent 5b39869860
commit f7ba137f19
5 changed files with 16 additions and 11 deletions

View File

@ -5365,16 +5365,20 @@
// Focus on the control that is associated with the given setting.
api.previewer.bind( 'focus-control-for-setting', function( settingId ) {
var matchedControl;
var matchedControls = [];
api.control.each( function( control ) {
var settingIds = _.pluck( control.settings, 'id' );
if ( -1 !== _.indexOf( settingIds, settingId ) ) {
matchedControl = control;
matchedControls.push( control );
}
} );
if ( matchedControl ) {
matchedControl.focus();
// Focus on the matched control with the lowest priority (appearing higher).
if ( matchedControls.length ) {
matchedControls.sort( function( a, b ) {
return a.priority() - b.priority();
} );
matchedControls[0].focus();
}
} );

File diff suppressed because one or more lines are too long

View File

@ -312,14 +312,15 @@ wp.customize.selectiveRefresh = ( function( $, api ) {
* @since 4.5.0
*/
showControl: function() {
var partial = this, settingId = partial.params.primarySetting, menuSlug;
var partial = this, settingId = partial.params.primarySetting;
if ( ! settingId ) {
settingId = _.first( partial.settings() );
}
if ( partial.getType() === 'nav_menu' ) {
menuSlug = partial.params.navMenuArgs.theme_location;
if ( menuSlug ) {
settingId = 'nav_menu_locations[' + menuSlug + ']';
if ( partial.params.navMenuArgs.theme_location ) {
settingId = 'nav_menu_locations[' + partial.params.navMenuArgs.theme_location + ']';
} else if ( partial.params.navMenuArgs.menu ) {
settingId = 'nav_menu[' + String( partial.params.navMenuArgs.menu ) + ']';
}
}
api.preview.send( 'focus-control-for-setting', settingId );

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-39621';
$wp_version = '4.8-alpha-39622';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.