node.es6.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @file
  3. * Defines Javascript behaviors for the node module.
  4. */
  5. (function($, Drupal, drupalSettings) {
  6. /**
  7. * Behaviors for tabs in the node edit form.
  8. *
  9. * @type {Drupal~behavior}
  10. *
  11. * @prop {Drupal~behaviorAttach} attach
  12. * Attaches summary behavior for tabs in the node edit form.
  13. */
  14. Drupal.behaviors.nodeDetailsSummaries = {
  15. attach(context) {
  16. const $context = $(context);
  17. $context.find('.node-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', {
  23. '@name': name,
  24. '@date': date,
  25. });
  26. }
  27. if (name) {
  28. return Drupal.t('By @name', { '@name': name });
  29. }
  30. if (date) {
  31. return Drupal.t('Authored on @date', { '@date': date });
  32. }
  33. });
  34. $context.find('.node-form-options').drupalSetSummary(context => {
  35. const $optionsContext = $(context);
  36. const vals = [];
  37. if ($optionsContext.find('input').is(':checked')) {
  38. $optionsContext
  39. .find('input:checked')
  40. .next('label')
  41. .each(function() {
  42. vals.push(Drupal.checkPlain($.trim($(this).text())));
  43. });
  44. return vals.join(', ');
  45. }
  46. return Drupal.t('Not promoted');
  47. });
  48. },
  49. };
  50. })(jQuery, Drupal, drupalSettings);