Customize: Fix deep-linking to sections for themes via `autofocus[section]` query parameter.

* Expand containing panel when expanding themes section.
* Consolidate UI changes related to a section's expanded state change.
* Prevent collapsing current section when expanding.
* Auto-expand first themes section when expanding panel if one is not expanded already.

See #37661, #42354.
Fixes #42360.

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


git-svn-id: http://core.svn.wordpress.org/trunk@41867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-10-28 05:22:46 +00:00
parent 615a9afab8
commit 9dca5ae189
3 changed files with 40 additions and 12 deletions

View File

@ -1887,6 +1887,17 @@
api.section( 'wporg_themes' ).focus(); api.section( 'wporg_themes' ).focus();
}); });
function updateSelectedState() {
var el = section.headerContainer.find( '.customize-themes-section-title' );
el.toggleClass( 'selected', section.expanded() );
el.attr( 'aria-expanded', section.expanded() ? 'true' : 'false' );
if ( ! section.expanded() ) {
el.removeClass( 'details-open' );
}
}
section.expanded.bind( updateSelectedState );
updateSelectedState();
// Move section controls to the themes area. // Move section controls to the themes area.
api.bind( 'ready', function () { api.bind( 'ready', function () {
section.contentContainer = section.container.find( '.customize-themes-section' ); section.contentContainer = section.container.find( '.customize-themes-section' );
@ -1920,7 +1931,7 @@
return; return;
} }
if ( expanded ) { function expand() {
// Try to load controls if none are loaded yet. // Try to load controls if none are loaded yet.
if ( 0 === section.loaded ) { if ( 0 === section.loaded ) {
@ -1949,14 +1960,13 @@
section.filterSearch( searchTerm ); section.filterSearch( searchTerm );
} }
} }
otherSection.collapse( { duration: args.duration } );
} }
otherSection.collapse( { duration: args.duration } );
} }
}); });
section.contentContainer.addClass( 'current-section' ); section.contentContainer.addClass( 'current-section' );
container.scrollTop(); container.scrollTop();
section.headerContainer.find( '.customize-themes-section-title' ).addClass( 'selected' ).attr( 'aria-expanded', 'true' );
container.on( 'scroll', _.throttle( section.renderScreenshots, 300 ) ); container.on( 'scroll', _.throttle( section.renderScreenshots, 300 ) );
container.on( 'scroll', _.throttle( section.loadMore, 300 ) ); container.on( 'scroll', _.throttle( section.loadMore, 300 ) );
@ -1965,11 +1975,21 @@
args.completeCallback(); args.completeCallback();
} }
section.updateCount(); // Show this section's count. section.updateCount(); // Show this section's count.
}
if ( expanded ) {
if ( section.panel() && api.panel.has( section.panel() ) ) {
api.panel( section.panel() ).expand({
duration: args.duration,
completeCallback: expand
});
} else {
expand();
}
} else { } else {
section.contentContainer.removeClass( 'current-section' ); section.contentContainer.removeClass( 'current-section' );
// Always hide, even if they don't exist or are already hidden. // Always hide, even if they don't exist or are already hidden.
section.headerContainer.find( '.customize-themes-section-title' ).removeClass( 'selected details-open' ).attr( 'aria-expanded', 'false' );
section.headerContainer.find( '.filter-details' ).slideUp( 180 ); section.headerContainer.find( '.filter-details' ).slideUp( 180 );
container.off( 'scroll' ); container.off( 'scroll' );
@ -3058,7 +3078,7 @@
* @returns {void} * @returns {void}
*/ */
onChangeExpanded: function( expanded, args ) { onChangeExpanded: function( expanded, args ) {
var panel = this, overlay; var panel = this, overlay, sections, hasExpandedSection = false;
// Expand/collapse the panel normally. // Expand/collapse the panel normally.
api.Panel.prototype.onChangeExpanded.apply( this, [ expanded, args ] ); api.Panel.prototype.onChangeExpanded.apply( this, [ expanded, args ] );
@ -3082,9 +3102,17 @@
overlay.addClass( 'themes-panel-expanded' ); overlay.addClass( 'themes-panel-expanded' );
}, 200 ); }, 200 );
// Automatically open the installed themes section (except on small screens). // Automatically open the first section (except on small screens), if one isn't already expanded.
if ( 600 < window.innerWidth ) { if ( 600 < window.innerWidth ) {
api.section( 'installed_themes' ).expand(); sections = panel.sections();
_.each( sections, function( section ) {
if ( section.expanded() ) {
hasExpandedSection = true;
}
} );
if ( ! hasExpandedSection && sections.length > 0 ) {
sections[0].expand();
}
} }
} else { } else {
overlay overlay

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-beta4-42032'; $wp_version = '4.9-beta4-42033';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.