Mercurial > hg > cmmr2012-drupal-site
comparison core/misc/date.es6.js @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
1 /** | 1 /** |
2 * @file | 2 * @file |
3 * Polyfill for HTML5 date input. | 3 * Polyfill for HTML5 date input. |
4 */ | 4 */ |
5 | 5 |
6 (function ($, Modernizr, Drupal) { | 6 (function($, Modernizr, Drupal) { |
7 /** | 7 /** |
8 * Attach datepicker fallback on date elements. | 8 * Attach datepicker fallback on date elements. |
9 * | 9 * |
10 * @type {Drupal~behavior} | 10 * @type {Drupal~behavior} |
11 * | 11 * |
21 const $context = $(context); | 21 const $context = $(context); |
22 // Skip if date are supported by the browser. | 22 // Skip if date are supported by the browser. |
23 if (Modernizr.inputtypes.date === true) { | 23 if (Modernizr.inputtypes.date === true) { |
24 return; | 24 return; |
25 } | 25 } |
26 $context.find('input[data-drupal-date-format]').once('datePicker').each(function () { | 26 $context |
27 const $input = $(this); | 27 .find('input[data-drupal-date-format]') |
28 const datepickerSettings = {}; | 28 .once('datePicker') |
29 const dateFormat = $input.data('drupalDateFormat'); | 29 .each(function() { |
30 // The date format is saved in PHP style, we need to convert to jQuery | 30 const $input = $(this); |
31 // datepicker. | 31 const datepickerSettings = {}; |
32 datepickerSettings.dateFormat = dateFormat | 32 const dateFormat = $input.data('drupalDateFormat'); |
33 .replace('Y', 'yy') | 33 // The date format is saved in PHP style, we need to convert to jQuery |
34 .replace('m', 'mm') | 34 // datepicker. |
35 .replace('d', 'dd'); | 35 datepickerSettings.dateFormat = dateFormat |
36 // Add min and max date if set on the input. | 36 .replace('Y', 'yy') |
37 if ($input.attr('min')) { | 37 .replace('m', 'mm') |
38 datepickerSettings.minDate = $input.attr('min'); | 38 .replace('d', 'dd'); |
39 } | 39 // Add min and max date if set on the input. |
40 if ($input.attr('max')) { | 40 if ($input.attr('min')) { |
41 datepickerSettings.maxDate = $input.attr('max'); | 41 datepickerSettings.minDate = $input.attr('min'); |
42 } | 42 } |
43 $input.datepicker(datepickerSettings); | 43 if ($input.attr('max')) { |
44 }); | 44 datepickerSettings.maxDate = $input.attr('max'); |
45 } | |
46 $input.datepicker(datepickerSettings); | |
47 }); | |
45 }, | 48 }, |
46 detach(context, settings, trigger) { | 49 detach(context, settings, trigger) { |
47 if (trigger === 'unload') { | 50 if (trigger === 'unload') { |
48 $(context).find('input[data-drupal-date-format]').findOnce('datePicker').datepicker('destroy'); | 51 $(context) |
52 .find('input[data-drupal-date-format]') | |
53 .findOnce('datePicker') | |
54 .datepicker('destroy'); | |
49 } | 55 } |
50 }, | 56 }, |
51 }; | 57 }; |
52 }(jQuery, Modernizr, Drupal)); | 58 })(jQuery, Modernizr, Drupal); |