From 9206741190a0274065f280de46aa330cb928a7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 23 Jun 2017 17:50:13 +0200 Subject: [PATCH] update pikaday.js --- public/javascripts/pikaday.js | 235 ++++++++++++++++++++++++++-------- 1 file changed, 185 insertions(+), 50 deletions(-) diff --git a/public/javascripts/pikaday.js b/public/javascripts/pikaday.js index 7fec0fc464f..ba7aca0641d 100644 --- a/public/javascripts/pikaday.js +++ b/public/javascripts/pikaday.js @@ -59,22 +59,6 @@ } }, - fireEvent = function(el, eventName, data) - { - var ev; - - if (document.createEvent) { - ev = document.createEvent('HTMLEvents'); - ev.initEvent(eventName, true, false); - ev = extend(ev, data); - el.dispatchEvent(ev); - } else if (document.createEventObject) { - ev = document.createEventObject(); - ev = extend(ev, data); - el.fireEvent('on' + eventName, ev); - } - }, - trim = function(str) { return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g,''); @@ -160,6 +144,22 @@ return to; }, + fireEvent = function(el, eventName, data) + { + var ev; + + if (document.createEvent) { + ev = document.createEvent('HTMLEvents'); + ev.initEvent(eventName, true, false); + ev = extend(ev, data); + el.dispatchEvent(ev); + } else if (document.createEventObject) { + ev = document.createEventObject(); + ev = extend(ev, data); + el.fireEvent('on' + eventName, ev); + } + }, + adjustCalendar = function(calendar) { if (calendar.month < 0) { calendar.year -= Math.ceil(Math.abs(calendar.month)/12); @@ -183,6 +183,9 @@ // automatically show/hide the picker on `field` focus (default `true` if `field` is set) bound: undefined, + // data-attribute on the input field with an aria assistance tekst (only applied when `bound` is set) + ariaLabel: 'Use the arrow keys to pick a date', + // position of the datepicker, relative to the field (default to bottom & left) // ('bottom' & 'left' keywords are not used, 'top' & 'right' are modifier on the bottom/left position) position: 'bottom left', @@ -193,6 +196,13 @@ // the default output format for `.toString()` and `field` value format: 'YYYY-MM-DD', + // the toString function which gets passed a current date object and format + // and returns a string + toString: null, + + // used to create date object from current input string + parse: null, + // the initial date to view when first opened defaultDate: null, @@ -216,6 +226,9 @@ // show week numbers at head of row showWeekNumber: false, + // Week picker mode + pickWholeWeek: false, + // used internally (don't config outside) minYear: 0, maxYear: 9999, @@ -236,6 +249,9 @@ // Render days of the calendar grid that fall in the next or previous month showDaysInNextAndPreviousMonths: false, + // Allows user to select days that fall in the next or previous month + enableSelectionDaysInNextAndPreviousMonths: false, + // how many months are visible numberOfMonths: 1, @@ -246,6 +262,9 @@ // Specify a DOM element to render the calendar in container: undefined, + // Blur field when date is selected + blurFieldOnSelect : true, + // internationalization i18n: { previousMonth : 'Previous Month', @@ -258,11 +277,17 @@ // Theme Classname theme: null, + // events array + events: [], + // callback function onSelect: null, onOpen: null, onClose: null, - onDraw: null + onDraw: null, + + // Enable keyboard input + keyboardInput: true }, @@ -281,9 +306,15 @@ renderDay = function(opts) { var arr = []; + var ariaSelected = 'false'; if (opts.isEmpty) { if (opts.showDaysInNextAndPreviousMonths) { arr.push('is-outside-current-month'); + + if(!opts.enableSelectionDaysInNextAndPreviousMonths) { + arr.push('is-selection-disabled'); + } + } else { return ''; } @@ -296,6 +327,10 @@ } if (opts.isSelected) { arr.push('is-selected'); + ariaSelected = 'true'; + } + if (opts.hasEvent) { + arr.push('has-event'); } if (opts.isInRange) { arr.push('is-inrange'); @@ -306,7 +341,7 @@ if (opts.isEndRange) { arr.push('is-endrange'); } - return '' + + return '' + '