Projet

Général

Profil

Paste
Télécharger (1,88 ko) Statistiques
| Branche: | Révision:

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

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
          break;
18

    
19
        case 'timeEntry':
20
          $(this)
21
            .timeEntry(datePopup.settings)
22
            .addClass('date-popup-init');
23
          $(this).click(function(){
24
            $(this).focus();
25
          });
26
          break;
27

    
28
        case 'timepicker':
29
          // Translate the PHP date format into the style the timepicker uses.
30
          datePopup.settings.timeFormat = datePopup.settings.timeFormat
31
            // 12-hour, leading zero,
32
            .replace('h', 'hh')
33
            // 12-hour, no leading zero.
34
            .replace('g', 'h')
35
            // 24-hour, leading zero.
36
            .replace('H', 'HH')
37
            // 24-hour, no leading zero.
38
            .replace('G', 'H')
39
            // AM/PM.
40
            .replace('A', 'p')
41
            // Minutes with leading zero.
42
            .replace('i', 'mm')
43
            // Seconds with leading zero.
44
            .replace('s', 'ss');
45

    
46
          datePopup.settings.startTime = new Date(datePopup.settings.startTime);
47
          $(this)
48
            .timepicker(datePopup.settings)
49
            .addClass('date-popup-init');
50
          $(this).click(function(){
51
            $(this).focus();
52
          });
53
          break;
54
      }
55
    }
56
  }
57

    
58
  Drupal.behaviors.date_popup = {
59
    attach: function (context) {
60
      for (var id in Drupal.settings.datePopup) {
61
        $('#'+ id).bind('focus', Drupal.settings.datePopup[id], makeFocusHandler);
62
      }
63
    }
64
  };
65
})(jQuery);