source: trunk/admin/themes/default/js/datepicker.js @ 28497

Last change on this file since 28497 was 28497, checked in by mistic100, 10 years ago

feature 3080 : simpler date inputs (one input + fontello + picker selects)

File size: 1.7 KB
Line 
1jQuery.fn.pwgDatepicker = function(options) {
2  options = options || {};
3 
4  return this.each(function() {
5    var $this = jQuery(this),
6        $target = jQuery('[name="'+ jQuery(this).data('datepicker') +'"]'),
7        value = $target.val().split('-');
8   
9    function set(date) {
10      $this.datepicker('setDate', date);
11     
12      if ($this.data('datepicker-start')) {
13        $start.datepicker('option', 'maxDate', date);
14      }
15      else if ($this.data('datepicker-end')) {
16        $end.datepicker('option', 'minDate', date);
17      }
18    }
19
20    // init picker
21    $this.datepicker(jQuery.extend({
22      dateFormat: 'DD d MM yy',
23      altField: $target,
24      altFormat: 'yy-mm-dd',
25      autoSize: true,
26      changeMonth : true,
27      changeYear: true
28    }, options));
29   
30    // attach linked picker (for ranges)
31    if ($this.data('datepicker-start')) {
32      var $start = jQuery('[data-datepicker="'+ jQuery(this).data('datepicker-start') +'"]');
33     
34      $this.datepicker('option', 'onClose', function(date) {
35        $start.datepicker('option', 'maxDate', date);
36      });
37    }
38    else if ($this.data('datepicker-end')) {
39      var $end = jQuery('[data-datepicker="'+ jQuery(this).data('datepicker-end') +'"]');
40     
41      $this.datepicker('option', 'onClose', function(date) {
42        $end.datepicker('option', 'minDate', date);
43      });
44    }
45   
46    // attach unset button
47    if ($this.data('datepicker-unset')) {
48      jQuery('#'+ $this.data('datepicker-unset')).on('click', function(e) {
49        e.preventDefault();
50       
51        $target.val('');
52        set(null);
53      });
54    }
55   
56    // set value from linked input
57    if (value.length == 3) {
58      set(new Date(value[0], value[1]-1, value[2]));
59    }
60  });
61};
Note: See TracBrowser for help on using the repository browser.