diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-14 16:35:02 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-14 16:35:02 +0200 |
| commit | b282797767e6980ebad340e352bef4b0552c150d (patch) | |
| tree | ce0c56245a76b8d15142fb7bd70489aacd47d844 /app/views/revisions/index.html.erb | |
| parent | dcdc892d940adffced3d2bc272d813a47c7d4700 (diff) | |
Move the revision picker into admin_interface.js
Diffstat (limited to 'app/views/revisions/index.html.erb')
| -rw-r--r-- | app/views/revisions/index.html.erb | 62 |
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 %> | ||
