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