form.es6.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * @file
  3. * Defines Javascript behaviors for the media form.
  4. */
  5. (function ($, Drupal) {
  6. /**
  7. * Behaviors for summaries for tabs in the media edit form.
  8. *
  9. * @type {Drupal~behavior}
  10. *
  11. * @prop {Drupal~behaviorAttach} attach
  12. * Attaches summary behavior for tabs in the media edit form.
  13. */
  14. Drupal.behaviors.mediaFormSummaries = {
  15. attach(context) {
  16. const $context = $(context);
  17. $context.find('.media-form-author').drupalSetSummary((context) => {
  18. const $authorContext = $(context);
  19. const name = $authorContext.find('.field--name-uid input').val();
  20. const date = $authorContext.find('.field--name-created input').val();
  21. if (name && date) {
  22. return Drupal.t('By @name on @date', { '@name': name, '@date': date });
  23. }
  24. else if (name) {
  25. return Drupal.t('By @name', { '@name': name });
  26. }
  27. else if (date) {
  28. return Drupal.t('Authored on @date', { '@date': date });
  29. }
  30. });
  31. },
  32. };
  33. }(jQuery, Drupal));