node.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @file
  3. * Defines Javascript behaviors for the node module.
  4. */
  5. (function ($, Drupal, drupalSettings) {
  6. 'use strict';
  7. /**
  8. * Behaviors for tabs in the node edit form.
  9. *
  10. * @type {Drupal~behavior}
  11. *
  12. * @prop {Drupal~behaviorAttach} attach
  13. * Attaches summary behavior for tabs in the node edit form.
  14. */
  15. Drupal.behaviors.nodeDetailsSummaries = {
  16. attach: function (context) {
  17. var $context = $(context);
  18. $context.find('.node-form-revision-information').drupalSetSummary(function (context) {
  19. var $revisionContext = $(context);
  20. var revisionCheckbox = $revisionContext.find('.js-form-item-revision input');
  21. // Return 'New revision' if the 'Create new revision' checkbox is
  22. // checked, or if the checkbox doesn't exist, but the revision log does.
  23. // For users without the "Administer content" permission the checkbox
  24. // won't appear, but the revision log will if the content type is set to
  25. // auto-revision.
  26. if (revisionCheckbox.is(':checked') || (!revisionCheckbox.length && $revisionContext.find('.js-form-item-revision-log textarea').length)) {
  27. return Drupal.t('New revision');
  28. }
  29. return Drupal.t('No revision');
  30. });
  31. $context.find('.node-form-author').drupalSetSummary(function (context) {
  32. var $authorContext = $(context);
  33. var name = $authorContext.find('.field--name-uid input').val();
  34. var date = $authorContext.find('.field--name-created input').val();
  35. if (name && date) {
  36. return Drupal.t('By @name on @date', {'@name': name, '@date': date});
  37. }
  38. else if (name) {
  39. return Drupal.t('By @name', {'@name': name});
  40. }
  41. else if (date) {
  42. return Drupal.t('Authored on @date', {'@date': date});
  43. }
  44. });
  45. $context.find('.node-form-options').drupalSetSummary(function (context) {
  46. var $optionsContext = $(context);
  47. var vals = [];
  48. if ($optionsContext.find('input').is(':checked')) {
  49. $optionsContext.find('input:checked').next('label').each(function () {
  50. vals.push(Drupal.checkPlain($.trim($(this).text())));
  51. });
  52. return vals.join(', ');
  53. }
  54. else {
  55. return Drupal.t('Not promoted');
  56. }
  57. });
  58. $context.find('fieldset.node-translation-options').drupalSetSummary(function (context) {
  59. var $translationContext = $(context);
  60. var translate;
  61. var $checkbox = $translationContext.find('.js-form-item-translation-translate input');
  62. if ($checkbox.size()) {
  63. translate = $checkbox.is(':checked') ? Drupal.t('Needs to be updated') : Drupal.t('Does not need to be updated');
  64. }
  65. else {
  66. $checkbox = $translationContext.find('.js-form-item-translation-retranslate input');
  67. translate = $checkbox.is(':checked') ? Drupal.t('Flag other translations as outdated') : Drupal.t('Do not flag other translations as outdated');
  68. }
  69. return translate;
  70. });
  71. }
  72. };
  73. })(jQuery, Drupal, drupalSettings);