deb518ba9b3ab5050bfb7650ec82f664860ceab0
[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)
18         .find('.book-outline-form')
19         .drupalSetSummary(context => {
20           const $select = $(context).find('.book-title-select');
21           const val = $select.val();
22
23           if (val === '0') {
24             return Drupal.t('Not in book');
25           }
26           if (val === 'new') {
27             return Drupal.t('New book');
28           }
29
30           return Drupal.checkPlain($select.find(':selected').text());
31         });
32     },
33   };
34 })(jQuery, Drupal);