simpletest.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. (function ($) {
  2. /**
  3. * Add the cool table collapsing on the testing overview page.
  4. */
  5. Drupal.behaviors.simpleTestMenuCollapse = {
  6. attach: function (context, settings) {
  7. var timeout = null;
  8. // Adds expand-collapse functionality.
  9. $('div.simpletest-image').once('simpletest-image', function () {
  10. var $this = $(this);
  11. var direction = settings.simpleTest[this.id].imageDirection;
  12. $this.html(settings.simpleTest.images[direction]);
  13. // Adds group toggling functionality to arrow images.
  14. $this.click(function () {
  15. var trs = $this.closest('tbody').children('.' + settings.simpleTest[this.id].testClass);
  16. var direction = settings.simpleTest[this.id].imageDirection;
  17. var row = direction ? trs.length - 1 : 0;
  18. // If clicked in the middle of expanding a group, stop so we can switch directions.
  19. if (timeout) {
  20. clearTimeout(timeout);
  21. }
  22. // Function to toggle an individual row according to the current direction.
  23. // We set a timeout of 20 ms until the next row will be shown/hidden to
  24. // create a sliding effect.
  25. function rowToggle() {
  26. if (direction) {
  27. if (row >= 0) {
  28. $(trs[row]).hide();
  29. row--;
  30. timeout = setTimeout(rowToggle, 20);
  31. }
  32. }
  33. else {
  34. if (row < trs.length) {
  35. $(trs[row]).removeClass('js-hide').show();
  36. row++;
  37. timeout = setTimeout(rowToggle, 20);
  38. }
  39. }
  40. }
  41. // Kick-off the toggling upon a new click.
  42. rowToggle();
  43. // Toggle the arrow image next to the test group title.
  44. $this.html(settings.simpleTest.images[(direction ? 0 : 1)]);
  45. settings.simpleTest[this.id].imageDirection = !direction;
  46. });
  47. });
  48. }
  49. };
  50. /**
  51. * Select/deselect all the inner checkboxes when the outer checkboxes are
  52. * selected/deselected.
  53. */
  54. Drupal.behaviors.simpleTestSelectAll = {
  55. attach: function (context, settings) {
  56. $('td.simpletest-select-all').once('simpletest-select-all', function () {
  57. var testCheckboxes = settings.simpleTest['simpletest-test-group-' + $(this).attr('id')].testNames;
  58. var groupCheckbox = $('<input type="checkbox" class="form-checkbox" id="' + $(this).attr('id') + '-select-all" />');
  59. // Each time a single-test checkbox is checked or unchecked, make sure
  60. // that the associated group checkbox gets the right state too.
  61. var updateGroupCheckbox = function () {
  62. var checkedTests = 0;
  63. for (var i = 0; i < testCheckboxes.length; i++) {
  64. $('#' + testCheckboxes[i]).each(function () {
  65. if (($(this).attr('checked'))) {
  66. checkedTests++;
  67. }
  68. });
  69. }
  70. $(groupCheckbox).attr('checked', (checkedTests == testCheckboxes.length));
  71. };
  72. // Have the single-test checkboxes follow the group checkbox.
  73. groupCheckbox.change(function () {
  74. var checked = !!($(this).attr('checked'));
  75. for (var i = 0; i < testCheckboxes.length; i++) {
  76. $('#' + testCheckboxes[i]).attr('checked', checked);
  77. }
  78. });
  79. // Have the group checkbox follow the single-test checkboxes.
  80. for (var i = 0; i < testCheckboxes.length; i++) {
  81. $('#' + testCheckboxes[i]).change(function () {
  82. updateGroupCheckbox();
  83. });
  84. }
  85. // Initialize status for the group checkbox correctly.
  86. updateGroupCheckbox();
  87. $(this).append(groupCheckbox);
  88. });
  89. }
  90. };
  91. })(jQuery);