Skip to content

Instantly share code, notes, and snippets.

@Fab1en
Created October 27, 2014 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fab1en/d9366450c18f90f8ffe8 to your computer and use it in GitHub Desktop.
Save Fab1en/d9366450c18f90f8ffe8 to your computer and use it in GitHub Desktop.
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