customizer.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. /* global wp */
  9. ( function( $ ) {
  10. // Blog name
  11. wp.customize( 'blogname', function( value ) {
  12. value.bind( function( to ) {
  13. $( '.site-title a' ).text( to );
  14. });
  15. });
  16. // Blog description
  17. wp.customize( 'blogdescription', function( value ) {
  18. value.bind( function( to ) {
  19. $( '.site-description' ).text( to );
  20. });
  21. });
  22. // Header text display
  23. wp.customize( 'header_textcolor', function( value ) {
  24. value.bind( function( to ) {
  25. // if header text display is set to false
  26. if ( 'blank' === to ) {
  27. $( '.site-identity, .site-title, .site-description' ).css({
  28. clip: 'rect(1px, 1px, 1px, 1px)',
  29. position: 'absolute'
  30. });
  31. $( 'body' ).addClass( 'hide-site-title-description' );
  32. } else {
  33. $( '.site-identity, .site-title, .site-description' ).css({
  34. clip: 'auto',
  35. position: 'relative'
  36. });
  37. // Update body class.
  38. $( 'body' ).removeClass( 'hide-site-title-description' );
  39. }
  40. });
  41. });
  42. // Background colour
  43. wp.customize( 'background_color', function( value ) {
  44. value.bind( function( to ) {
  45. if ( '' === to ) {
  46. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-color: #ffffff; }</style>' ).appendTo( 'head' );
  47. } else {
  48. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-color: ' + to + '; }</style>' ).appendTo( 'head' );
  49. }
  50. });
  51. });
  52. // Background image
  53. wp.customize( 'background_image', function( value ) {
  54. value.bind( function( to ) {
  55. if ( '' === to ) {
  56. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-image: inherit; }</style>' ).appendTo( 'head' );
  57. } else {
  58. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-image: url("' + to + '"); }</style>' ).appendTo( 'head' );
  59. }
  60. });
  61. });
  62. // Background position X
  63. wp.customize( 'background_position_x', function( value ) {
  64. value.bind( function( to ) {
  65. if ( '' === to ) {
  66. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-position-x: inherit; }</style>' ).appendTo( 'head' );
  67. } else {
  68. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-position-x: ' + to + '; }</style>' ).appendTo( 'head' );
  69. }
  70. });
  71. });
  72. // Background position Y
  73. wp.customize( 'background_position_y', function( value ) {
  74. value.bind( function( to ) {
  75. if ( '' === to ) {
  76. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-position-y: inherit; }</style>' ).appendTo( 'head' );
  77. } else {
  78. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-position-y: ' + to + '; }</style>' ).appendTo( 'head' );
  79. }
  80. });
  81. });
  82. // Background size
  83. wp.customize( 'background_size', function( value ) {
  84. value.bind( function( to ) {
  85. if ( '' === to ) {
  86. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-size: inherit; }</style>' ).appendTo( 'head' );
  87. } else {
  88. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-size: ' + to + '; }</style>' ).appendTo( 'head' );
  89. }
  90. });
  91. });
  92. // Background repeat
  93. wp.customize( 'background_repeat', function( value ) {
  94. value.bind( function( to ) {
  95. if ( '' === to ) {
  96. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-repeat: inherit; }</style>' ).appendTo( 'head' );
  97. } else {
  98. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-repeat: ' + to + '; }</style>' ).appendTo( 'head' );
  99. }
  100. });
  101. });
  102. // Background attachment
  103. wp.customize( 'background_attachment', function( value ) {
  104. value.bind( function( to ) {
  105. if ( '' === to ) {
  106. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-attachment: inherit; }</style>' ).appendTo( 'head' );
  107. // Make sure background images with 'scroll' background-attachment display properly
  108. } else if ( 'scroll' === to ) {
  109. $( '<style>html { background-attachment: ' + to + '; } body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-image: none !important; background-color: transparent !important; }</style>' ).appendTo( 'head' );
  110. } else {
  111. $( '<style>html, body.custom-background, .site-header, .site-content, .single .entry-media, .widget-area, .top-navigation > div { background-attachment: ' + to + '; }</style>' ).appendTo( 'head' );
  112. }
  113. });
  114. });
  115. } )( jQuery );