This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/web/core/modules/system/js/system.date.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

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