annotate core/modules/system/js/system.date.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 /**
Chris@0 2 * DO NOT EDIT THIS FILE.
Chris@0 3 * See the following change record for more information,
Chris@0 4 * https://www.drupal.org/node/2815083
Chris@0 5 * @preserve
Chris@0 6 **/
Chris@0 7
Chris@0 8 (function ($, Drupal, drupalSettings) {
Chris@0 9 var dateFormats = drupalSettings.dateFormats;
Chris@0 10
Chris@0 11 Drupal.behaviors.dateFormat = {
Chris@0 12 attach: function attach(context) {
Chris@0 13 var $context = $(context);
Chris@0 14 var $source = $context.find('[data-drupal-date-formatter="source"]').once('dateFormat');
Chris@0 15 var $target = $context.find('[data-drupal-date-formatter="preview"]').once('dateFormat');
Chris@0 16 var $preview = $target.find('em');
Chris@0 17
Chris@0 18 if (!$source.length || !$target.length) {
Chris@0 19 return;
Chris@0 20 }
Chris@0 21
Chris@0 22 function dateFormatHandler(e) {
Chris@0 23 var baseValue = $(e.target).val() || '';
Chris@0 24 var dateString = baseValue.replace(/\\?(.?)/gi, function (key, value) {
Chris@0 25 return dateFormats[key] ? dateFormats[key] : value;
Chris@0 26 });
Chris@0 27
Chris@0 28 $preview.html(dateString);
Chris@0 29 $target.toggleClass('js-hide', !dateString.length);
Chris@0 30 }
Chris@0 31
Chris@0 32 $source.on('keyup.dateFormat change.dateFormat input.dateFormat', dateFormatHandler).trigger('keyup');
Chris@0 33 }
Chris@0 34 };
Chris@0 35 })(jQuery, Drupal, drupalSettings);