book.es6.js 826 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @file
  3. * Javascript behaviors for the Book module.
  4. */
  5. (function($, Drupal) {
  6. /**
  7. * Adds summaries to the book outline form.
  8. *
  9. * @type {Drupal~behavior}
  10. *
  11. * @prop {Drupal~behaviorAttach} attach
  12. * Attaches summary behavior to book outline forms.
  13. */
  14. Drupal.behaviors.bookDetailsSummaries = {
  15. attach(context) {
  16. $(context)
  17. .find('.book-outline-form')
  18. .drupalSetSummary(context => {
  19. const $select = $(context).find('.book-title-select');
  20. const val = $select.val();
  21. if (val === '0') {
  22. return Drupal.t('Not in book');
  23. }
  24. if (val === 'new') {
  25. return Drupal.t('New book');
  26. }
  27. return Drupal.checkPlain($select.find(':selected').text());
  28. });
  29. },
  30. };
  31. })(jQuery, Drupal);