Skip to content
Snippets Groups Projects
Commit 47bb5142 authored by Karen Stevenson's avatar Karen Stevenson
Browse files

Get colorpicker working again with an assist from the Examples module Field example.

parent ba4bf0ca
No related branches found
Tags 7.x-3.0-alpha1
No related merge requests found
......@@ -15,6 +15,7 @@ Version 7.x-3.0-alpha1
Initial release of 7.3 branch.
- Get colorpicker working again with an assist from the Examples module Field example.
- Issue #1227128 The ical feed needs to have a '.ics' extension on it.
- The ical icon was not attaching to block views.
- The row plugin needs to clone the node before altering it, or other views on the same page that use the same node will acquire things like the 'date_id' that the row plugin is setting.
......
......@@ -224,7 +224,7 @@ function calendar_remove($view_name) {
/**
* Check to make sure the user has entered a valid 6 digit hex color.
*/
function calendar_validate_hex_color($element) {
function calendar_validate_hex_color($element, &$form_state) {
if (!$element['#required'] && empty($element['#value'])) {
return;
}
......@@ -232,6 +232,6 @@ function calendar_validate_hex_color($element) {
form_error($element, "'". check_plain($element['#value']) ."'". t(' is not a valid hex color'));
}
else {
form_set_value($element, $element['#value']);
form_set_value($element, $element['#value'], $form_state);
}
}
......@@ -95,11 +95,19 @@ class calendar_plugin_row_node extends views_plugin_row {
'#default_value' => isset($colors[$key]) ? $colors[$key] : '#ffffff',
'#size' => 7,
'#maxlength' => 7,
'#attributes' => array('class' => array('calendar-colors-colorpicker')),
'#element_validate' => array('calendar_validate_hex_color'),
'#dependency' => array('edit-row-options-colors-legend' => array('type')),
'#prefix' => '<div style="float:left;margin-right:10px">',
'#suffix' => '</div>',
'#prefix' => '<div class="calendar-colorpicker-wrapper">',
'#suffix' => '<div class="calendar-colorpicker"></div></div>',
'#attributes' => array('class' => array('edit-calendar-colorpicker')),
'#attached' => array(
// Add Farbtastic color picker.
'library' => array(
array('system', 'farbtastic'),
),
// Add javascript to trigger the colorpicker.
'js' => array(drupal_get_path('module', 'calendar') . '/js/calendar_colorpicker.js'),
),
);
}
......@@ -116,11 +124,8 @@ class calendar_plugin_row_node extends views_plugin_row {
'#default_value' => $this->options['colors']['taxonomy_field'],
'#description' => t("Select the taxonomy term field to use when setting stripe colors."),
'#options' => $vocab_field_options,
'#attributes' => array('class' => array('calendar-colors-colorpicker')),
'#element_validate' => array('calendar_validate_hex_color'),
'#dependency' => array('edit-row-options-colors-legend' => array('taxonomy')),
'#prefix' => '<div style="float:left;margin-right:10px">',
'#suffix' => '</div>',
);
if (empty($vocab_field_options)) {
$form['colors']['taxonomy_field']['#options'] = array('' => '');
......@@ -156,11 +161,20 @@ class calendar_plugin_row_node extends views_plugin_row {
'#size' => 7,
'#maxlength' => 7,
'#access' => !empty($field_options),
'#attributes' => array('class' => array('calendar-colors-colorpicker')),
'#element_validate' => array('calendar_validate_hex_color'),
'#dependency' => array('edit-row-options-colors-legend' => array('taxonomy')),
'#prefix' => '<div style="float:left;margin-right:10px">',
'#suffix' => '</div>',
'#element_validate' => array('calendar_validate_hex_color'),
'#dependency' => array('edit-row-options-colors-legend' => array('type')),
'#prefix' => '<div class="calendar-colorpicker-wrapper">',
'#suffix' => '<div class="calendar-colorpicker"></div></div>',
'#attributes' => array('class' => array('edit-calendar-colorpicker')),
'#attached' => array(
// Add Farbtastic color picker.
'library' => array(
array('system', 'farbtastic'),
),
// Add javascript to trigger the colorpicker.
'js' => array(drupal_get_path('module', 'calendar') . '/js/calendar_colorpicker.js'),
),
);
}
}
......@@ -173,10 +187,19 @@ class calendar_plugin_row_node extends views_plugin_row {
'#type' => 'textfield',
'#default_value' => isset($colors_group[$gid]) ? $colors_group[$gid] : '#ffffff',
'#dependency' => array('edit-row-options-colors-legend' => array('group')),
'#attributes' => array('class' => array('calendar-colors-colorpicker')),
'#element_validate' => array('calendar_validate_hex_color'),
'#prefix' => '<div style="float:left;margin-right:10px">',
'#suffix' => '</div>',
'#dependency' => array('edit-row-options-colors-legend' => array('type')),
'#prefix' => '<div class="calendar-colorpicker-wrapper">',
'#suffix' => '<div class="calendar-colorpicker"></div></div>',
'#attributes' => array('class' => array('edit-calendar-colorpicker')),
'#attached' => array(
// Add Farbtastic color picker.
'library' => array(
array('system', 'farbtastic'),
),
// Add javascript to trigger the colorpicker.
'js' => array(drupal_get_path('module', 'calendar') . '/js/calendar_colorpicker.js'),
),
);
}
}
......
......@@ -8,34 +8,20 @@
* Bind the colorpicker event to the form element
*/
(function ($) {
Drupal.behaviors.calendarColorpicker = {
attach: function (context) {
// do we have multiple calendar_colors?
if ($("div.calendar_colorpicker").size() > 0) {
// loop over each calendar_color type
$("div.calendar_colorpicker").each(function() {
// create the farbtastic colorpicker
var farb = $.farbtastic(this);
// get the id of the current matched colorpicker wrapper div
var id = $(this).attr("id");
// get the calendar_color_textfields associated with this calendar_color
$("input.calendar_colorfield").filter("." + id).each(function () {
// set the background colors of all of the textfields appropriately
farb.linkTo(this);
// when clicked, they get linked to the farbtastic colorpicker that they are associated with
$(this).click(function () {
farb.linkTo(this);
Drupal.behaviors.field_example_colorpicker = {
attach: function(context) {
$(".edit-calendar-colorpicker").live("focus", function(event) {
var edit_field = this;
var picker = $(this).closest('div').parent().find(".calendar-colorpicker");
// Hide all color pickers except this one.
$(".calendar-colorpicker").hide();
$(picker).show();
$.farbtastic(picker, function(color) {
edit_field.value = color;
}).setColor(edit_field.value);
});
});
});
}
}
}
};
})(jQuery);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment