mirror of
https://github.com/rickbarrette/redmine_dark_mode.git
synced 2026-11-17 20:50:36 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a2f1fe3b8 | ||
|
|
786bb499b2 | ||
|
|
3e932e0612 | ||
|
|
62be748419 | ||
|
|
ba953295ee | ||
|
|
885c4d2b3a |
No files matched your search
@@ -24,12 +24,15 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function render(button) {
|
// The top bar's icon button, and on phones a line in the slide-out menu (the top bar is hidden there)
|
||||||
|
function render(button, link) {
|
||||||
var dm = window.RedmineDarkMode;
|
var dm = window.RedmineDarkMode;
|
||||||
var label = isDark() ? dm.labels.light : dm.labels.dark;
|
var label = isDark() ? dm.labels.light : dm.labels.dark;
|
||||||
button.innerHTML = isDark() ? SUN : MOON;
|
var icon = isDark() ? SUN : MOON;
|
||||||
|
button.innerHTML = icon;
|
||||||
button.title = label;
|
button.title = label;
|
||||||
button.setAttribute('aria-label', label);
|
button.setAttribute('aria-label', label);
|
||||||
|
if (link) link.innerHTML = icon + '<span>' + label + '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
@@ -39,17 +42,109 @@
|
|||||||
var button = document.createElement('button');
|
var button = document.createElement('button');
|
||||||
button.type = 'button';
|
button.type = 'button';
|
||||||
button.className = 'dark-mode-toggle';
|
button.className = 'dark-mode-toggle';
|
||||||
render(button);
|
|
||||||
button.addEventListener('click', function () {
|
var link = null;
|
||||||
|
var flyout = document.querySelector('.js-flyout-menu');
|
||||||
|
if (flyout) {
|
||||||
|
var list = document.createElement('ul');
|
||||||
|
list.className = 'dark-mode-flyout';
|
||||||
|
var item = document.createElement('li');
|
||||||
|
link = document.createElement('a');
|
||||||
|
link.href = '#';
|
||||||
|
link.className = 'dark-mode-flyout-toggle';
|
||||||
|
item.appendChild(link);
|
||||||
|
list.appendChild(item);
|
||||||
|
flyout.appendChild(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggle(e) {
|
||||||
|
e.preventDefault();
|
||||||
var mode = isDark() ? 'light' : 'dark';
|
var mode = isDark() ? 'light' : 'dark';
|
||||||
window.RedmineDarkMode.set(mode);
|
window.RedmineDarkMode.set(mode);
|
||||||
render(button);
|
render(button, link);
|
||||||
save(mode);
|
save(mode);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
render(button, link);
|
||||||
|
button.addEventListener('click', toggle);
|
||||||
|
if (link) link.addEventListener('click', toggle);
|
||||||
menu.insertBefore(button, menu.firstChild);
|
menu.insertBefore(button, menu.firstChild);
|
||||||
|
|
||||||
// The device switching light/dark (Automatic) changes the icon too
|
// The device switching light/dark (Automatic) changes the icon too
|
||||||
var media = window.matchMedia('(prefers-color-scheme: dark)');
|
var media = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
if (media.addEventListener) media.addEventListener('change', function () { render(button); });
|
if (media.addEventListener) media.addEventListener('change', function () { render(button, link); });
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// "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;
|
||||||
|
};
|
||||||
|
})();
|
||||||
@@ -196,6 +196,9 @@ html.dark-mode .tooltip:hover {
|
|||||||
/* Sticky issue title shown when scrolling down an issue (white in core) */
|
/* Sticky issue title shown when scrolling down an issue (white in core) */
|
||||||
html.dark-mode div#sticky-issue-header { background-color: var(--oc-white); color: var(--oc-gray-9); }
|
html.dark-mode div#sticky-issue-header { background-color: var(--oc-white); color: var(--oc-gray-9); }
|
||||||
|
|
||||||
|
/* The box behind the tab scroll arrows, shown when tabs don't fit, e.g. Administration > Settings (white in core) */
|
||||||
|
html.dark-mode div.tabs-buttons { background: var(--oc-white); }
|
||||||
|
|
||||||
/* Text formatting toolbar: its icons are dark drawings, so the buttons are inverted (interface icons only,
|
/* Text formatting toolbar: its icons are dark drawings, so the buttons are inverted (interface icons only,
|
||||||
never pictures); the background and border are set so they come out as the dark ones after inverting */
|
never pictures); the background and border are set so they come out as the dark ones after inverting */
|
||||||
html.dark-mode .jstElements button {
|
html.dark-mode .jstElements button {
|
||||||
@@ -245,6 +248,27 @@ html.dark-mode .item-description { color: #969aa1; }
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The phone slide-out menu's dark mode line, after the profile links */
|
||||||
|
.flyout-menu ul.dark-mode-flyout { margin-top: 12px; }
|
||||||
|
.flyout-menu .dark-mode-flyout-toggle { display: flex; align-items: center; gap: 8px; }
|
||||||
|
.flyout-menu .dark-mode-flyout-toggle svg { flex: none; }
|
||||||
|
|
||||||
|
/* Redmine's open slide-out menu is as tall as the page and the page can't scroll while it's open, so on a
|
||||||
|
phone its last lines (Sign out, this toggle) sat out of reach. Pinned to the screen, it scrolls by itself. */
|
||||||
|
@media screen and (max-width: 899px) {
|
||||||
|
.flyout-is-active .flyout-menu {
|
||||||
|
position: fixed;
|
||||||
|
inset-block: 0;
|
||||||
|
inset-inline-end: 0;
|
||||||
|
block-size: 100vh;
|
||||||
|
block-size: 100dvh;
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Issue boxes and other cards: Gitea's card colour instead of Redmine's pale yellow */
|
/* Issue boxes and other cards: Gitea's card colour instead of Redmine's pale yellow */
|
||||||
html.dark-mode div.issue { background: #191a1c; border-color: #3f4248; }
|
html.dark-mode div.issue { background: #191a1c; border-color: #3f4248; }
|
||||||
|
|
||||||
@@ -430,3 +454,40 @@ html.dark-mode .label-sub { color: #969aa1; }
|
|||||||
html.dark-mode .box-white,
|
html.dark-mode .box-white,
|
||||||
html.dark-mode div.issue_template { background-color: #1e1f20; }
|
html.dark-mode div.issue_template { background-color: #1e1f20; }
|
||||||
html.dark-mode fieldset.issue { background-color: #191a1c; }
|
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; }
|
||||||
@@ -15,3 +15,4 @@ en:
|
|||||||
label_dark_mode_dark: "On (dark)"
|
label_dark_mode_dark: "On (dark)"
|
||||||
label_dark_mode_switch_dark: "Switch to dark mode"
|
label_dark_mode_switch_dark: "Switch to dark mode"
|
||||||
label_dark_mode_switch_light: "Switch to light mode"
|
label_dark_mode_switch_light: "Switch to light mode"
|
||||||
|
button_dark_mode_ok: "OK"
|
||||||
@@ -12,7 +12,7 @@ Redmine::Plugin.register :redmine_dark_mode do
|
|||||||
name 'Redmine Dark Mode plugin'
|
name 'Redmine Dark Mode plugin'
|
||||||
author 'Rick Barrette'
|
author 'Rick Barrette'
|
||||||
description 'A dark mode for Redmine: follows the device by default, with a per-user choice and a toggle in the top menu'
|
description 'A dark mode for Redmine: follows the device by default, with a per-user choice and a toggle in the top menu'
|
||||||
version '2026.11.1'
|
version '2026.11.4'
|
||||||
url 'https://github.com/rickbarrette/redmine_dark_mode'
|
url 'https://github.com/rickbarrette/redmine_dark_mode'
|
||||||
author_url 'https://barrettefabrication.com'
|
author_url 'https://barrettefabrication.com'
|
||||||
requires_redmine version_or_higher: '7.0.0'
|
requires_redmine version_or_higher: '7.0.0'
|
||||||
|
|||||||
@@ -9,9 +9,12 @@
|
|||||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
module RedmineDarkMode
|
module RedmineDarkMode
|
||||||
# A user's choice: follow the device (the default), or always light or dark
|
# A user's choice: follow the device, or always light or dark
|
||||||
MODES = %w[auto light dark].freeze
|
MODES = %w[auto light dark].freeze
|
||||||
|
|
||||||
|
# Until someone chooses, Redmine follows their device
|
||||||
|
DEFAULT_MODE = 'auto'
|
||||||
|
|
||||||
def self.setup
|
def self.setup
|
||||||
UserPreference.prepend(RedmineDarkMode::UserPreferencePatch)
|
UserPreference.prepend(RedmineDarkMode::UserPreferencePatch)
|
||||||
UserPreference.safe_attributes 'dark_mode'
|
UserPreference.safe_attributes 'dark_mode'
|
||||||
@@ -20,9 +23,9 @@ module RedmineDarkMode
|
|||||||
RedmineDarkMode::Hooks
|
RedmineDarkMode::Hooks
|
||||||
end
|
end
|
||||||
|
|
||||||
# The mode for this user (anonymous users follow the device, or their browser's saved choice)
|
# The mode for this user: their choice, else the default (anonymous users: their browser's saved choice, else the default)
|
||||||
def self.mode_for(user)
|
def self.mode_for(user)
|
||||||
mode = user&.logged? ? user.pref.dark_mode : nil
|
mode = user&.logged? ? user.pref.dark_mode : nil
|
||||||
MODES.include?(mode) ? mode : 'auto'
|
MODES.include?(mode) ? mode : DEFAULT_MODE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -30,7 +30,7 @@ module RedmineDarkMode
|
|||||||
get mode() { return mode; },
|
get mode() { return mode; },
|
||||||
set: function (value) { mode = value; apply(); },
|
set: function (value) { mode = value; apply(); },
|
||||||
loggedIn: #{User.current.logged?.to_json},
|
loggedIn: #{User.current.logged?.to_json},
|
||||||
labels: #{{ dark: l(:label_dark_mode_switch_dark), light: l(:label_dark_mode_switch_light) }.to_json}
|
labels: #{{ dark: l(:label_dark_mode_switch_dark), light: l(:label_dark_mode_switch_light), ok: l(:button_dark_mode_ok), cancel: l(:button_cancel) }.to_json}
|
||||||
};
|
};
|
||||||
apply();
|
apply();
|
||||||
if (media.addEventListener) media.addEventListener('change', apply);
|
if (media.addEventListener) media.addEventListener('change', apply);
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ module RedmineDarkMode
|
|||||||
# Keeps the user's dark mode choice with their other preferences (My account)
|
# Keeps the user's dark mode choice with their other preferences (My account)
|
||||||
module UserPreferencePatch
|
module UserPreferencePatch
|
||||||
def dark_mode
|
def dark_mode
|
||||||
self[:dark_mode].presence || 'auto'
|
self[:dark_mode].presence || RedmineDarkMode::DEFAULT_MODE
|
||||||
end
|
end
|
||||||
|
|
||||||
def dark_mode=(value)
|
def dark_mode=(value)
|
||||||
self[:dark_mode] = RedmineDarkMode::MODES.include?(value.to_s) ? value.to_s : 'auto'
|
self[:dark_mode] = RedmineDarkMode::MODES.include?(value.to_s) ? value.to_s : RedmineDarkMode::DEFAULT_MODE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user