summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/system/js/system.js
diff options
context:
space:
mode:
authorcatch <catch@35733.no-reply.drupal.org>2022-09-09 07:26:42 +0100
committercatch <catch@35733.no-reply.drupal.org>2022-09-09 07:26:42 +0100
commit8aa8ce1ffbcca9c727f46e58c714e1d351f7ef88 (patch)
tree27be6908992c340ba0b4c0bd3f4339670aa71e90 /core/modules/system/js/system.js
parent09f8f13d8a72b8e482cc689fcd10f023df41b899 (diff)
downloaddrupal-8aa8ce1ffbcca9c727f46e58c714e1d351f7ef88.tar.gz
drupal-8aa8ce1ffbcca9c727f46e58c714e1d351f7ef88.zip
Issue #3278415 by nod_, lauriii, catch, Wim Leers, longwave, xjm, claudiu.cristea: Remove usages of the JavaScript ES6 build step, the build step itself, and associated dev dependencies
Diffstat (limited to 'core/modules/system/js/system.js')
-rw-r--r--core/modules/system/js/system.js72
1 files changed, 53 insertions, 19 deletions
diff --git a/core/modules/system/js/system.js b/core/modules/system/js/system.js
index 86bbfb220a8b..7bca481c068b 100644
--- a/core/modules/system/js/system.js
+++ b/core/modules/system/js/system.js
@@ -1,24 +1,47 @@
/**
-* DO NOT EDIT THIS FILE.
-* See the following change record for more information,
-* https://www.drupal.org/node/2815083
-* @preserve
-**/
+ * @file
+ * System behaviors.
+ */
(function ($, Drupal, drupalSettings) {
+ // Cache IDs in an array for ease of use.
const ids = [];
+
+ /**
+ * Attaches field copy behavior from input fields to other input fields.
+ *
+ * When a field is filled out, apply its value to other fields that will
+ * likely use the same value. In the installer this is used to populate the
+ * administrator email address with the same value as the site email address.
+ *
+ * @type {Drupal~behavior}
+ *
+ * @prop {Drupal~behaviorAttach} attach
+ * Attaches the field copy behavior to an input field.
+ */
Drupal.behaviors.copyFieldValue = {
attach(context) {
- Object.keys(drupalSettings.copyFieldValue || {}).forEach(element => {
+ // List of fields IDs on which to bind the event listener.
+ // Create an array of IDs to use with jQuery.
+ Object.keys(drupalSettings.copyFieldValue || {}).forEach((element) => {
ids.push(element);
});
if (ids.length) {
- $(once('copy-field-values', 'body')).on('value:copy', this.valueTargetCopyHandler);
- $(once('copy-field-values', `#${ids.join(', #')}`)).on('blur', this.valueSourceBlurHandler);
+ // Listen to value:copy events on all dependent fields.
+ // We have to use body and not document because of the way jQuery events
+ // bubble up the DOM tree.
+ $(once('copy-field-values', 'body')).on(
+ 'value:copy',
+ this.valueTargetCopyHandler,
+ );
+ // Listen on all source elements.
+ $(once('copy-field-values', `#${ids.join(', #')}`)).on(
+ 'blur',
+ this.valueSourceBlurHandler,
+ );
}
},
-
detach(context, settings, trigger) {
if (trigger === 'unload' && ids.length) {
$(once.remove('copy-field-values', 'body')).off('value:copy');
@@ -26,23 +49,34 @@
}
},
+ /**
+ * Event handler that fill the target element with the specified value.
+ *
+ * @param {jQuery.Event} e
+ * Event object.
+ * @param {string} value
+ * Custom value from jQuery trigger.
+ */
valueTargetCopyHandler(e, value) {
- const {
- target
- } = e;
-
+ const { target } = e;
if (target.value === '') {
target.value = value;
}
},
+ /**
+ * Handler for a Blur event on a source field.
+ *
+ * This event handler will trigger a 'value:copy' event on all dependent
+ * fields.
+ *
+ * @param {jQuery.Event} e
+ * The event triggered.
+ */
valueSourceBlurHandler(e) {
- const {
- value
- } = e.target;
+ const { value } = e.target;
const targetIds = drupalSettings.copyFieldValue[e.target.id];
$(`#${targetIds.join(', #')}`).trigger('value:copy', value);
- }
-
+ },
};
-})(jQuery, Drupal, drupalSettings); \ No newline at end of file
+})(jQuery, Drupal, drupalSettings);