Created
October 27, 2014 09:14
-
-
Save Fab1en/d9366450c18f90f8ffe8 to your computer and use it in GitHub Desktop.
WP Customizer : click to edit posts
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
// 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