12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- (function($, Modernizr, Drupal) {
-
- Drupal.behaviors.date = {
- attach(context, settings) {
- const $context = $(context);
-
- if (Modernizr.inputtypes.date === true) {
- return;
- }
- $context
- .find('input[data-drupal-date-format]')
- .once('datePicker')
- .each(function() {
- const $input = $(this);
- const datepickerSettings = {};
- const dateFormat = $input.data('drupalDateFormat');
-
-
- datepickerSettings.dateFormat = dateFormat
- .replace('Y', 'yy')
- .replace('m', 'mm')
- .replace('d', 'dd');
-
- if ($input.attr('min')) {
- datepickerSettings.minDate = $input.attr('min');
- }
- if ($input.attr('max')) {
- datepickerSettings.maxDate = $input.attr('max');
- }
- $input.datepicker(datepickerSettings);
- });
- },
- detach(context, settings, trigger) {
- if (trigger === 'unload') {
- $(context)
- .find('input[data-drupal-date-format]')
- .findOnce('datePicker')
- .datepicker('destroy');
- }
- },
- };
- })(jQuery, Modernizr, Drupal);
|