Projet

Général

Profil

Paste
Télécharger (979 octets) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / calendar / js / calendar_colorpicker.js @ 62e0cc08

1
/**
2
 * Implementation of hook_elements.
3
 *
4
 * Much of the colorpicker code was adapted from the Colorpicker module.
5
 * That module has no stable release yet nor any D6 branch.
6
 */
7
/*
8
 *  Bind the colorpicker event to the form element
9
 */
10
(function ($) {
11
  Drupal.behaviors.field_example_colorpicker = {
12
    attach: function(context) {
13

    
14
      if ($.isFunction($.fn.on)) {
15
        // For jQuery 1.7+
16
        $(document).on("focus", ".edit-calendar-colorpicker", calendarFocusHandler);
17
      } else {
18
        $(".edit-calendar-colorpicker").live("focus", calendarFocusHandler);
19
      }
20

    
21
    }
22
  }
23

    
24
  function calendarFocusHandler(event) {
25
    var edit_field = this;
26
    var picker = $(this).closest('div').parent().find(".calendar-colorpicker");
27

    
28
    // Hide all color pickers except this one.
29
    $(".calendar-colorpicker").hide();
30
    $(picker).show();
31
    $.farbtastic(picker, function(color) {
32
      edit_field.value = color;
33
    }).setColor(edit_field.value);
34
  }
35
})(jQuery);
36