1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
(function ($) {
|
7 |
|
|
|
8 |
|
|
Drupal.behaviors.webform = Drupal.behaviors.webform || {};
|
9 |
|
|
|
10 |
|
|
Drupal.behaviors.webform.attach = function(context) {
|
11 |
|
|
|
12 |
|
|
Drupal.webform.datepicker(context);
|
13 |
|
|
};
|
14 |
|
|
|
15 |
|
|
Drupal.webform = Drupal.webform || {};
|
16 |
|
|
|
17 |
|
|
Drupal.webform.datepicker = function(context) {
|
18 |
|
|
$('div.webform-datepicker').each(function() {
|
19 |
|
|
var $webformDatepicker = $(this);
|
20 |
|
|
var $calendar = $webformDatepicker.find('input.webform-calendar');
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
if ($calendar.length == 0) {
|
24 |
|
|
return;
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
var startDate = $calendar[0].className.replace(/.*webform-calendar-start-(\d{4}-\d{2}-\d{2}).*/, '$1').split('-');
|
28 |
|
|
var endDate = $calendar[0].className.replace(/.*webform-calendar-end-(\d{4}-\d{2}-\d{2}).*/, '$1').split('-');
|
29 |
|
|
var firstDay = $calendar[0].className.replace(/.*webform-calendar-day-(\d).*/, '$1');
|
30 |
|
|
|
31 |
|
|
startDate = new Date(startDate[0], startDate[1] - 1, startDate[2]);
|
32 |
|
|
endDate = new Date(endDate[0], endDate[1] - 1, endDate[2]);
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
if (startDate > endDate) {
|
36 |
|
|
var laterDate = startDate;
|
37 |
|
|
startDate = endDate;
|
38 |
|
|
endDate = laterDate;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
var startYear = startDate.getFullYear();
|
42 |
|
|
var endYear = endDate.getFullYear();
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
$calendar.datepicker({
|
46 |
|
|
dateFormat: 'yy-mm-dd',
|
47 |
|
|
yearRange: startYear + ':' + endYear,
|
48 |
|
|
firstDay: parseInt(firstDay),
|
49 |
|
|
minDate: startDate,
|
50 |
|
|
maxDate: endDate,
|
51 |
|
|
onSelect: function(dateText, inst) {
|
52 |
|
|
var date = dateText.split('-');
|
53 |
3753f249
|
Assos Assos
|
$webformDatepicker.find('select.year, input.year').val(+date[0]).trigger('change');
|
54 |
|
|
$webformDatepicker.find('select.month').val(+date[1]).trigger('change');
|
55 |
|
|
$webformDatepicker.find('select.day').val(+date[2]).trigger('change');
|
56 |
85ad3d82
|
Assos Assos
|
},
|
57 |
|
|
beforeShow: function(input, inst) {
|
58 |
|
|
|
59 |
|
|
var year = $webformDatepicker.find('select.year, input.year').val();
|
60 |
|
|
var month = $webformDatepicker.find('select.month').val();
|
61 |
|
|
var day = $webformDatepicker.find('select.day').val();
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
var today = new Date();
|
65 |
|
|
year = year ? year : today.getFullYear();
|
66 |
|
|
month = month ? month : today.getMonth() + 1;
|
67 |
|
|
day = day ? day : today.getDate();
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
year = (year < startYear || year > endYear) ? startYear : year;
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
$(input).val(year + '-' + month + '-' + day);
|
75 |
|
|
}
|
76 |
|
|
});
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
$calendar.click(function(event) {
|
80 |
|
|
$(this).focus();
|
81 |
|
|
event.preventDefault();
|
82 |
|
|
});
|
83 |
|
|
});
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
})(jQuery); |