Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function ($, Drupal, drupalSettings) { Chris@0: var dateFormats = drupalSettings.dateFormats; Chris@0: Chris@0: Drupal.behaviors.dateFormat = { Chris@0: attach: function attach(context) { Chris@0: var $context = $(context); Chris@0: var $source = $context.find('[data-drupal-date-formatter="source"]').once('dateFormat'); Chris@0: var $target = $context.find('[data-drupal-date-formatter="preview"]').once('dateFormat'); Chris@0: var $preview = $target.find('em'); Chris@0: Chris@0: if (!$source.length || !$target.length) { Chris@0: return; Chris@0: } Chris@0: Chris@0: function dateFormatHandler(e) { Chris@0: var baseValue = $(e.target).val() || ''; Chris@0: var dateString = baseValue.replace(/\\?(.?)/gi, function (key, value) { Chris@0: return dateFormats[key] ? dateFormats[key] : value; Chris@0: }); Chris@0: Chris@0: $preview.html(dateString); Chris@0: $target.toggleClass('js-hide', !dateString.length); Chris@0: } Chris@0: Chris@0: $source.on('keyup.dateFormat change.dateFormat input.dateFormat', dateFormatHandler).trigger('keyup'); Chris@0: } Chris@0: }; Chris@0: })(jQuery, Drupal, drupalSettings);