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.

git-svn-id: https://develop.svn.wordpress.org/trunk@30307 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2014-11-11 22:36:51 +00:00
parent 63642323a5
commit 3b3be684e8
2 changed files with 15 additions and 6 deletions

View File

@ -131,8 +131,8 @@
* @augments wp.customize.Class
*/
Container = api.Class.extend({
defaultActiveArguments: { duration: 'fast' },
defaultExpandedArguments: { duration: 'fast' },
defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
defaultExpandedArguments: { duration: 'fast', completeCallback: $.noop },
initialize: function ( id, options ) {
var container = this;
@ -217,7 +217,11 @@
*/
onChangeActive: function ( active, args ) {
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 );
} else {
this.container.stop( true, true ).slideUp( duration, args.completeCallback );
@ -640,7 +644,7 @@
* @augments wp.customize.Class
*/
api.Control = api.Class.extend({
defaultActiveArguments: { duration: 'fast' },
defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
initialize: function( id, options ) {
var control = this,
@ -781,7 +785,11 @@
* @param {Object} args merged on top of this.defaultActiveArguments
*/
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 );
} else {
this.container.slideUp( args.duration, args.completeCallback );

View File

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