mirror of
https://github.com/rickbarrette/redmine_dark_mode.git
synced 2026-11-17 12:50:36 -05:00
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:
1 parent
ad2451129f
commit
885c4d2b3a
6 files changed
+120
-6
No files matched your search
@@ -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.
|
||||
|
||||
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
|
||||
|
||||
# Until someone chooses, Redmine follows their device
|
||||
DEFAULT_MODE = 'auto'
|
||||
|
||||
def self.setup
|
||||
UserPreference.prepend(RedmineDarkMode::UserPreferencePatch)
|
||||
UserPreference.safe_attributes 'dark_mode'
|
||||
@@ -20,9 +23,9 @@ module RedmineDarkMode
|
||||
RedmineDarkMode::Hooks
|
||||
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)
|
||||
mode = user&.logged? ? user.pref.dark_mode : nil
|
||||
MODES.include?(mode) ? mode : 'auto'
|
||||
MODES.include?(mode) ? mode : DEFAULT_MODE
|
||||
end
|
||||
end
|
||||
@@ -30,7 +30,7 @@ module RedmineDarkMode
|
||||
get mode() { return mode; },
|
||||
set: function (value) { mode = value; apply(); },
|
||||
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();
|
||||
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)
|
||||
module UserPreferencePatch
|
||||
def dark_mode
|
||||
self[:dark_mode].presence || 'auto'
|
||||
self[:dark_mode].presence || RedmineDarkMode::DEFAULT_MODE
|
||||
end
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user