system.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. Object.keys(drupalSettings.copyFieldValue || {}).forEach(function (element) {
  12. ids.push(element);
  13. });
  14. if (ids.length) {
  15. $('body').once('copy-field-values').on('value:copy', this.valueTargetCopyHandler);
  16. $('#' + ids.join(', #')).once('copy-field-values').on('blur', this.valueSourceBlurHandler);
  17. }
  18. },
  19. detach: function detach(context, settings, trigger) {
  20. if (trigger === 'unload' && ids.length) {
  21. $('body').removeOnce('copy-field-values').off('value:copy');
  22. $('#' + ids.join(', #')).removeOnce('copy-field-values').off('blur');
  23. }
  24. },
  25. valueTargetCopyHandler: function valueTargetCopyHandler(e, value) {
  26. var $target = $(e.target);
  27. if ($target.val() === '') {
  28. $target.val(value);
  29. }
  30. },
  31. valueSourceBlurHandler: function valueSourceBlurHandler(e) {
  32. var value = $(e.target).val();
  33. var targetIds = drupalSettings.copyFieldValue[e.target.id];
  34. $('#' + targetIds.join(', #')).trigger('value:copy', value);
  35. }
  36. };
  37. })(jQuery, Drupal, drupalSettings);