Skip to content

Commit

Permalink
Add auto/manual color scheme stylesheets depending on user preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Dec 1, 2024
1 parent 8a020b3 commit 2ca74ab
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 7 deletions.
1 change: 0 additions & 1 deletion app/assets/stylesheets/parameters.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ $table-border-factor: .1;
$list-group-hover-bg: rgba(var(--bs-emphasis-color-rgb), .075);

$enable-negative-margins: true;
$color-mode-type: media-query;
3 changes: 3 additions & 0 deletions app/assets/stylesheets/screen-auto-ltr.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: media-query
);
3 changes: 3 additions & 0 deletions app/assets/stylesheets/screen-auto-rtl.rtlcss.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: media-query
);
1 change: 0 additions & 1 deletion app/assets/stylesheets/screen-ltr.scss

This file was deleted.

3 changes: 3 additions & 0 deletions app/assets/stylesheets/screen-manual-ltr.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: data
);
3 changes: 3 additions & 0 deletions app/assets/stylesheets/screen-manual-rtl.rtlcss.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: data
);
1 change: 0 additions & 1 deletion app/assets/stylesheets/screen-rtl.rtlcss.scss

This file was deleted.

10 changes: 9 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,15 @@ def preferred_editor
end
end

helper_method :preferred_editor
def preferred_site_color_scheme
if current_user
current_user.preferences.find_by(:k => "site.color_scheme")&.v || "auto"
else
"auto"
end
end

helper_method :preferred_editor, :preferred_site_color_scheme

def update_totp
if Settings.key?(:totp_key)
Expand Down
6 changes: 5 additions & 1 deletion app/views/layouts/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
<%= javascript_include_tag "turbo", :type => "module" %>
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "i18n/#{I18n.locale}" %>
<%= stylesheet_link_tag "screen-#{dir}", :media => "screen" %>
<% if preferred_site_color_scheme == "auto" %>
<%= stylesheet_link_tag "screen-auto-#{dir}", :media => "screen" %>
<% else %>
<%= stylesheet_link_tag "screen-manual-#{dir}", :media => "screen" %>
<% end %>
<%= stylesheet_link_tag "print-#{dir}", :media => "print" %>
<%= stylesheet_link_tag "leaflet-all", :media => "screen, print" %>
<%= render :partial => "layouts/meta" %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/site.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<%= I18n.locale %>" dir="<%= dir %>">
<%= tag.html :lang => I18n.locale, :dir => dir, :data => { :bs_theme => (preferred_site_color_scheme if preferred_site_color_scheme != "auto") } do %>
<%= render :partial => "layouts/head" %>
<body class="<%= body_class %>">
<%= render :partial => "layouts/header" %>
Expand All @@ -8,4 +8,4 @@
<noscript><p><img src="<%= request.protocol %><%= Settings.matomo["location"] %>/matomo.php?idsite=<%= Settings.matomo["site"] %>" class="matomo" alt="" /></p></noscript>
<% end -%>
</body>
</html>
<% end %>

0 comments on commit 2ca74ab

Please sign in to comment.