annotate core/modules/system/js/system.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@0 1 /**
Chris@0 2 * DO NOT EDIT THIS FILE.
Chris@0 3 * See the following change record for more information,
Chris@0 4 * https://www.drupal.org/node/2815083
Chris@0 5 * @preserve
Chris@0 6 **/
Chris@0 7
Chris@0 8 (function ($, Drupal, drupalSettings) {
Chris@0 9 var ids = [];
Chris@0 10
Chris@0 11 Drupal.behaviors.copyFieldValue = {
Chris@0 12 attach: function attach(context) {
Chris@14 13 Object.keys(drupalSettings.copyFieldValue || {}).forEach(function (element) {
Chris@14 14 ids.push(element);
Chris@14 15 });
Chris@14 16
Chris@0 17 if (ids.length) {
Chris@0 18 $('body').once('copy-field-values').on('value:copy', this.valueTargetCopyHandler);
Chris@0 19
Chris@0 20 $('#' + ids.join(', #')).once('copy-field-values').on('blur', this.valueSourceBlurHandler);
Chris@0 21 }
Chris@0 22 },
Chris@0 23 detach: function detach(context, settings, trigger) {
Chris@0 24 if (trigger === 'unload' && ids.length) {
Chris@0 25 $('body').removeOnce('copy-field-values').off('value:copy');
Chris@0 26 $('#' + ids.join(', #')).removeOnce('copy-field-values').off('blur');
Chris@0 27 }
Chris@0 28 },
Chris@0 29 valueTargetCopyHandler: function valueTargetCopyHandler(e, value) {
Chris@0 30 var $target = $(e.target);
Chris@0 31 if ($target.val() === '') {
Chris@0 32 $target.val(value);
Chris@0 33 }
Chris@0 34 },
Chris@0 35 valueSourceBlurHandler: function valueSourceBlurHandler(e) {
Chris@0 36 var value = $(e.target).val();
Chris@0 37 var targetIds = drupalSettings.copyFieldValue[e.target.id];
Chris@0 38 $('#' + targetIds.join(', #')).trigger('value:copy', value);
Chris@0 39 }
Chris@0 40 };
Chris@0 41 })(jQuery, Drupal, drupalSettings);