1c80ad7922ae7b457a2b36826311d5e04175c77f
[yaffs-website] / web / core / modules / system / js / system.date.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, Drupal, drupalSettings) {
9   var dateFormats = drupalSettings.dateFormats;
10
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');
17
18       if (!$source.length || !$target.length) {
19         return;
20       }
21
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;
26         });
27
28         $preview.html(dateString);
29         $target.toggleClass('js-hide', !dateString.length);
30       }
31
32       $source.on('keyup.dateFormat change.dateFormat input.dateFormat', dateFormatHandler).trigger('keyup');
33     }
34   };
35 })(jQuery, Drupal, drupalSettings);