Make WordPress Core

Changeset 36796


Ignore:
Timestamp:
03/01/2016 10:03:27 PM (11 years ago)
Author:
westonruter
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-controls.js

    r36709 r36796  
    34693469
    34703470                // Focus the autofocused element
    3471                 _.each( [ 'panel', 'section', 'control' ], function ( type ) {
    3472                         var instance, id = api.settings.autofocus[ type ];
    3473                         if ( id && api[ type ]( id ) ) {
    3474                                 instance = api[ type ]( id );
    3475                                 // Wait until the element is embedded in the DOM
    3476                                 instance.deferred.embedded.done( function () {
    3477                                         // Wait until the preview has activated and so active panels, sections, controls have been set
    3478                                         api.previewer.deferred.active.done( function () {
     3471                _.each( [ 'panel', 'section', 'control' ], function( type ) {
     3472                        var id = api.settings.autofocus[ type ];
     3473                        if ( ! id ) {
     3474                                return;
     3475                        }
     3476
     3477                        /*
     3478                         * Defer focus until:
     3479                         * 1. The panel, section, or control exists (especially for dynamically-created ones).
     3480                         * 2. The instance is embedded in the document (and so is focusable).
     3481                         * 3. The preview has finished loading so that the active states have been set.
     3482                         */
     3483                        api[ type ]( id, function( instance ) {
     3484                                instance.deferred.embedded.done( function() {
     3485                                        api.previewer.deferred.active.done( function() {
    34793486                                                instance.focus();
    34803487                                        });
    34813488                                });
    3482                         }
     3489                        });
    34833490                });
    34843491
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r36776 r36796  
    17291729                        'sections' => array(),
    17301730                        'nonce'    => $this->get_nonces(),
    1731                         'autofocus' => array(),
     1731                        'autofocus' => $this->get_autofocus(),
    17321732                        'documentTitleTmpl' => $this->get_document_title_template(),
    17331733                        'previewableDevices' => $this->get_previewable_devices(),
     
    17511751                                        }
    17521752                                }
    1753                         }
    1754                 }
    1755 
    1756                 // Pass to front end the Customizer construct being deeplinked.
    1757                 foreach ( $this->get_autofocus() as $type => $id ) {
    1758                         $can_autofocus = (
    1759                                 ( 'control' === $type && $this->get_control( $id ) && $this->get_control( $id )->check_capabilities() )
    1760                                 ||
    1761                                 ( 'section' === $type && isset( $settings['sections'][ $id ] ) )
    1762                                 ||
    1763                                 ( 'panel' === $type && isset( $settings['panels'][ $id ] ) )
    1764                         );
    1765                         if ( $can_autofocus ) {
    1766                                 $settings['autofocus'][ $type ] = $id;
    17671753                        }
    17681754                }
Note: See TracChangeset for help on using the changeset viewer.