diff.js 2.1 KB

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