From 914b6d96d2cae67507ef848a7a229fd5319d7968 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sat, 17 May 2014 22:04:36 +0000 Subject: feature 3080 : simpler date inputs (one input + fontello + picker selects) git-svn-id: http://piwigo.org/svn/trunk@28497 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/themes/default/js/datepicker.js | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 admin/themes/default/js/datepicker.js (limited to 'admin/themes/default/js/datepicker.js') 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 -- cgit v1.2.3