forked from wp-premium/gravityforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatepicker.js
55 lines (48 loc) · 1.96 KB
/
datepicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
jQuery(document).ready(gformInitDatepicker);
function gformInitDatepicker() {
jQuery('.datepicker').each(function () {
var element = jQuery(this),
inputId = this.id,
optionsObj = {
yearRange: '-100:+20',
showOn: 'focus',
dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
suppressDatePicker: false,
onClose: function () {
element.focus();
var self = this;
this.suppressDatePicker = true;
setTimeout( function() {
self.suppressDatePicker = false;
}, 200 );
},
beforeShow: function( input, inst ) {
return ! this.suppressDatePicker;
}
};
if (element.hasClass('dmy')) {
optionsObj.dateFormat = 'dd/mm/yy';
} else if (element.hasClass('dmy_dash')) {
optionsObj.dateFormat = 'dd-mm-yy';
} else if (element.hasClass('dmy_dot')) {
optionsObj.dateFormat = 'dd.mm.yy';
} else if (element.hasClass('ymd_slash')) {
optionsObj.dateFormat = 'yy/mm/dd';
} else if (element.hasClass('ymd_dash')) {
optionsObj.dateFormat = 'yy-mm-dd';
} else if (element.hasClass('ymd_dot')) {
optionsObj.dateFormat = 'yy.mm.dd';
}
if (element.hasClass('datepicker_with_icon')) {
optionsObj.showOn = 'both';
optionsObj.buttonImage = jQuery('#gforms_calendar_icon_' + inputId).val();
optionsObj.buttonImageOnly = true;
}
inputId = inputId.split('_');
// allow the user to override the datepicker options object
optionsObj = gform.applyFilters('gform_datepicker_options_pre_init', optionsObj, inputId[1], inputId[2]);
element.datepicker(optionsObj);
});
}