preview.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @file
  3. * Attaches preview-related behavior for the Color module.
  4. */
  5. (function ($) {
  6. Drupal.color = {
  7. callback: function(context, settings, form, farb, height, width) {
  8. // Solid background.
  9. $('#preview', form).css('backgroundColor', $('#palette input[name="palette[base]"]', form).val());
  10. // Text preview
  11. $('#text', form).css('color', $('#palette input[name="palette[text]"]', form).val());
  12. $('#text a, #text h2', form).css('color', $('#palette input[name="palette[link]"]', form).val());
  13. // Set up gradients if there are some.
  14. var color_start, color_end;
  15. for (i in settings.gradients) {
  16. color_start = farb.unpack($('#palette input[name="palette[' + settings.gradients[i]['colors'][0] + ']"]', form).val());
  17. color_end = farb.unpack($('#palette input[name="palette[' + settings.gradients[i]['colors'][1] + ']"]', form).val());
  18. if (color_start && color_end) {
  19. var delta = [];
  20. for (j in color_start) {
  21. delta[j] = (color_end[j] - color_start[j]) / (settings.gradients[i]['vertical'] ? height[i] : width[i]);
  22. }
  23. var accum = color_start;
  24. // Render gradient lines.
  25. $('#gradient-' + i + ' > div', form).each(function () {
  26. for (j in accum) {
  27. accum[j] += delta[j];
  28. }
  29. this.style.backgroundColor = farb.pack(accum);
  30. });
  31. }
  32. }
  33. }
  34. };
  35. })(jQuery);