system.date.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. (function ($, Drupal, drupalSettings) {
  8. var dateFormats = drupalSettings.dateFormats;
  9. Drupal.behaviors.dateFormat = {
  10. attach: function attach(context) {
  11. var $context = $(context);
  12. var $source = $context.find('[data-drupal-date-formatter="source"]').once('dateFormat');
  13. var $target = $context.find('[data-drupal-date-formatter="preview"]').once('dateFormat');
  14. var $preview = $target.find('em');
  15. if (!$source.length || !$target.length) {
  16. return;
  17. }
  18. function dateFormatHandler(e) {
  19. var baseValue = $(e.target).val() || '';
  20. var dateString = baseValue.replace(/\\?(.?)/gi, function (key, value) {
  21. return dateFormats[key] ? dateFormats[key] : value;
  22. });
  23. $preview.text(dateString);
  24. $target.toggleClass('js-hide', !dateString.length);
  25. }
  26. $source.on('keyup.dateFormat change.dateFormat input.dateFormat', dateFormatHandler).trigger('keyup');
  27. }
  28. };
  29. })(jQuery, Drupal, drupalSettings);