2 * File customize-preview.js.
4 * Instantly live-update customizer settings in the preview for improved user experience.
9 // Collect information from customize-controls.js about which panels are opening.
10 wp.customize.bind( 'preview-ready', function() {
12 // Initially hide the theme option placeholders on load
13 $( '.panel-placeholder' ).hide();
15 wp.customize.preview.bind( 'section-highlight', function( data ) {
17 // Only on the front page.
18 if ( ! $( 'body' ).hasClass( 'twentyseventeen-front-page' ) ) {
22 // When the section is expanded, show and scroll to the content placeholders, exposing the edit links.
23 if ( true === data.expanded ) {
24 $( 'body' ).addClass( 'highlight-front-sections' );
25 $( '.panel-placeholder' ).slideDown( 200, function() {
26 $.scrollTo( $( '#panel1' ), {
28 offset: { 'top': -70 } // Account for sticky menu.
32 // If we've left the panel, hide the placeholders and scroll back to the top.
34 $( 'body' ).removeClass( 'highlight-front-sections' );
35 // Don't change scroll when leaving - it's likely to have unintended consequences.
36 $( '.panel-placeholder' ).slideUp( 200 );
41 // Site title and description.
42 wp.customize( 'blogname', function( value ) {
43 value.bind( function( to ) {
44 $( '.site-title a' ).text( to );
47 wp.customize( 'blogdescription', function( value ) {
48 value.bind( function( to ) {
49 $( '.site-description' ).text( to );
54 wp.customize( 'header_textcolor', function( value ) {
55 value.bind( function( to ) {
56 if ( 'blank' === to ) {
57 $( '.site-title, .site-description' ).css({
58 clip: 'rect(1px, 1px, 1px, 1px)',
61 // Add class for different logo styles if title and description are hidden.
62 $( 'body' ).addClass( 'title-tagline-hidden' );
65 // Check if the text color has been removed and use default colors in theme stylesheet.
67 $( '#twentyseventeen-custom-header-styles' ).remove();
69 $( '.site-title, .site-description' ).css({
73 $( '.site-branding, .site-branding a, .site-description, .site-description a' ).css({
76 // Add class for different logo styles if title and description are visible.
77 $( 'body' ).removeClass( 'title-tagline-hidden' );
83 wp.customize( 'colorscheme', function( value ) {
84 value.bind( function( to ) {
86 // Update color body class.
88 .removeClass( 'colors-light colors-dark colors-custom' )
89 .addClass( 'colors-' + to );
94 wp.customize( 'colorscheme_hue', function( value ) {
95 value.bind( function( to ) {
97 // Update custom color CSS.
98 var style = $( '#custom-theme-colors' ),
99 hue = style.data( 'hue' ),
102 // Equivalent to css.replaceAll, with hue followed by comma to prevent values with units from being changed.
103 css = css.split( hue + ',' ).join( to + ',' );
104 style.html( css ).data( 'hue', to );
109 wp.customize( 'page_layout', function( value ) {
110 value.bind( function( to ) {
111 if ( 'one-column' === to ) {
112 $( 'body' ).addClass( 'page-one-column' ).removeClass( 'page-two-column' );
114 $( 'body' ).removeClass( 'page-one-column' ).addClass( 'page-two-column' );
119 // Whether a header image is available.
120 function hasHeaderImage() {
121 var image = wp.customize( 'header_image' )();
122 return '' !== image && 'remove-header' !== image;
125 // Whether a header video is available.
126 function hasHeaderVideo() {
127 var externalVideo = wp.customize( 'external_header_video' )(),
128 video = wp.customize( 'header_video' )();
130 return '' !== externalVideo || ( 0 !== video && '' !== video );
133 // Toggle a body class if a custom header exists.
134 $.each( [ 'external_header_video', 'header_image', 'header_video' ], function( index, settingId ) {
135 wp.customize( settingId, function( setting ) {
136 setting.bind(function() {
137 if ( hasHeaderImage() ) {
138 $( document.body ).addClass( 'has-header-image' );
140 $( document.body ).removeClass( 'has-header-image' );
143 if ( ! hasHeaderVideo() ) {
144 $( document.body ).removeClass( 'has-header-video' );