Merge lp:~twom/loggerhead/side-by-side-js-fix into lp:loggerhead

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 508
Merged at revision: 511
Proposed branch: lp:~twom/loggerhead/side-by-side-js-fix
Merge into: lp:loggerhead
Prerequisite: lp:~twom/loggerhead/animation-binding
Diff against target: 129 lines (+21/-19)
1 file modified
loggerhead/static/javascript/diff.js (+21/-19)
To merge this branch: bzr merge lp:~twom/loggerhead/side-by-side-js-fix
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+390569@code.launchpad.net

Commit message

Fix side-by-side diffs

Description of the change

The diff JS wasn't transliterated to jQuery completely, fix showing side-by-side and unified diffs by using the correct methods.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loggerhead/static/javascript/diff.js'
2--- loggerhead/static/javascript/diff.js 2020-09-10 16:51:28 +0000
3+++ loggerhead/static/javascript/diff.js 2020-09-10 16:51:28 +0000
4@@ -1,6 +1,6 @@
5 var unified = true;
6
7-function make_unified(chunk) {
8+function make_unified(index) {
9 var pending_added = [];
10 function flush_adds(before) {
11 for (var i = 0; i < pending_added.length; i++) {
12@@ -8,24 +8,25 @@
13 }
14 pending_added.length = 0;
15 }
16- chunk.get('children').filter(".pseudorow").each(
17+ $(this).children().filter(".pseudorow").each(
18 function (i, line) {
19+ line = $(line);
20 if (line.hasClass("context-row")) {
21 flush_adds(line);
22- line.removeChild($(line).find('.code'));
23+ line.find('.code')[0].remove();
24 }
25 else if (line.hasClass("both-row")) {
26- var added_line = line.create('<div class="pseudorow insert-row"><div class="lineNumber first">&nbsp;</div><div class="clear">&nbsp;</div></div>');
27+ var added_line = $('<div class="pseudorow insert-row"><div class="lineNumber first">&nbsp;</div><div class="clear">&nbsp;</div></div>');
28 var clear = $(added_line).find('.clear');
29 $(line).find('.lineNumber.second').insertBefore(clear);
30 $(line).find('.code.insert').insertBefore(clear);
31 pending_added[pending_added.length] = added_line;
32 $('<div class="lineNumber second">&nbsp;</div>').insertBefore($(line).find('.code.delete'));
33- line.replaceClass("both-row", "delete-row");
34+ line.addClass('delete-row').removeClass('both-row');
35 }
36 else if (line.hasClass("insert-row")) {
37 flush_adds(line);
38- line.removeChild($(line).find('.blank'));
39+ line.find('.blank').remove();
40 }
41 else if (line.hasClass("delete-row")) {
42 $(line).find('.blank').remove();
43@@ -33,10 +34,10 @@
44 }
45 });
46 flush_adds(null);
47- chunk.replaceClass('sbs', 'unified');
48+ $(this).addClass('unified').removeClass('sbs');
49 }
50
51-function make_sbs(chunk) {
52+function make_sbs(index) {
53 var added = [];
54 var removed = [];
55 function clear_bufs(before) {
56@@ -45,33 +46,34 @@
57 for (var i = 0; i < common; i++) {
58 var a = added[i];
59 var r = removed[i];
60- a.ancestor().removeChild(a);
61- r.removeChild($(r).find('.lineNumber.second'));
62+ a.remove();
63+ r.find('.lineNumber.second').remove();
64 $(a).find('.lineNumber.second').insertBefore($(r).find('.clear'));
65 $(a).find('.code.insert').insertBefore($(r).find('.clear'));
66- r.replaceClass('removed-row', 'both-row');
67+ r.addClass('both-row').removeClass('removed-row');
68 }
69 if (added.length > removed.length) {
70 for (var j = common; j < added.length; j++) {
71 a = $(added[j]);
72- $('<div class="code blank">&nbsp;</div>').insertBefore(a.find('.lineNumber.second'));
73+ a.find('.lineNumber.second').before('<div class="code blank">&nbsp;</div>');
74 }
75 }
76 else if (added.length < removed.length) {
77 for (var j = common; j < removed.length; j++) {
78 r = $(removed[j]);
79 r.find('.code.delete').insertBefore(r.find('.lineNumber.second'));
80- r.create('<div class="code blank">&nbsp;</div>').insertBefore(r.find('.clear'));
81+ r.find('.clear').before('<div class="code blank">&nbsp;</div>')
82 }
83 }
84 added.length = 0;
85 removed.length = 0;
86 }
87- chunk.get('children').filter(".pseudorow").each(
88+ $(this).children().filter(".pseudorow").each(
89 function (i, line) {
90+ line = $(line);
91 if (line.hasClass("context-row")) {
92 clear_bufs(line);
93- $(line).find('.code').cloneNode(true).insertBefore($(line).find(".second"));
94+ $(line).find(".second").before($(line).find('.code').clone());
95 }
96 else if (line.hasClass("insert-row")) {
97 added[added.length] = line;
98@@ -81,7 +83,7 @@
99 }
100 });
101 clear_bufs(null);
102- chunk.replaceClass('unified', 'sbs');
103+ $(this).addClass('sbs').removeClass('unified');
104
105 }
106
107@@ -91,12 +93,12 @@
108 if (unified) {
109 pts && pts.each(make_sbs);
110 unified = false;
111- $("#toggle_unified_sbs").set('innerHTML', "Show unified diffs");
112+ $("#toggle_unified_sbs").html("Show unified diffs");
113 }
114 else {
115 pts && pts.each(make_unified);
116 unified = true;
117- $("#toggle_unified_sbs").set('innerHTML', "Show diffs side-by-side");
118+ $("#toggle_unified_sbs").html("Show diffs side-by-side");
119 }
120 }
121
122@@ -149,7 +151,7 @@
123
124 function node_process(node) {
125 if (!unified) {
126- node.get('children').filter('.pseudotable').each(make_sbs);
127+ node.children().filter('.pseudotable').each(make_sbs);
128 }
129 }
130

Subscribers

People subscribed via source and target branches