Projet

Général

Profil

Paste
Télécharger (2,23 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / date / date_popup / date_popup.js @ ee46a8ed

1
/**
2
 * Attaches the calendar behavior to all required fields
3
 */
4
(function($) {
5
  function makeFocusHandler(e) {
6
    if (!$(this).hasClass('date-popup-init')) {
7
      var datePopup = e.data;
8
      // Explicitely filter the methods we accept.
9
      switch (datePopup.func) {
10
        case 'datepicker':
11
          $(this)
12
            .datepicker(datePopup.settings)
13
            .addClass('date-popup-init');
14
          $(this).click(function(){
15
            $(this).focus();
16
          });
17
          if (datePopup.settings.syncEndDate) {
18
            $('.start-date-wrapper').each(function(){
19
              var start_date_wrapper = this;
20
              $(this).find('input:eq(0)').change(function(){
21
                $(start_date_wrapper).next('.end-date-wrapper').find('input:eq(0)').val($(this).val());
22
              });
23
            });
24
          }
25
          break;
26

    
27
        case 'timeEntry':
28
          $(this)
29
            .timeEntry(datePopup.settings)
30
            .addClass('date-popup-init');
31
          $(this).click(function(){
32
            $(this).focus();
33
          });
34
          break;
35

    
36
        case 'timepicker':
37
          // Translate the PHP date format into the style the timepicker uses.
38
          datePopup.settings.timeFormat = datePopup.settings.timeFormat
39
            // 12-hour, leading zero,
40
            .replace('h', 'hh')
41
            // 12-hour, no leading zero.
42
            .replace('g', 'h')
43
            // 24-hour, leading zero.
44
            .replace('H', 'HH')
45
            // 24-hour, no leading zero.
46
            .replace('G', 'H')
47
            // AM/PM.
48
            .replace('A', 'p')
49
            // Minutes with leading zero.
50
            .replace('i', 'mm')
51
            // Seconds with leading zero.
52
            .replace('s', 'ss');
53

    
54
          datePopup.settings.startTime = new Date(datePopup.settings.startTime);
55
          $(this)
56
            .timepicker(datePopup.settings)
57
            .addClass('date-popup-init');
58
          $(this).click(function(){
59
            $(this).focus();
60
          });
61
          break;
62
      }
63
    }
64
  }
65

    
66
  Drupal.behaviors.date_popup = {
67
    attach: function (context) {
68
      for (var id in Drupal.settings.datePopup) {
69
        $('#'+ id).bind('focus', Drupal.settings.datePopup[id], makeFocusHandler);
70
      }
71
    }
72
  };
73
})(jQuery);