3 * Attaches preview-related behavior for the Color module.
6 (function ($, Drupal) {
11 * Namespace for color-related functionality for Drupal.
18 * The callback for when the color preview has been attached.
20 * @param {Element} context
21 * The context to initiate the color behaviour.
22 * @param {object} settings
23 * Settings for the color functionality.
24 * @param {HTMLFormElement} form
25 * The form to initiate the color behaviour on.
26 * @param {object} farb
27 * The farbtastic object.
28 * @param {number} height
30 * @param {number} width
33 callback: function (context, settings, form, farb, height, width) {
37 form.find('.color-preview').css('backgroundColor', form.find('.color-palette input[name="palette[base]"]').val());
40 form.find('#text').css('color', form.find('.color-palette input[name="palette[text]"]').val());
41 form.find('#text a, #text h2').css('color', form.find('.color-palette input[name="palette[link]"]').val());
43 function gradientLineColor(i, element) {
44 for (var k in accum) {
45 if (accum.hasOwnProperty(k)) {
49 element.style.backgroundColor = farb.pack(accum);
52 // Set up gradients if there are some.
55 for (var i in settings.gradients) {
56 if (settings.gradients.hasOwnProperty(i)) {
57 color_start = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[0] + ']"]').val());
58 color_end = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[1] + ']"]').val());
59 if (color_start && color_end) {
61 for (var j in color_start) {
62 if (color_start.hasOwnProperty(j)) {
63 delta[j] = (color_end[j] - color_start[j]) / (settings.gradients[i].vertical ? height[i] : width[i]);
67 // Render gradient lines.
68 form.find('#gradient-' + i + ' > div').each(gradientLineColor);