diff options
Diffstat (limited to 'core/misc/date.js')
-rw-r--r-- | core/misc/date.js | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/core/misc/date.js b/core/misc/date.js index bd1045665f35..4cfa477eb9da 100644 --- a/core/misc/date.js +++ b/core/misc/date.js @@ -4,10 +4,13 @@ * https://www.drupal.org/node/2815083 * @preserve **/ -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + (function ($, Modernizr, Drupal) { Drupal.behaviors.date = { attach: function attach(context, settings) { @@ -15,7 +18,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var dataDatepickerProcessed = 'data-datepicker-is-processed'; var getDateSelector = function getDateSelector(elements) { - return ['[' + dataFieldElements + '="' + elements + '"]', ':not([' + dataDatepickerProcessed + '="' + elements + '"])'].join(''); + return ["[".concat(dataFieldElements, "=\"").concat(elements, "\"]"), ":not([".concat(dataDatepickerProcessed, "=\"").concat(elements, "\"])")].join(''); }; if (Modernizr.inputtypes.date === false) { @@ -23,35 +26,27 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var dateInput = dateTime.querySelector('input[type="date"]'); var timeInput = dateTime.querySelector('input[type="time"]'); var help = Drupal.theme.dateTimeHelp({ - dateId: dateInput.id + '--description', + dateId: "".concat(dateInput.id, "--description"), dateDesc: dateInput.dataset.help, - timeId: timeInput.id + '--description', + timeId: "".concat(timeInput.id, "--description"), timeDesc: timeInput.dataset.help }); - [dateInput, timeInput].forEach(function (input) { - input.setAttribute('aria-describedby', input.id + '--description'); - + input.setAttribute('aria-describedby', "".concat(input.id, "--description")); input.setAttribute('type', 'text'); }); - Drupal.DatepickerPolyfill.attachDescription(dateTime, help); - dateTime.setAttribute(dataDatepickerProcessed, 'date-time'); }); - Array.prototype.forEach.call(document.querySelectorAll(getDateSelector('date')), function (date) { var dateInput = date.querySelector('input[type="date"]'); var help = Drupal.theme.dateHelp({ dateDesc: dateInput.dataset.help }); - - var id = date.id + '--description'; + var id = "".concat(date.id, "--description"); dateInput.setAttribute('aria-describedby', id); - dateInput.setAttribute('type', 'text'); Drupal.DatepickerPolyfill.attachDescription(date, help, id); - date.setAttribute(dataDatepickerProcessed, 'date'); }); } @@ -64,7 +59,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } _createClass(_class, null, [{ - key: 'attachDescription', + key: "attachDescription", value: function attachDescription(element, help, id) { var description = element.nextElementSibling; @@ -72,17 +67,20 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons description = Drupal.DatepickerPolyfill.descriptionWrapperElement(id); element.parentNode.insertBefore(description, element.nextSibling); } + description.insertAdjacentHTML('beforeend', help); } }, { - key: 'descriptionWrapperElement', + key: "descriptionWrapperElement", value: function descriptionWrapperElement(id) { var description = document.createElement('div'); description.classList.add('description'); description.setAttribute('data-drupal-field-elements', 'description'); + if (id) { description.setAttribute('id', id); } + return description; } }]); @@ -92,7 +90,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons Drupal.theme.dateHelp = function (_ref) { var dateDesc = _ref.dateDesc; - return '<div class="no-native-datepicker-help">' + dateDesc + '</div>'; + return "<div class=\"no-native-datepicker-help\">".concat(dateDesc, "</div>"); }; Drupal.theme.dateTimeHelp = function (_ref2) { @@ -100,6 +98,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons timeId = _ref2.timeId, dateDesc = _ref2.dateDesc, timeDesc = _ref2.timeDesc; - return '<div class="no-native-datepicker-help">\n <span id="' + dateId + '">' + dateDesc + '</span> <span id="' + timeId + '">' + timeDesc + '</span>\n </div>'; + return "<div class=\"no-native-datepicker-help\">\n <span id=\"".concat(dateId, "\">").concat(dateDesc, "</span> <span id=\"").concat(timeId, "\">").concat(timeDesc, "</span>\n </div>"); }; })(jQuery, Modernizr, Drupal);
\ No newline at end of file |