Projet

Général

Profil

Paste
Télécharger (1,63 ko) Statistiques
| Branche: | Révision:

root / htmltest / modules / field / modules / text / text.js @ 85ad3d82

1

    
2
(function ($) {
3

    
4
/**
5
 * Auto-hide summary textarea if empty and show hide and unhide links.
6
 */
7
Drupal.behaviors.textSummary = {
8
  attach: function (context, settings) {
9
    $('.text-summary', context).once('text-summary', function () {
10
      var $widget = $(this).closest('div.field-type-text-with-summary');
11
      var $summaries = $widget.find('div.text-summary-wrapper');
12

    
13
      $summaries.once('text-summary-wrapper').each(function(index) {
14
        var $summary = $(this);
15
        var $summaryLabel = $summary.find('label');
16
        var $full = $widget.find('.text-full').eq(index).closest('.form-item');
17
        var $fullLabel = $full.find('label');
18

    
19
        // Create a placeholder label when the field cardinality is
20
        // unlimited or greater than 1.
21
        if ($fullLabel.length == 0) {
22
          $fullLabel = $('<label></label>').prependTo($full);
23
        }
24

    
25
        // Setup the edit/hide summary link.
26
        var $link = $('<span class="field-edit-link">(<a class="link-edit-summary" href="#">' + Drupal.t('Hide summary') + '</a>)</span>').toggle(
27
          function () {
28
            $summary.hide();
29
            $(this).find('a').html(Drupal.t('Edit summary')).end().appendTo($fullLabel);
30
            return false;
31
          },
32
          function () {
33
            $summary.show();
34
            $(this).find('a').html(Drupal.t('Hide summary')).end().appendTo($summaryLabel);
35
            return false;
36
          }
37
        ).appendTo($summaryLabel);
38

    
39
        // If no summary is set, hide the summary field.
40
        if ($(this).find('.text-summary').val() == '') {
41
          $link.click();
42
        }
43
        return;
44
      });
45
    });
46
  }
47
};
48

    
49
})(jQuery);