| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | (function () { |
| 4 | function initMergeBox(root) { |
| 5 | const openButton = root.querySelector("[data-pull-merge-open]"); |
| 6 | const cancelButton = root.querySelector("[data-pull-merge-cancel]"); |
| 7 | const choice = root.querySelector("[data-pull-merge-choice]"); |
| 8 | const confirm = root.querySelector("[data-pull-merge-confirm]"); |
| 9 | const method = root.querySelector("[data-pull-merge-method]"); |
| 10 | const confirmMethod = root.querySelector("[data-pull-merge-confirm-method]"); |
| 11 | const subject = root.querySelector("[data-pull-merge-subject]"); |
| 12 | if (!openButton || !choice || !confirm) return; |
| 13 | |
| 14 | function syncMethod() { |
| 15 | if (method && confirmMethod) confirmMethod.value = method.value; |
| 16 | } |
| 17 | |
| 18 | openButton.addEventListener("click", function () { |
| 19 | syncMethod(); |
| 20 | choice.hidden = true; |
| 21 | confirm.hidden = false; |
| 22 | if (subject) subject.focus(); |
| 23 | }); |
| 24 | |
| 25 | if (cancelButton) { |
| 26 | cancelButton.addEventListener("click", function () { |
| 27 | confirm.hidden = true; |
| 28 | choice.hidden = false; |
| 29 | openButton.focus(); |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | if (method) method.addEventListener("change", syncMethod); |
| 34 | } |
| 35 | |
| 36 | document.querySelectorAll("[data-pull-merge-box]").forEach(initMergeBox); |
| 37 | })(); |