diff.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (function ($) {
  2. Drupal.behaviors.diffRevisions = {
  3. attach: function (context, settings) {
  4. var $rows = $('table.diff-revisions tbody tr');
  5. function updateDiffRadios() {
  6. var newTd = false;
  7. var oldTd = false;
  8. if (!$rows.length) {
  9. return true;
  10. }
  11. $rows.removeClass('selected').each(function() {
  12. var $row = $(this);
  13. $row.removeClass('selected');
  14. var $inputs = $row.find('input[type="radio"]');
  15. var $oldRadio = $inputs.filter('[name="old"]').eq(0);
  16. var $newRadio = $inputs.filter('[name="new"]').eq(0);
  17. if (!$oldRadio.length || !$newRadio.length) {
  18. return true;
  19. }
  20. if ($oldRadio.attr('checked')) {
  21. oldTd = true;
  22. $row.addClass('selected');
  23. $oldRadio.css('visibility', 'visible');
  24. $newRadio.css('visibility', 'hidden');
  25. } else if ($newRadio.attr('checked')) {
  26. newTd = true;
  27. $row.addClass('selected');
  28. $oldRadio.css('visibility', 'hidden');
  29. $newRadio.css('visibility', 'visible');
  30. } else {
  31. if (Drupal.settings.diffRevisionRadios == 'linear') {
  32. if (newTd && oldTd) {
  33. $oldRadio.css('visibility', 'visible');
  34. $newRadio.css('visibility', 'hidden');
  35. } else if (newTd) {
  36. $newRadio.css('visibility', 'visible');
  37. $oldRadio.css('visibility', 'visible');
  38. } else {
  39. $newRadio.css('visibility', 'visible');
  40. $oldRadio.css('visibility', 'hidden');
  41. }
  42. } else {
  43. $newRadio.css('visibility', 'visible');
  44. $oldRadio.css('visibility', 'visible');
  45. }
  46. }
  47. });
  48. return true;
  49. }
  50. if (Drupal.settings.diffRevisionRadios) {
  51. $rows.find('input[name="new"], input[name="old"]').click(updateDiffRadios);
  52. updateDiffRadios();
  53. }
  54. }
  55. };
  56. })(jQuery);