customizer.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * File customizer.js.
  3. *
  4. * Theme Customizer enhancements for a better user experience.
  5. *
  6. * Contains handlers to make Theme Customizer preview reload changes asynchronously.
  7. */
  8. ( function( $ ) {
  9. // Collect information from panel-customizer.js about which panels are opening
  10. wp.customize.bind( 'preview-ready', function() {
  11. wp.customize.preview.bind( 'section-highlight', function( data ) {
  12. // If there's an expanded panel section, scroll down to that panel & highlight in the preview
  13. if ( true === data.expanded ) {
  14. $.scrollTo( $( '.' + data.section ), {
  15. duration: 600,
  16. offset: { 'top': -40 }
  17. } );
  18. $( '.' + data.section ).addClass( 'lodestar-highlight' );
  19. // If we've left the panel, remove the highlight and scroll back to the top
  20. } else {
  21. $.scrollTo( $( '#masthead' ), {
  22. duration: 300,
  23. offset: { 'top': 0 }
  24. } );
  25. $( '.' + data.section ).removeClass( 'lodestar-highlight' );
  26. }
  27. } );
  28. } );
  29. // Site title and description.
  30. wp.customize( 'blogname', function( value ) {
  31. value.bind( function( to ) {
  32. $( '.site-title a' ).text( to );
  33. } );
  34. } );
  35. wp.customize( 'blogdescription', function( value ) {
  36. value.bind( function( to ) {
  37. $( '.site-description' ).text( to );
  38. } );
  39. } );
  40. // Header text color.
  41. wp.customize( 'header_textcolor', function( value ) {
  42. value.bind( function( to ) {
  43. if ( 'blank' === to ) {
  44. $( '.site-title a, .site-description' ).css( {
  45. 'clip': 'rect(1px, 1px, 1px, 1px)',
  46. 'position': 'absolute'
  47. } );
  48. } else {
  49. $( '.site-title a, .site-description' ).css( {
  50. 'clip': 'auto',
  51. 'position': 'relative'
  52. } );
  53. $( '.site-title a, .site-description' ).css( {
  54. 'color': to
  55. } );
  56. }
  57. } );
  58. } );
  59. } )( jQuery );