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
56
57
58
59
60
61
|
jQuery.fn.pwgDatepicker = function(options) {
options = options || {};
return this.each(function() {
var $this = jQuery(this),
$target = jQuery('[name="'+ jQuery(this).data('datepicker') +'"]'),
value = $target.val().split('-');
function set(date) {
$this.datepicker('setDate', date);
if ($this.data('datepicker-start')) {
$start.datepicker('option', 'maxDate', date);
}
else if ($this.data('datepicker-end')) {
$end.datepicker('option', 'minDate', date);
}
}
// init picker
$this.datepicker(jQuery.extend({
dateFormat: 'DD d MM yy',
altField: $target,
altFormat: 'yy-mm-dd',
autoSize: true,
changeMonth : true,
changeYear: true
}, options));
// attach linked picker (for ranges)
if ($this.data('datepicker-start')) {
var $start = jQuery('[data-datepicker="'+ jQuery(this).data('datepicker-start') +'"]');
$this.datepicker('option', 'onClose', function(date) {
$start.datepicker('option', 'maxDate', date);
});
}
else if ($this.data('datepicker-end')) {
var $end = jQuery('[data-datepicker="'+ jQuery(this).data('datepicker-end') +'"]');
$this.datepicker('option', 'onClose', function(date) {
$end.datepicker('option', 'minDate', date);
});
}
// attach unset button
if ($this.data('datepicker-unset')) {
jQuery('#'+ $this.data('datepicker-unset')).on('click', function(e) {
e.preventDefault();
$target.val('');
set(null);
});
}
// set value from linked input
if (value.length == 3) {
set(new Date(value[0], value[1]-1, value[2]));
}
});
};
|