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. git-svn-id: https://develop.svn.wordpress.org/trunk@39622 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
130adf0dc2
commit
460c358859
|
@ -5365,16 +5365,20 @@
|
||||||
|
|
||||||
// Focus on the control that is associated with the given setting.
|
// Focus on the control that is associated with the given setting.
|
||||||
api.previewer.bind( 'focus-control-for-setting', function( settingId ) {
|
api.previewer.bind( 'focus-control-for-setting', function( settingId ) {
|
||||||
var matchedControl;
|
var matchedControls = [];
|
||||||
api.control.each( function( control ) {
|
api.control.each( function( control ) {
|
||||||
var settingIds = _.pluck( control.settings, 'id' );
|
var settingIds = _.pluck( control.settings, 'id' );
|
||||||
if ( -1 !== _.indexOf( settingIds, settingId ) ) {
|
if ( -1 !== _.indexOf( settingIds, settingId ) ) {
|
||||||
matchedControl = control;
|
matchedControls.push( control );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if ( matchedControl ) {
|
// Focus on the matched control with the lowest priority (appearing higher).
|
||||||
matchedControl.focus();
|
if ( matchedControls.length ) {
|
||||||
|
matchedControls.sort( function( a, b ) {
|
||||||
|
return a.priority() - b.priority();
|
||||||
|
} );
|
||||||
|
matchedControls[0].focus();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -312,14 +312,15 @@ wp.customize.selectiveRefresh = ( function( $, api ) {
|
||||||
* @since 4.5.0
|
* @since 4.5.0
|
||||||
*/
|
*/
|
||||||
showControl: function() {
|
showControl: function() {
|
||||||
var partial = this, settingId = partial.params.primarySetting, menuSlug;
|
var partial = this, settingId = partial.params.primarySetting;
|
||||||
if ( ! settingId ) {
|
if ( ! settingId ) {
|
||||||
settingId = _.first( partial.settings() );
|
settingId = _.first( partial.settings() );
|
||||||
}
|
}
|
||||||
if ( partial.getType() === 'nav_menu' ) {
|
if ( partial.getType() === 'nav_menu' ) {
|
||||||
menuSlug = partial.params.navMenuArgs.theme_location;
|
if ( partial.params.navMenuArgs.theme_location ) {
|
||||||
if ( menuSlug ) {
|
settingId = 'nav_menu_locations[' + partial.params.navMenuArgs.theme_location + ']';
|
||||||
settingId = 'nav_menu_locations[' + menuSlug + ']';
|
} else if ( partial.params.navMenuArgs.menu ) {
|
||||||
|
settingId = 'nav_menu[' + String( partial.params.navMenuArgs.menu ) + ']';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
api.preview.send( 'focus-control-for-setting', settingId );
|
api.preview.send( 'focus-control-for-setting', settingId );
|
||||||
|
|
Loading…
Reference in New Issue