preview.es6.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @file
  3. * Preview for the Bartik theme.
  4. */
  5. (function($, Drupal, drupalSettings) {
  6. Drupal.color = {
  7. logoChanged: false,
  8. callback(context, settings, $form) {
  9. // Change the logo to be the real one.
  10. if (!this.logoChanged) {
  11. $('.color-preview .color-preview-logo img').attr(
  12. 'src',
  13. drupalSettings.color.logo,
  14. );
  15. this.logoChanged = true;
  16. }
  17. // Remove the logo if the setting is toggled off.
  18. if (drupalSettings.color.logo === null) {
  19. $('div').remove('.color-preview-logo');
  20. }
  21. const $colorPreview = $form.find('.color-preview');
  22. const $colorPalette = $form.find('.js-color-palette');
  23. // Solid background.
  24. $colorPreview.css(
  25. 'backgroundColor',
  26. $colorPalette.find('input[name="palette[bg]"]').val(),
  27. );
  28. // Text preview.
  29. $colorPreview
  30. .find('.color-preview-main h2, .color-preview .preview-content')
  31. .css('color', $colorPalette.find('input[name="palette[text]"]').val());
  32. $colorPreview
  33. .find('.color-preview-content a')
  34. .css('color', $colorPalette.find('input[name="palette[link]"]').val());
  35. // Sidebar block.
  36. const $colorPreviewBlock = $colorPreview.find(
  37. '.color-preview-sidebar .color-preview-block',
  38. );
  39. $colorPreviewBlock.css(
  40. 'background-color',
  41. $colorPalette.find('input[name="palette[sidebar]"]').val(),
  42. );
  43. $colorPreviewBlock.css(
  44. 'border-color',
  45. $colorPalette.find('input[name="palette[sidebarborders]"]').val(),
  46. );
  47. // Footer wrapper background.
  48. $colorPreview
  49. .find('.color-preview-footer-wrapper')
  50. .css(
  51. 'background-color',
  52. $colorPalette.find('input[name="palette[footer]"]').val(),
  53. );
  54. // CSS3 Gradients.
  55. const gradientStart = $colorPalette
  56. .find('input[name="palette[top]"]')
  57. .val();
  58. const gradientEnd = $colorPalette
  59. .find('input[name="palette[bottom]"]')
  60. .val();
  61. $colorPreview
  62. .find('.color-preview-header')
  63. .attr(
  64. 'style',
  65. `background-color: ${gradientStart}; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(${gradientStart}), to(${gradientEnd})); background-image: -moz-linear-gradient(-90deg, ${gradientStart}, ${gradientEnd});`,
  66. );
  67. $colorPreview
  68. .find('.color-preview-site-name')
  69. .css(
  70. 'color',
  71. $colorPalette.find('input[name="palette[titleslogan]"]').val(),
  72. );
  73. },
  74. };
  75. })(jQuery, Drupal, drupalSettings);