Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / misc / machine-name.es6.js
index ee7f528092ffb0cec2c1b7d68a7254a6afa6972e..0fee7f6b5f7c0ea998d0009eb14d80919eeb7655 100644 (file)
@@ -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.
      *
         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.
         }
         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.
         // 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);
 
           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');
         }
       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();
       });
     },
   };
-}(jQuery, Drupal, drupalSettings));
+})(jQuery, Drupal, drupalSettings);