diff options
author | mistic100 <mistic@piwigo.org> | 2014-05-17 22:04:36 +0000 |
---|---|---|
committer | mistic100 <mistic@piwigo.org> | 2014-05-17 22:04:36 +0000 |
commit | 914b6d96d2cae67507ef848a7a229fd5319d7968 (patch) | |
tree | 97d0c9f0741ddb6ddee8cfbb20717b6b0fd9b75e /admin/themes/default/js/datepicker.js | |
parent | ce8a29810abe6f7fdf82043b32ca87ba0f14220c (diff) |
feature 3080 : simpler date inputs (one input + fontello + picker selects)
git-svn-id: http://piwigo.org/svn/trunk@28497 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/themes/default/js/datepicker.js')
-rw-r--r-- | admin/themes/default/js/datepicker.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/admin/themes/default/js/datepicker.js b/admin/themes/default/js/datepicker.js new file mode 100644 index 000000000..ace38da13 --- /dev/null +++ b/admin/themes/default/js/datepicker.js @@ -0,0 +1,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])); + } + }); +};
\ No newline at end of file |