Last active
February 11, 2017 03:55
-
-
Save westonruter/324f294d4e6907382fdcf68fc24f0e63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Watch for the first expansion of each added panel. | |
var logPanelFirstExpanded = function( panel ) { | |
var onceExpanded, onExpandedChange; | |
if ( ! panel.extended( wp.customize.Posts.PostsPanel ) ) { | |
return; | |
} | |
onceExpanded = function() { | |
console.info( 'Panel "%s" expanded! You should now lazy-load your controls if needed.', panel.id ); | |
}; | |
if ( panel.expanded.get() ) { | |
onceExpanded( panel ); // Already expanded so no need for onExpandedChange. | |
} else { | |
onExpandedChange = function( isExpanded ) { | |
if ( isExpanded ) { | |
panel.expanded.unbind( onExpandedChange ); // Value#unbind(). | |
onceExpanded( panel ); | |
} | |
}; | |
panel.expanded.bind( onExpandedChange ); // Value#bind(). | |
} | |
}; | |
// Watch any panels already added. | |
wp.customize.panel.each( logPanelFirstExpanded ); | |
// Watch for panels newly added. | |
wp.customize.panel.bind( 'add', logPanelFirstExpanded ); // Events#bind(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment