I am pretty weak with understanding the Customizer javascript API but I am trying. I have done a few things but now I need to send data to the Customizer preview based on the click of a control in the Customizer.
When a control is clicked in the Customizer, the class ".invisible" is applied to the control. Based on this, I want to hide <section class="about_me"></section>
on the website. The control's value is this class. How do I do this? Here is what I've tried:
api('gm_sortable_sections', function(setting) {
var section = setting.get(); // aka section.about_me
setting.bind(function onChange(){
api.control('gm_sortable_sections', function(control) {
control.sectionToHide = api.previewer.preview.container.find('.' + section);
control.sortableContainer = $(control.container).find('ul.sortable' ).first();
control.sortableContainer.find( 'li' ).each( function() {
if ( $( this ).is( '.invisible' ) ) {
console.log(control.sectionToHide);
control.sectionToHide.addClass('.invisible');
// api.previewer.send( 'sortable-visible');
// $('section.'+ section).addClass('.invisible');
}
});
});
});
});
I've managed to figure out how to get the ".invisible" value from the control but how do I then send this and update the CSS or add the class to the section in the preview (and then actually update the website to save this theme_mod_).