2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal, drupalSettings) {
9 var dateFormats = drupalSettings.dateFormats;
11 Drupal.behaviors.dateFormat = {
12 attach: function attach(context) {
13 var $context = $(context);
14 var $source = $context.find('[data-drupal-date-formatter="source"]').once('dateFormat');
15 var $target = $context.find('[data-drupal-date-formatter="preview"]').once('dateFormat');
16 var $preview = $target.find('em');
18 if (!$source.length || !$target.length) {
22 function dateFormatHandler(e) {
23 var baseValue = $(e.target).val() || '';
24 var dateString = baseValue.replace(/\\?(.?)/gi, function (key, value) {
25 return dateFormats[key] ? dateFormats[key] : value;
28 $preview.html(dateString);
29 $target.toggleClass('js-hide', !dateString.length);
32 $source.on('keyup.dateFormat change.dateFormat input.dateFormat', dateFormatHandler).trigger('keyup');
35 })(jQuery, Drupal, drupalSettings);