Dark "Are you sure?" dialog on dark pages

rails-ujs confirmations (data-confirm) show a dark dialog in Gitea's colours while the page is dark,
instead of the browser's box drawn in the device's colours; OK carries on with the link, button or
form. Light pages keep the browser's box. RedmineDarkMode.confirm(message, onOk) does the same for
other scripts. The default mode is one setting (DEFAULT_MODE, Automatic).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-02 22:22:50 -05:00
1 parent ad2451129f
commit 885c4d2b3a
6 files changed
+120 -6

No files matched your search

+73
View File
@@ -53,3 +53,76 @@
if (media.addEventListener) media.addEventListener('change', function () { render(button); });
});
})();
// "Are you sure?" confirmations (data-confirm, through rails-ujs). The browser draws its own box in the device's
// colours, so on a dark page it can flash up bright; while the page is dark, a dark dialog asks instead, and OK
// carries on with the link, button or form. Light pages keep the browser's box.
(function () {
if (!window.RedmineDarkMode || !window.HTMLDialogElement) return;
var nativeConfirm = window.Rails && Rails.confirm;
var approved = null;
function ask(message, onOk) {
var labels = window.RedmineDarkMode.labels;
var dialog = document.createElement('dialog');
dialog.className = 'dark-mode-confirm';
var text = document.createElement('p');
text.textContent = message;
var buttons = document.createElement('div');
buttons.className = 'dark-mode-confirm-buttons';
var cancel = document.createElement('button');
cancel.type = 'button';
cancel.textContent = labels.cancel;
var ok = document.createElement('button');
ok.type = 'button';
ok.className = 'dark-mode-confirm-ok';
ok.textContent = labels.ok;
buttons.append(cancel, ok);
dialog.append(text, buttons);
document.body.appendChild(dialog);
var confirmed = false;
cancel.addEventListener('click', function () { dialog.close(); });
ok.addEventListener('click', function () { confirmed = true; dialog.close(); });
// Clicking the dimmed page outside the dialog cancels, like Escape
dialog.addEventListener('click', function (e) { if (e.target === dialog) dialog.close(); });
dialog.addEventListener('close', function () {
dialog.remove();
if (confirmed) onOk();
});
dialog.showModal();
ok.focus();
}
// For other scripts: asks in the dark dialog on dark pages, or the browser's box on light ones, then runs onOk
window.RedmineDarkMode.confirm = function (message, onOk) {
if (document.documentElement.classList.contains('dark-mode')) {
ask(message, onOk);
} else if (window.confirm(message)) {
onOk();
}
};
if (!window.Rails) return;
Rails.confirm = function (message, element) {
if (!document.documentElement.classList.contains('dark-mode')) {
return nativeConfirm ? nativeConfirm(message, element) : window.confirm(message);
}
// The second pass, after OK: let it through
if (approved === element) {
approved = null;
return true;
}
ask(message, function () {
approved = element;
if (element.tagName === 'FORM') {
element.requestSubmit ? element.requestSubmit() : element.submit();
} else {
element.click();
}
});
return false;
};
})();
+37
View File
@@ -430,3 +430,40 @@ html.dark-mode .label-sub { color: #969aa1; }
html.dark-mode .box-white,
html.dark-mode div.issue_template { background-color: #1e1f20; }
html.dark-mode fieldset.issue { background-color: #191a1c; }
/* The dark "Are you sure?" dialog (dark_mode.js), in place of the browser's bright one */
dialog.dark-mode-confirm {
min-width: 320px;
max-width: min(90vw, 480px);
padding: 0;
border: 1px solid #3f4248;
border-radius: 8px;
background: #1e1f20;
color: #d2d4d8;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
font-size: 1rem;
}
dialog.dark-mode-confirm::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.dark-mode-confirm p { margin: 0; padding: 20px 20px 16px; white-space: pre-line; }
.dark-mode-confirm-buttons {
display: flex;
justify-content: flex-end;
gap: 8px;
padding: 12px 16px;
border-top: 1px solid #3f4248;
background: #1b1c1e;
border-radius: 0 0 8px 8px;
}
.dark-mode-confirm-buttons button {
min-width: 80px;
padding: 6px 14px;
border: 1px solid #3f4248;
border-radius: 4px;
background: #2c2e32;
color: #d2d4d8;
font: inherit;
cursor: pointer;
}
.dark-mode-confirm-buttons button:hover { background: #35373c; }
.dark-mode-confirm-buttons button.dark-mode-confirm-ok { background: #4183c4; border-color: #4183c4; color: #fff; }
.dark-mode-confirm-buttons button.dark-mode-confirm-ok:hover { background: #548fca; border-color: #548fca; }