New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Customizer options based on context #228

Merged
merged 4 commits into from Apr 28, 2014
@@ -0,0 +1,3 @@
.control-section[id^=accordion-section-largo_] {
display:none;
}
Copy path View file
@@ -39,6 +39,9 @@ private function load() {
private function setup_actions() {
add_action( 'customize_register', array( $this, 'action_customize_register' ) );
add_action( 'customize_preview_init', array( $this, 'action_customize_preview_init' ) );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'action_customize_controls_enqueue_scripts' ) );
}
@@ -211,6 +214,48 @@ public function action_customize_register( $wp_customize ) {
}
/**
* Add contextual information when the Customizer is loaded
*/
public function action_customize_preview_init() {
add_action( 'wp_footer', array( $this, 'action_preview_wp_footer' ) );
}
/**
* Enqueue scripts and styles specific to the Largo Customizer
*/
public function action_customize_controls_enqueue_scripts() {
wp_enqueue_script( 'largo-customizer', get_template_directory_uri() . '/inc/customizer/js/customizer.js', array( 'jquery' ) );
wp_enqueue_style( 'largo-customizer', get_template_directory_uri() . '/inc/customizer/css/customizer.css' );
}
/**
* Customizer settings based on context
*/
public function action_preview_wp_footer() {
$settings = array(
'hidden_sections' => array(),
);
if ( ! is_home() ) {
$settings['hidden_sections'][] = 'largo_homepage';
}
?>
<script type="text/javascript">
var _wplargoCustomizerPreviewSettings = <?php echo json_encode( $settings ); ?>;
if ( typeof window.parent.largoCustomizerPreviewSettings == 'function' ) {
window.parent.largoCustomizerPreviewSettings( _wplargoCustomizerPreviewSettings );
}
</script>
<?php
}
/**
* Filter customizer values to use our existing settings framework
*
Copy path View file
@@ -0,0 +1,19 @@
/**
* Called from inside the iframe
*/
function largoCustomizerPreviewSettings( settings ) {
var sections = [ 'largo_homepage', 'largo_footer_layout', 'largo_colors' ];
// Show the sections that should appear on this view
jQuery.each( sections, function( index, value ){
if ( -1 == settings.hidden_sections.indexOf( value ) ) {
jQuery('#accordion-section-'+value).slideDown('fast');
} else {
jQuery('#accordion-section-'+value).slideUp('fast');
}
});
}
ProTip! Use n and p to navigate between commits in a pull request.