diff options
author | Lauri Eskola <lauriii@1078742.no-reply.drupal.org> | 2018-08-09 18:49:18 +0300 |
---|---|---|
committer | Lauri Eskola <lauriii@1078742.no-reply.drupal.org> | 2018-08-09 18:49:18 +0300 |
commit | e742590eedd0f8bfe0f4f21710df3ddfe0524521 (patch) | |
tree | 6ca0c5c851f63186f0cb1ca52a28ee899dd3aa14 /core/misc/machine-name.es6.js | |
parent | c6e6709878839e0639d73d7c1e4420a8008e8a33 (diff) | |
download | drupal-e742590eedd0f8bfe0f4f21710df3ddfe0524521.tar.gz drupal-e742590eedd0f8bfe0f4f21710df3ddfe0524521.zip |
Issue #2981652 by ApacheEx, corbacho, drpal, dawehner, xjm, alexpott, lauriii: Format core JavaScript using recently add Prettier
Diffstat (limited to 'core/misc/machine-name.es6.js')
-rw-r--r-- | core/misc/machine-name.es6.js | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/core/misc/machine-name.es6.js b/core/misc/machine-name.es6.js index ee7f528092ff..0fee7f6b5f7c 100644 --- a/core/misc/machine-name.es6.js +++ b/core/misc/machine-name.es6.js @@ -3,7 +3,7 @@ * Machine name functionality. */ -(function ($, Drupal, drupalSettings) { +(function($, Drupal, drupalSettings) { /** * Attach the machine-readable name form element behavior. * @@ -13,7 +13,6 @@ * Attaches machine-name behaviors. */ Drupal.behaviors.machineName = { - /** * Attaches the behavior. * @@ -59,7 +58,10 @@ const baseValue = $(e.target).val(); const rx = new RegExp(options.replace_pattern, 'g'); - const expected = baseValue.toLowerCase().replace(rx, options.replace).substr(0, options.maxlength); + const expected = baseValue + .toLowerCase() + .replace(rx, options.replace) + .substr(0, options.maxlength); // Abort the last pending request because the label has changed and it // is no longer valid. @@ -76,26 +78,35 @@ } if (baseValue.toLowerCase() !== expected) { timeout = setTimeout(() => { - xhr = self.transliterate(baseValue, options).done((machine) => { + xhr = self.transliterate(baseValue, options).done(machine => { self.showMachineName(machine.substr(0, options.maxlength), data); }); }, 300); - } - else { + } else { self.showMachineName(expected, data); } } - Object.keys(settings.machineName).forEach((sourceId) => { + Object.keys(settings.machineName).forEach(sourceId => { let machine = ''; const options = settings.machineName[sourceId]; - const $source = $context.find(sourceId).addClass('machine-name-source').once('machine-name'); - const $target = $context.find(options.target).addClass('machine-name-target'); + const $source = $context + .find(sourceId) + .addClass('machine-name-source') + .once('machine-name'); + const $target = $context + .find(options.target) + .addClass('machine-name-target'); const $suffix = $context.find(options.suffix); const $wrapper = $target.closest('.js-form-item'); // All elements have to exist. - if (!$source.length || !$target.length || !$suffix.length || !$wrapper.length) { + if ( + !$source.length || + !$target.length || + !$suffix.length || + !$wrapper.length + ) { return; } // Skip processing upon a form validation error on the machine name. @@ -111,15 +122,20 @@ // based on the human-readable form element value. if ($target.is(':disabled') || $target.val() !== '') { machine = $target.val(); - } - else if ($source.val() !== '') { + } else if ($source.val() !== '') { machine = self.transliterate($source.val(), options); } // Append the machine name preview to the source field. - const $preview = $(`<span class="machine-name-value">${options.field_prefix}${Drupal.checkPlain(machine)}${options.field_suffix}</span>`); + const $preview = $( + `<span class="machine-name-value">${ + options.field_prefix + }${Drupal.checkPlain(machine)}${options.field_suffix}</span>`, + ); $suffix.empty(); if (options.label) { - $suffix.append(`<span class="machine-name-label">${options.label}: </span>`); + $suffix.append( + `<span class="machine-name-label">${options.label}: </span>`, + ); } $suffix.append($preview); @@ -137,14 +153,19 @@ options, }; // If it is editable, append an edit link. - const $link = $(`<span class="admin-link"><button type="button" class="link">${Drupal.t('Edit')}</button></span>`).on('click', eventData, clickEditHandler); + const $link = $( + `<span class="admin-link"><button type="button" class="link">${Drupal.t( + 'Edit', + )}</button></span>`, + ).on('click', eventData, clickEditHandler); $suffix.append($link); // Preview the machine name in realtime when the human-readable name // changes, but only if there is no machine name yet; i.e., only upon // initial creation, not when editing. if ($target.val() === '') { - $source.on('formUpdated.machineName', eventData, machineNameHandler) + $source + .on('formUpdated.machineName', eventData, machineNameHandler) // Initialize machine name preview. .trigger('formUpdated.machineName'); } @@ -161,11 +182,14 @@ if (machine !== '') { if (machine !== settings.replace) { data.$target.val(machine); - data.$preview.html(settings.field_prefix + Drupal.checkPlain(machine) + settings.field_suffix); + data.$preview.html( + settings.field_prefix + + Drupal.checkPlain(machine) + + settings.field_suffix, + ); } data.$suffix.show(); - } - else { + } else { data.$suffix.hide(); data.$target.val(machine); data.$preview.empty(); @@ -203,4 +227,4 @@ }); }, }; -}(jQuery, Drupal, drupalSettings)); +})(jQuery, Drupal, drupalSettings); |