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