wpcom-customize-preview.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * File wpcom-customize-preview.js.
  3. *
  4. * Instantly live-update customizer settings in the preview for improved user experience,
  5. * targeting the updates needed to hide the page title on the homepage on WordPress.com.
  6. */
  7. ( function( $ ) {
  8. // Hide Front Page Title
  9. wp.customize( 'hide_front_page_title', function( value ) {
  10. value.bind( function( to ) {
  11. if ( true === to ) {
  12. $( 'body' ).addClass( 'hide-homepage-title' );
  13. } else {
  14. $( 'body' ).removeClass( 'hide-homepage-title' );
  15. }
  16. } );
  17. } );
  18. // Since the plugin handles customizer preview updates via the postMessage transport,
  19. // we need to manually override the "extra CSS" when a user selects a different color palette.
  20. wp.customize( 'colors_manager[colors]', function( value ) {
  21. value.bind( function( to ) {
  22. const { bg, fg1, fg2 } = to;
  23. const extraCSS = `/*
  24. * Site title text shadow.
  25. */
  26. .site-title a {
  27. background-image: linear-gradient(to right, ${ fg1 } 100%, transparent 100%);
  28. text-shadow: 1px 0px ${ bg },
  29. -1px 0px ${ bg },
  30. -2px 0px ${ bg },
  31. 2px 0px ${ bg },
  32. -3px 0px ${ bg },
  33. 3px 0px ${ bg },
  34. -4px 0px ${ bg },
  35. 4px 0px ${ bg },
  36. -5px 0px ${ bg },
  37. 5px 0px ${ bg };
  38. }
  39. /*
  40. * Custom gradients.
  41. */
  42. .has-hard-diagonal-gradient-background {
  43. background: linear-gradient(to bottom right, ${ fg1 } 49.9%, ${ fg2 } 50%);
  44. }
  45. .has-hard-diagonal-inverted-gradient-background {
  46. background: linear-gradient(to top left, ${ fg1 } 49.9%, ${ fg2 } 50%);
  47. }
  48. .has-diagonal-gradient-background {
  49. background: linear-gradient(to bottom right, ${ fg1 }, ${ fg2 });
  50. }
  51. .has-diagonal-inverted-gradient-background {
  52. background: linear-gradient(to top left, ${ fg1 }, ${ fg2 });
  53. }
  54. .has-hard-horizontal-gradient-background {
  55. background: linear-gradient(to bottom, ${ fg1 } 50%, ${ fg2 } 50%);
  56. }
  57. .has-hard-horizontal-inverted-gradient-background {
  58. background: linear-gradient(to top, ${ fg1 } 50%, ${ fg2 } 50%);
  59. }
  60. .has-horizontal-gradient-background {
  61. background: linear-gradient(to bottom, ${ fg1 }, ${ fg2 });
  62. }
  63. .has-horizontal-inverted-gradient-background {
  64. background: linear-gradient(to top, ${ fg1 }, ${ fg2 });
  65. }
  66. .has-stripe-gradient-background {
  67. background: linear-gradient(to bottom, transparent 20%, ${ fg1 } 20%, ${ fg1 } 80%, transparent 80%);
  68. }`;
  69. // Append an extra style element that overrides the previous extra CSS
  70. if ( $('#custom-colors-extra-css').length ) {
  71. $( '#custom-colors-extra-css' ).html( extraCSS );
  72. } else {
  73. $( 'head' ).append( `<style id="custom-colors-extra-css">${ extraCSS }</style>` );
  74. }
  75. } );
  76. } );
  77. } )( jQuery );