e8ebb8d728204f3abedb771543712786bc77be54
[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', {
26             '@name': name,
27             '@date': date,
28           });
29         }
30         if (name) {
31           return Drupal.t('By @name', { '@name': name });
32         }
33         if (date) {
34           return Drupal.t('Authored on @date', { '@date': date });
35         }
36       });
37     },
38   };
39 })(jQuery, Drupal);