system.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal, drupalSettings) {
  8. var ids = [];
  9. Drupal.behaviors.copyFieldValue = {
  10. attach: function attach(context) {
  11. for (var sourceId in drupalSettings.copyFieldValue) {
  12. if (drupalSettings.copyFieldValue.hasOwnProperty(sourceId)) {
  13. ids.push(sourceId);
  14. }
  15. }
  16. if (ids.length) {
  17. $('body').once('copy-field-values').on('value:copy', this.valueTargetCopyHandler);
  18. $('#' + ids.join(', #')).once('copy-field-values').on('blur', this.valueSourceBlurHandler);
  19. }
  20. },
  21. detach: function detach(context, settings, trigger) {
  22. if (trigger === 'unload' && ids.length) {
  23. $('body').removeOnce('copy-field-values').off('value:copy');
  24. $('#' + ids.join(', #')).removeOnce('copy-field-values').off('blur');
  25. }
  26. },
  27. valueTargetCopyHandler: function valueTargetCopyHandler(e, value) {
  28. var $target = $(e.target);
  29. if ($target.val() === '') {
  30. $target.val(value);
  31. }
  32. },
  33. valueSourceBlurHandler: function valueSourceBlurHandler(e) {
  34. var value = $(e.target).val();
  35. var targetIds = drupalSettings.copyFieldValue[e.target.id];
  36. $('#' + targetIds.join(', #')).trigger('value:copy', value);
  37. }
  38. };
  39. })(jQuery, Drupal, drupalSettings);