root / drupal7 / sites / all / modules / date / date_popup / date_popup.js @ 599a39cd
1 |
/**
|
---|---|
2 |
* @file
|
3 |
* Attaches the calendar behavior to all required fields.
|
4 |
*/
|
5 |
|
6 |
(function($) { |
7 |
function makeFocusHandler(e) { |
8 |
if (!$(this).hasClass('date-popup-init')) { |
9 |
var datePopup = e.data;
|
10 |
// Explicitely filter the methods we accept.
|
11 |
switch (datePopup.func) {
|
12 |
case 'datepicker': |
13 |
$(this) |
14 |
.datepicker(datePopup.settings) |
15 |
.addClass('date-popup-init')
|
16 |
.focus(); |
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 |
.focus(); |
32 |
break;
|
33 |
|
34 |
case 'timepicker': |
35 |
// Translate the PHP date format into the style the timepicker uses.
|
36 |
datePopup.settings.timeFormat = datePopup.settings.timeFormat |
37 |
// 12-hour, leading zero,
|
38 |
.replace('h', 'hh') |
39 |
// 12-hour, no leading zero.
|
40 |
.replace('g', 'h') |
41 |
// 24-hour, leading zero.
|
42 |
.replace('H', 'HH') |
43 |
// 24-hour, no leading zero.
|
44 |
.replace('G', 'H') |
45 |
// AM/PM.
|
46 |
.replace('A', 'p') |
47 |
// Minutes with leading zero.
|
48 |
.replace('i', 'mm') |
49 |
// Seconds with leading zero.
|
50 |
.replace('s', 'ss'); |
51 |
|
52 |
datePopup.settings.startTime = new Date(datePopup.settings.startTime);
|
53 |
$(this) |
54 |
.timepicker(datePopup.settings) |
55 |
.addClass('date-popup-init')
|
56 |
.focus(); |
57 |
break;
|
58 |
} |
59 |
} |
60 |
} |
61 |
|
62 |
Drupal.behaviors.date_popup = { |
63 |
attach: function (context) { |
64 |
for (var id in Drupal.settings.datePopup) { |
65 |
$('#' + id).bind('focus', Drupal.settings.datePopup[id], makeFocusHandler); |
66 |
} |
67 |
} |
68 |
}; |
69 |
|
70 |
})(jQuery); |