| 1 |
// $Id: simpletest.js,v 1.10 2009/04/26 19:18:46 webchick Exp $
|
| 2 |
(function ($) {
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Add the cool table collapsing on the testing overview page.
|
| 6 |
*/
|
| 7 |
Drupal.behaviors.simpleTestMenuCollapse = {
|
| 8 |
attach: function (context, settings) {
|
| 9 |
var timeout = null;
|
| 10 |
// Adds expand-collapse functionality.
|
| 11 |
$('div.simpletest-image').each(function () {
|
| 12 |
direction = settings.simpleTest[$(this).attr('id')].imageDirection;
|
| 13 |
$(this).html(settings.simpleTest.images[direction]);
|
| 14 |
});
|
| 15 |
|
| 16 |
// Adds group toggling functionality to arrow images.
|
| 17 |
$('div.simpletest-image').click(function () {
|
| 18 |
var trs = $(this).parents('tbody').children('.' + settings.simpleTest[this.id].testClass);
|
| 19 |
var direction = settings.simpleTest[this.id].imageDirection;
|
| 20 |
var row = direction ? trs.size() - 1 : 0;
|
| 21 |
|
| 22 |
// If clicked in the middle of expanding a group, stop so we can switch directions.
|
| 23 |
if (timeout) {
|
| 24 |
clearTimeout(timeout);
|
| 25 |
}
|
| 26 |
|
| 27 |
// Function to toggle an individual row according to the current direction.
|
| 28 |
// We set a timeout of 20 ms until the next row will be shown/hidden to
|
| 29 |
// create a sliding effect.
|
| 30 |
function rowToggle() {
|
| 31 |
if (direction) {
|
| 32 |
if (row >= 0) {
|
| 33 |
$(trs[row]).hide();
|
| 34 |
row--;
|
| 35 |
timeout = setTimeout(rowToggle, 20);
|
| 36 |
}
|
| 37 |
}
|
| 38 |
else {
|
| 39 |
if (row < trs.size()) {
|
| 40 |
$(trs[row]).removeClass('js-hide').show();
|
| 41 |
row++;
|
| 42 |
timeout = setTimeout(rowToggle, 20);
|
| 43 |
}
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
// Kick-off the toggling upon a new click.
|
| 48 |
rowToggle();
|
| 49 |
|
| 50 |
// Toggle the arrow image next to the test group title.
|
| 51 |
$(this).html(settings.simpleTest.images[(direction ? 0 : 1)]);
|
| 52 |
settings.simpleTest[this.id].imageDirection = !direction;
|
| 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').each(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);
|