wpcom-customize-preview.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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, txt, link } = to;
  23. const extraCSS = `
  24. :root {
  25. --global--color-background: ${ bg };
  26. --global--color-foreground: ${ txt };
  27. --global--color-primary: ${ link };
  28. --global--color-secondary: ${ fg1 };
  29. --global--color-tertiary: ${ fg2 };
  30. }
  31. .site-title a {
  32. background-image: linear-gradient(to right, ${ fg1 } 100%, transparent 100%);
  33. text-shadow: 1px 0px ${ bg },
  34. -1px 0px ${ bg },
  35. -2px 0px ${ bg },
  36. 2px 0px ${ bg },
  37. -3px 0px ${ bg },
  38. 3px 0px ${ bg },
  39. -4px 0px ${ bg },
  40. 4px 0px ${ bg },
  41. -5px 0px ${ bg },
  42. 5px 0px ${ bg };
  43. }
  44. /*
  45. * Custom gradients.
  46. */
  47. .has-hard-diagonal-gradient-background {
  48. background: linear-gradient(to bottom right, ${ fg1 } 49.9%, ${ fg2 } 50%);
  49. }
  50. .has-hard-diagonal-inverted-gradient-background {
  51. background: linear-gradient(to top left, ${ fg1 } 49.9%, ${ fg2 } 50%);
  52. }
  53. .has-diagonal-gradient-background {
  54. background: linear-gradient(to bottom right, ${ fg1 }, ${ fg2 });
  55. }
  56. .has-diagonal-inverted-gradient-background {
  57. background: linear-gradient(to top left, ${ fg1 }, ${ fg2 });
  58. }
  59. .has-hard-horizontal-gradient-background {
  60. background: linear-gradient(to bottom, ${ fg1 } 50%, ${ fg2 } 50%);
  61. }
  62. .has-hard-horizontal-inverted-gradient-background {
  63. background: linear-gradient(to top, ${ fg1 } 50%, ${ fg2 } 50%);
  64. }
  65. .has-horizontal-gradient-background {
  66. background: linear-gradient(to bottom, ${ fg1 }, ${ fg2 });
  67. }
  68. .has-horizontal-inverted-gradient-background {
  69. background: linear-gradient(to top, ${ fg1 }, ${ fg2 });
  70. }
  71. .has-stripe-gradient-background {
  72. background: linear-gradient(to bottom, transparent 20%, ${ fg1 } 20%, ${ fg1 } 80%, transparent 80%);
  73. }`;
  74. // Append an extra style element that overrides the previous extra CSS
  75. if ( $('#custom-colors-extra-css').length ) {
  76. $( '#custom-colors-extra-css' ).html( extraCSS );
  77. } else {
  78. $( 'head' ).append( `<style id="custom-colors-extra-css">${ extraCSS }</style>` );
  79. }
  80. } );
  81. } );
  82. } )( jQuery );