Version 1
[yaffs-website] / web / core / modules / node / node.js
1 /**
2  * @file
3  * Defines Javascript behaviors for the node module.
4  */
5
6 (function ($, Drupal, drupalSettings) {
7
8   'use strict';
9
10   /**
11    * Behaviors for tabs in the node edit form.
12    *
13    * @type {Drupal~behavior}
14    *
15    * @prop {Drupal~behaviorAttach} attach
16    *   Attaches summary behavior for tabs in the node edit form.
17    */
18   Drupal.behaviors.nodeDetailsSummaries = {
19     attach: function (context) {
20       var $context = $(context);
21
22       $context.find('.node-form-author').drupalSetSummary(function (context) {
23         var $authorContext = $(context);
24         var name = $authorContext.find('.field--name-uid input').val();
25         var date = $authorContext.find('.field--name-created input').val();
26
27         if (name && date) {
28           return Drupal.t('By @name on @date', {'@name': name, '@date': date});
29         }
30         else if (name) {
31           return Drupal.t('By @name', {'@name': name});
32         }
33         else if (date) {
34           return Drupal.t('Authored on @date', {'@date': date});
35         }
36       });
37
38       $context.find('.node-form-options').drupalSetSummary(function (context) {
39         var $optionsContext = $(context);
40         var vals = [];
41
42         if ($optionsContext.find('input').is(':checked')) {
43           $optionsContext.find('input:checked').next('label').each(function () {
44             vals.push(Drupal.checkPlain($.trim($(this).text())));
45           });
46           return vals.join(', ');
47         }
48         else {
49           return Drupal.t('Not promoted');
50         }
51       });
52     }
53   };
54
55 })(jQuery, Drupal, drupalSettings);