Customize: Ensure autofocus deep-linking applies for dynamically-created panels, sections, and controls.
Removes overly-zealous filtering of autofocus panels, sections, and controls which are unrecognized or for which the user doesn't have the capability to focus (in which case it would no-op anyway). Also defers autofocus logic until instances are created, even after initial `ready` event. This ensures that autofocus can apply for any panels, sections, or controls that get created via the loaded preview. See #28650. Fixes #36018. Built from https://develop.svn.wordpress.org/trunk@36796 git-svn-id: http://core.svn.wordpress.org/trunk@36763 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
dfadc557b6
commit
94b59e7f0d
|
@ -3468,18 +3468,25 @@
|
|||
});
|
||||
|
||||
// Focus the autofocused element
|
||||
_.each( [ 'panel', 'section', 'control' ], function ( type ) {
|
||||
var instance, id = api.settings.autofocus[ type ];
|
||||
if ( id && api[ type ]( id ) ) {
|
||||
instance = api[ type ]( id );
|
||||
// Wait until the element is embedded in the DOM
|
||||
instance.deferred.embedded.done( function () {
|
||||
// Wait until the preview has activated and so active panels, sections, controls have been set
|
||||
api.previewer.deferred.active.done( function () {
|
||||
_.each( [ 'panel', 'section', 'control' ], function( type ) {
|
||||
var id = api.settings.autofocus[ type ];
|
||||
if ( ! id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Defer focus until:
|
||||
* 1. The panel, section, or control exists (especially for dynamically-created ones).
|
||||
* 2. The instance is embedded in the document (and so is focusable).
|
||||
* 3. The preview has finished loading so that the active states have been set.
|
||||
*/
|
||||
api[ type ]( id, function( instance ) {
|
||||
instance.deferred.embedded.done( function() {
|
||||
api.previewer.deferred.active.done( function() {
|
||||
instance.focus();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1728,7 +1728,7 @@ final class WP_Customize_Manager {
|
|||
'panels' => array(),
|
||||
'sections' => array(),
|
||||
'nonce' => $this->get_nonces(),
|
||||
'autofocus' => array(),
|
||||
'autofocus' => $this->get_autofocus(),
|
||||
'documentTitleTmpl' => $this->get_document_title_template(),
|
||||
'previewableDevices' => $this->get_previewable_devices(),
|
||||
'selectiveRefreshEnabled' => isset( $this->selective_refresh ),
|
||||
|
@ -1753,20 +1753,6 @@ final class WP_Customize_Manager {
|
|||
}
|
||||
}
|
||||
|
||||
// Pass to front end the Customizer construct being deeplinked.
|
||||
foreach ( $this->get_autofocus() as $type => $id ) {
|
||||
$can_autofocus = (
|
||||
( 'control' === $type && $this->get_control( $id ) && $this->get_control( $id )->check_capabilities() )
|
||||
||
|
||||
( 'section' === $type && isset( $settings['sections'][ $id ] ) )
|
||||
||
|
||||
( 'panel' === $type && isset( $settings['panels'][ $id ] ) )
|
||||
);
|
||||
if ( $can_autofocus ) {
|
||||
$settings['autofocus'][ $type ] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.5-beta1-36795';
|
||||
$wp_version = '4.5-beta1-36796';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue