customizer.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 ( $( '.' + data.section ).length ) {
  13. // If there's an expanded panel section, scroll down to that panel & highlight in the preview
  14. if ( true === data.expanded ) {
  15. $( 'body' ).animate( {
  16. scrollTop: $( '.' + data.section ).offset().top - $( '.header-wrapper' ).outerHeight(), //Accounts for fixed header height
  17. }, 600 );
  18. $( '.' + data.section ).addClass( 'affinity-highlight' );
  19. // If we've left the panel, remove the highlight and scroll back to the top
  20. } else {
  21. $( 'body' ).animate( {
  22. scrollTop: 0,
  23. }, 600 );
  24. $( '.' + data.section ).removeClass( 'affinity-highlight' );
  25. }
  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 a' ).css( {
  54. 'color': to
  55. } );
  56. }
  57. } );
  58. } );
  59. // Header overlay opacity.
  60. wp.customize( 'affinity_overlay', function( value ) {
  61. value.bind( function( to ) {
  62. $( '.custom-header-image' ).css( {
  63. 'opacity': to,
  64. } );
  65. } );
  66. } );
  67. // Display the excerpt when Blog Display is set to Full post
  68. wp.customize( 'jetpack_content_blog_display', function( value ) {
  69. value.bind( function( to ) {
  70. // make sure we're not on a single page
  71. if ( ! $( 'body.hfeed' ).length ) return;
  72. if ( 'content' == to ){
  73. if ( $( '.entry-summary' ).length ) {
  74. $( '.entry-summary' ).show();
  75. } else {
  76. $( '.entry-content' ).each( function() {
  77. var the_excerpt = $( this + ' .jetpack-the-excerpt' ).html()
  78. // add an excerpt to each article
  79. $( this ).prepend( the_excerpt );
  80. });
  81. }
  82. } else {
  83. $( '.entry-summary' ).hide();
  84. }
  85. } );
  86. } );
  87. /* Featured Images background attachment.
  88. * Disabled because the Customizer doesn't like fixed-position backgrounds
  89. wp.customize( 'affinity_scrolling', function( value ) {
  90. value.bind( function( to ) {
  91. if ( 1 == to ) {
  92. $( '.custom-header-image' ).css( 'background-attachment', 'fixed' );
  93. } else {
  94. $( '.custom-header-image' ).css( 'background-attachment', 'scroll' );
  95. }
  96. } );
  97. } );*/
  98. } )( jQuery );