summaryrefslogtreecommitdiff
path: root/app/views/revisions
diff options
context:
space:
mode:
Diffstat (limited to 'app/views/revisions')
-rw-r--r--app/views/revisions/index.html.erb62
1 files changed, 0 insertions, 62 deletions
diff --git a/app/views/revisions/index.html.erb b/app/views/revisions/index.html.erb
index e951016f..4f854518 100644
--- a/app/views/revisions/index.html.erb
+++ b/app/views/revisions/index.html.erb
@@ -66,65 +66,3 @@
66 <% end %> 66 <% end %>
67 </tbody> 67 </tbody>
68</table> 68</table>
69
70<%= javascript_tag nonce: true do %>
71 (function () {
72 var table = document.getElementById('revisions');
73 var form = document.getElementById('diff_form');
74 if (!table || !form) { return; }
75
76 var from_field = form.querySelector('input[name="start_revision"]');
77 var to_field = form.querySelector('input[name="end_revision"]');
78 var from_label = document.getElementById('diff_from');
79 var to_label = document.getElementById('diff_to');
80 var readout = document.getElementById('diff_selection_label');
81 var submit = form.querySelector('input[type="submit"]');
82 var rows = table.querySelectorAll('tbody tr');
83
84 // Two-slot FIFO: the newest pick becomes the target and the previous
85 // target becomes the source, so two taps anywhere give any pair.
86 // Picking the current target is a no-op; picking the current source
87 // swaps them.
88 var stack = [from_field.value, to_field.value].filter(function (v) { return v !== ''; });
89
90 function render() {
91 var from = stack[0] || '';
92 var to = stack[1] || '';
93 from_field.value = from;
94 to_field.value = to;
95 from_label.textContent = from;
96 to_label.textContent = to;
97 readout.hidden = !(from && to);
98 submit.disabled = !(from && to && from !== to);
99
100 rows.forEach(function (row) {
101 var rev = row.dataset.revision;
102 row.classList.toggle('diff_source', rev === from);
103 row.classList.toggle('diff_target', rev === to);
104 row.setAttribute('aria-pressed', (rev === from || rev === to) ? 'true' : 'false');
105 });
106 }
107
108 function pick(rev) {
109 if (rev === stack[1]) { return; }
110 stack.push(rev);
111 if (stack.length > 2) { stack.shift(); }
112 render();
113 }
114
115 rows.forEach(function (row) {
116 row.addEventListener('click', function (e) {
117 if (e.target.closest('a, button, input, label')) { return; }
118 pick(row.dataset.revision);
119 });
120 row.addEventListener('keydown', function (e) {
121 if (e.key === 'Enter' || e.key === ' ') {
122 e.preventDefault();
123 pick(row.dataset.revision);
124 }
125 });
126 });
127
128 render();
129 })();
130<% end %>