25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 lines
3.8 KiB

  1. (function($){
  2. function convertDiff(name, table) {
  3. var inline = table.className == 'inline';
  4. var ths = table.tHead.rows[0].cells;
  5. var afile, bfile;
  6. if ( inline ) {
  7. afile = ths[0].title;
  8. bfile = ths[1].title;
  9. } else {
  10. afile = $(ths[0]).find('a').text();
  11. bfile = $(ths[1]).find('a').text();
  12. }
  13. if ( afile.match(/^Revision /) ) {
  14. afile = 'a/' + name;
  15. bfile = 'b/' + name;
  16. }
  17. var lines = [
  18. "Index: " + name,
  19. "===================================================================",
  20. "--- " + afile.replace(/File /, ''),
  21. "+++ " + bfile.replace(/File /, ''),
  22. ];
  23. var sepIndex = 0;
  24. var oldOffset = 0, oldLength = 0, newOffset = 0, newLength = 0;
  25. for (var i = 0; i < table.tBodies.length; i++) {
  26. var tBody = table.tBodies[i];
  27. if (i == 0 || tBody.className == "skipped") {
  28. if (i > 0) {
  29. if (!oldOffset && oldLength) oldOffset = 1
  30. if (!newOffset && newLength) newOffset = 1
  31. lines[sepIndex] = lines[sepIndex]
  32. .replace("{1}", oldOffset).replace("{2}", oldLength)
  33. .replace("{3}", newOffset).replace("{4}", newLength);
  34. }
  35. sepIndex = lines.length;
  36. lines.push("@@ -{1},{2} +{3},{4} @@");
  37. oldOffset = 0, oldLength = 0, newOffset = 0, newLength = 0;
  38. if (tBody.className == "skipped") continue;
  39. }
  40. var tmpLines = [];
  41. for (var j = 0; j < tBody.rows.length; j++) {
  42. var cells = tBody.rows[j].cells;
  43. var oldLineNo = parseInt($(cells[0]).text());
  44. var newLineNo = parseInt($(cells[inline ? 1 : 2]).text());
  45. if (tBody.className == 'unmod') {
  46. lines.push(" " + $(cells[inline ? 2 : 1]).text());
  47. oldLength += 1;
  48. newLength += 1;
  49. if (!oldOffset) oldOffset = oldLineNo;
  50. if (!newOffset) newOffset = newLineNo;
  51. } else {
  52. var oldLine;
  53. var newLine;
  54. if (inline) {
  55. oldLine = newLine = $(cells[2]).text();
  56. } else {
  57. oldLine = $(cells[1]).text();
  58. newLine = $(cells[3]).text();
  59. }
  60. if (!isNaN(oldLineNo)) {
  61. lines.push("-" + oldLine);
  62. oldLength += 1;
  63. }
  64. if (!isNaN(newLineNo)) {
  65. tmpLines.push("+" + newLine);
  66. newLength += 1;
  67. }
  68. }
  69. }
  70. if (tmpLines.length > 0) {
  71. lines = lines.concat(tmpLines);
  72. }
  73. }
  74. if (!oldOffset && oldLength) oldOffset = 1;
  75. if (!newOffset && newLength) newOffset = 1;
  76. lines[sepIndex] = lines[sepIndex]
  77. .replace("{1}", oldOffset).replace("{2}", oldLength)
  78. .replace("{3}", newOffset).replace("{4}", newLength);
  79. /* remove trailing &nbsp; and join lines (with CR for IExplorer) */
  80. for ( var i = 0; i < lines.length; i++ )
  81. if ( lines[i] )
  82. lines[i] = lines[i].replace(/\xa0$/, '');
  83. return lines.join($.browser.msie ? "\r" : "\n");
  84. }
  85. $(document).ready(function($) {
  86. $("div.diff h2").each(function() {
  87. var switcher = $("<span class='switch'></span>").prependTo(this);
  88. var name = $.trim($(this).text());
  89. var table = $(this).siblings("table").get(0);
  90. if (! table) return;
  91. var pre = $("<pre></pre>").hide().insertAfter(table);
  92. $("<span>Tabular</span>").click(function() {
  93. $(pre).hide();
  94. $(table).show();
  95. $(this).addClass("active").siblings("span").removeClass("active");
  96. return false;
  97. }).addClass("active").appendTo(switcher);
  98. $("<span>Unified</span>").click(function() {
  99. $(table).hide();
  100. if (!pre.get(0).firstChild) pre.text(convertDiff(name, table));
  101. $(pre).fadeIn("fast")
  102. $(this).addClass("active").siblings("span").removeClass("active");
  103. return false;
  104. }).appendTo(switcher);
  105. });
  106. });
  107. })(jQuery);