Projet

Général

Profil

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

root / drupal7 / modules / field / modules / text / text.js @ c7768a53

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').first();
16
        var $full = $widget.find('.text-full').eq(index).closest('.form-item');
17
        var $fullLabel = $full.find('label').first();
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>');
27
        var $a = $link.find('a');
28
        var toggleClick = true;
29
        $link.bind('click', function (e) {
30
          if (toggleClick) {
31
            $summary.hide();
32
            $a.html(Drupal.t('Edit summary'));
33
            $link.appendTo($fullLabel);
34
          }
35
          else {
36
            $summary.show();
37
            $a.html(Drupal.t('Hide summary'));
38
            $link.appendTo($summaryLabel);
39
          }
40
          toggleClick = !toggleClick;
41
          return false;
42
        }).appendTo($summaryLabel);
43

    
44
        // If no summary is set, hide the summary field.
45
        if ($(this).find('.text-summary').val() == '') {
46
          $link.click();
47
        }
48
      });
49
    });
50
  }
51
};
52

    
53
})(jQuery);