cb0da60dc8f986c3d301685d627d0ee531f0ae2d
[yaffs-website] / web / core / modules / media / js / form.es6.js
1 /**
2  * @file
3  * Defines Javascript behaviors for the media form.
4  */
5
6 (function ($, Drupal) {
7   /**
8    * Behaviors for summaries for tabs in the media edit form.
9    *
10    * @type {Drupal~behavior}
11    *
12    * @prop {Drupal~behaviorAttach} attach
13    *   Attaches summary behavior for tabs in the media edit form.
14    */
15   Drupal.behaviors.mediaFormSummaries = {
16     attach(context) {
17       const $context = $(context);
18
19       $context.find('.media-form-author').drupalSetSummary((context) => {
20         const $authorContext = $(context);
21         const name = $authorContext.find('.field--name-uid input').val();
22         const date = $authorContext.find('.field--name-created input').val();
23
24         if (name && date) {
25           return Drupal.t('By @name on @date', { '@name': name, '@date': date });
26         }
27         else if (name) {
28           return Drupal.t('By @name', { '@name': name });
29         }
30         else if (date) {
31           return Drupal.t('Authored on @date', { '@date': date });
32         }
33       });
34     },
35   };
36 }(jQuery, Drupal));