Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP Customizer : click to edit posts
// 1) Bind click events in the preview iframe.
(function( exports, $ ){
var api = wp.customize;
api.controlConstructor.myCustomControl = api.Control.extend({
ready: function() {
var control = this;
// wait for the preview iframe to be ready
var timer = setInterval(function(){
if(control.previewer.preview && control.previewer.preview.iframe && control.previewer.preview.iframe[0].contentDocument) {
clearInterval(timer);
// get iframe document
var doc = control.previewer.preview.iframe[0].contentDocument;
// bind events using doc
}
}, 200);
}
});
})( wp, jQuery );
// 2) Reveal the correct panel
// old version
var $section = control.container.closest('.accordion-section');
if(!$section.hasClass('open')){
$section.find('h3').click();
}
// new API version
wp.customize.section(control.section()).expand();
// simpler version ?
control.section.expand();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.