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:
Weston Ruter
2016-03-01 22:04:27 +00:00
parent dfadc557b6
commit 94b59e7f0d
4 changed files with 19 additions and 26 deletions

View File

@@ -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