3 * Attaches preview-related behavior for the Color module.
8 * Namespace for color-related functionality for Drupal.
14 * The callback for when the color preview has been attached.
16 * @param {Element} context
17 * The context to initiate the color behaviour.
18 * @param {object} settings
19 * Settings for the color functionality.
20 * @param {HTMLFormElement} form
21 * The form to initiate the color behaviour on.
22 * @param {object} farb
23 * The farbtastic object.
24 * @param {number} height
26 * @param {number} width
29 callback(context, settings, form, farb, height, width) {
34 .find('.color-preview')
37 form.find('.color-palette input[name="palette[base]"]').val(),
45 form.find('.color-palette input[name="palette[text]"]').val(),
48 .find('#text a, #text h2')
51 form.find('.color-palette input[name="palette[link]"]').val(),
54 function gradientLineColor(i, element) {
55 Object.keys(accum || {}).forEach(k => {
58 element.style.backgroundColor = farb.pack(accum);
61 // Set up gradients if there are some.
64 Object.keys(settings.gradients || {}).forEach(i => {
65 colorStart = farb.unpack(
68 `.color-palette input[name="palette[${
69 settings.gradients[i].colors[0]
74 colorEnd = farb.unpack(
77 `.color-palette input[name="palette[${
78 settings.gradients[i].colors[1]
83 if (colorStart && colorEnd) {
85 Object.keys(colorStart || {}).forEach(colorStartKey => {
86 delta[colorStartKey] =
87 (colorEnd[colorStartKey] - colorStart[colorStartKey]) /
88 (settings.gradients[i].vertical ? height[i] : width[i]);
91 // Render gradient lines.
92 form.find(`#gradient-${i} > div`).each(gradientLineColor);