Customizer: Use `jQuery.fn.toggle()` instead of `slideUp`/`slideDown` if panel/section/control is not inserted into DOM yet.

jQuery does nothing when calling `slideUp` on elements that are not inserted into the DOM yet, which can now be the case now when first loading the Customizer as the panels, sections and controls get dynamically inserted, see #28709.

props westonruter.
fixes #30251.
Built from https://develop.svn.wordpress.org/trunk@30307


git-svn-id: http://core.svn.wordpress.org/trunk@30306 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2014-11-11 22:37:22 +00:00
parent b250062311
commit d21799ee1f
5 changed files with 18 additions and 9 deletions

View File

@ -131,8 +131,8 @@
* @augments wp.customize.Class * @augments wp.customize.Class
*/ */
Container = api.Class.extend({ Container = api.Class.extend({
defaultActiveArguments: { duration: 'fast' }, defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
defaultExpandedArguments: { duration: 'fast' }, defaultExpandedArguments: { duration: 'fast', completeCallback: $.noop },
initialize: function ( id, options ) { initialize: function ( id, options ) {
var container = this; var container = this;
@ -217,7 +217,11 @@
*/ */
onChangeActive: function ( active, args ) { onChangeActive: function ( active, args ) {
var duration = ( 'resolved' === api.previewer.deferred.active.state() ? args.duration : 0 ); var duration = ( 'resolved' === api.previewer.deferred.active.state() ? args.duration : 0 );
if ( active ) { if ( ! $.contains( document, this.container ) ) {
// jQuery.fn.slideUp is not hiding an element if it is not in the DOM
this.container.toggle( active );
args.completeCallback();
} else if ( active ) {
this.container.stop( true, true ).slideDown( duration, args.completeCallback ); this.container.stop( true, true ).slideDown( duration, args.completeCallback );
} else { } else {
this.container.stop( true, true ).slideUp( duration, args.completeCallback ); this.container.stop( true, true ).slideUp( duration, args.completeCallback );
@ -640,7 +644,7 @@
* @augments wp.customize.Class * @augments wp.customize.Class
*/ */
api.Control = api.Class.extend({ api.Control = api.Class.extend({
defaultActiveArguments: { duration: 'fast' }, defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
initialize: function( id, options ) { initialize: function( id, options ) {
var control = this, var control = this,
@ -781,7 +785,11 @@
* @param {Object} args merged on top of this.defaultActiveArguments * @param {Object} args merged on top of this.defaultActiveArguments
*/ */
onChangeActive: function ( active, args ) { onChangeActive: function ( active, args ) {
if ( active ) { if ( ! $.contains( document, this.container ) ) {
// jQuery.fn.slideUp is not hiding an element if it is not in the DOM
this.container.toggle( active );
args.completeCallback();
} else if ( active ) {
this.container.slideDown( args.duration, args.completeCallback ); this.container.slideDown( args.duration, args.completeCallback );
} else { } else {
this.container.slideUp( args.duration, args.completeCallback ); this.container.slideUp( args.duration, args.completeCallback );

File diff suppressed because one or more lines are too long

View File

@ -405,7 +405,8 @@
*/ */
api.Widgets.WidgetControl = api.Control.extend({ api.Widgets.WidgetControl = api.Control.extend({
defaultExpandedArguments: { defaultExpandedArguments: {
duration: 'fast' duration: 'fast',
completeCallback: $.noop
}, },
initialize: function ( id, options ) { initialize: function ( id, options ) {

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.1-alpha-30306'; $wp_version = '4.1-alpha-30307';
/** /**
* 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.