Projet

Général

Profil

Paste
Télécharger (3,51 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / simpletest.js @ 76597ebf

1
(function ($) {
2

    
3
/**
4
 * Add the cool table collapsing on the testing overview page.
5
 */
6
Drupal.behaviors.simpleTestMenuCollapse = {
7
  attach: function (context, settings) {
8
    var timeout = null;
9
    // Adds expand-collapse functionality.
10
    $('div.simpletest-image').once('simpletest-image', function () {
11
      var $this = $(this);
12
      var direction = settings.simpleTest[this.id].imageDirection;
13
      $this.html(settings.simpleTest.images[direction]);
14

    
15
      // Adds group toggling functionality to arrow images.
16
      $this.click(function () {
17
        var trs = $this.closest('tbody').children('.' + settings.simpleTest[this.id].testClass);
18
        var direction = settings.simpleTest[this.id].imageDirection;
19
        var row = direction ? trs.length - 1 : 0;
20

    
21
        // If clicked in the middle of expanding a group, stop so we can switch directions.
22
        if (timeout) {
23
          clearTimeout(timeout);
24
        }
25

    
26
        // Function to toggle an individual row according to the current direction.
27
        // We set a timeout of 20 ms until the next row will be shown/hidden to
28
        // create a sliding effect.
29
        function rowToggle() {
30
          if (direction) {
31
            if (row >= 0) {
32
              $(trs[row]).hide();
33
              row--;
34
              timeout = setTimeout(rowToggle, 20);
35
            }
36
          }
37
          else {
38
            if (row < trs.length) {
39
              $(trs[row]).removeClass('js-hide').show();
40
              row++;
41
              timeout = setTimeout(rowToggle, 20);
42
            }
43
          }
44
        }
45

    
46
        // Kick-off the toggling upon a new click.
47
        rowToggle();
48

    
49
        // Toggle the arrow image next to the test group title.
50
        $this.html(settings.simpleTest.images[(direction ? 0 : 1)]);
51
        settings.simpleTest[this.id].imageDirection = !direction;
52

    
53
      });
54
    });
55
  }
56
};
57

    
58
/**
59
 * Select/deselect all the inner checkboxes when the outer checkboxes are
60
 * selected/deselected.
61
 */
62
Drupal.behaviors.simpleTestSelectAll = {
63
  attach: function (context, settings) {
64
    $('td.simpletest-select-all').once('simpletest-select-all', function () {
65
      var testCheckboxes = settings.simpleTest['simpletest-test-group-' + $(this).attr('id')].testNames;
66
      var groupCheckbox = $('<input type="checkbox" class="form-checkbox" id="' + $(this).attr('id') + '-select-all" />');
67

    
68
      // Each time a single-test checkbox is checked or unchecked, make sure
69
      // that the associated group checkbox gets the right state too.
70
      var updateGroupCheckbox = function () {
71
        var checkedTests = 0;
72
        for (var i = 0; i < testCheckboxes.length; i++) {
73
          $('#' + testCheckboxes[i]).each(function () {
74
            if (($(this).attr('checked'))) {
75
              checkedTests++;
76
            }
77
          });
78
        }
79
        $(groupCheckbox).attr('checked', (checkedTests == testCheckboxes.length));
80
      };
81

    
82
      // Have the single-test checkboxes follow the group checkbox.
83
      groupCheckbox.change(function () {
84
        var checked = !!($(this).attr('checked'));
85
        for (var i = 0; i < testCheckboxes.length; i++) {
86
          $('#' + testCheckboxes[i]).attr('checked', checked);
87
        }
88
      });
89

    
90
      // Have the group checkbox follow the single-test checkboxes.
91
      for (var i = 0; i < testCheckboxes.length; i++) {
92
        $('#' + testCheckboxes[i]).change(function () {
93
          updateGroupCheckbox();
94
        });
95
      }
96

    
97
      // Initialize status for the group checkbox correctly.
98
      updateGroupCheckbox();
99
      $(this).append(groupCheckbox);
100
    });
101
  }
102
};
103

    
104
})(jQuery);