* Provides date format preview feature.
*/
-(function ($, Drupal, drupalSettings) {
+(function($, Drupal, drupalSettings) {
const dateFormats = drupalSettings.dateFormats;
/**
Drupal.behaviors.dateFormat = {
attach(context) {
const $context = $(context);
- const $source = $context.find('[data-drupal-date-formatter="source"]').once('dateFormat');
- const $target = $context.find('[data-drupal-date-formatter="preview"]').once('dateFormat');
+ const $source = $context
+ .find('[data-drupal-date-formatter="source"]')
+ .once('dateFormat');
+ const $target = $context
+ .find('[data-drupal-date-formatter="preview"]')
+ .once('dateFormat');
const $preview = $target.find('em');
// All elements have to exist.
*/
function dateFormatHandler(e) {
const baseValue = $(e.target).val() || '';
- const dateString = baseValue.replace(/\\?(.?)/gi, (key, value) => (dateFormats[key] ? dateFormats[key] : value));
+ const dateString = baseValue.replace(
+ /\\?(.?)/gi,
+ (key, value) => (dateFormats[key] ? dateFormats[key] : value),
+ );
$preview.html(dateString);
$target.toggleClass('js-hide', !dateString.length);
/**
* On given event triggers the date character replacement.
*/
- $source.on('keyup.dateFormat change.dateFormat input.dateFormat', dateFormatHandler)
+ $source
+ .on(
+ 'keyup.dateFormat change.dateFormat input.dateFormat',
+ dateFormatHandler,
+ )
// Initialize preview.
.trigger('keyup');
},
};
-}(jQuery, Drupal, drupalSettings));
+})(jQuery, Drupal, drupalSettings);