From: Anton Khorev Date: Sat, 16 Nov 2024 14:51:50 +0000 (+0300) Subject: Add auto/manual color scheme stylesheets depending on user preferences X-Git-Tag: live~1^2~8 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/2ca74ab3ef47143cb42403f207e438eacda08dc5?ds=sidebyside;hp=8a020b3ec727b8c9fa4d819855469dd348e58ee7 Add auto/manual color scheme stylesheets depending on user preferences --- diff --git a/app/assets/stylesheets/parameters.scss b/app/assets/stylesheets/parameters.scss index 28bf56901..07549d69b 100644 --- a/app/assets/stylesheets/parameters.scss +++ b/app/assets/stylesheets/parameters.scss @@ -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; diff --git a/app/assets/stylesheets/screen-auto-ltr.scss b/app/assets/stylesheets/screen-auto-ltr.scss new file mode 100644 index 000000000..89e31599a --- /dev/null +++ b/app/assets/stylesheets/screen-auto-ltr.scss @@ -0,0 +1,3 @@ +@use "common" with ( + $color-mode-type: media-query +); diff --git a/app/assets/stylesheets/screen-auto-rtl.rtlcss.scss b/app/assets/stylesheets/screen-auto-rtl.rtlcss.scss new file mode 100644 index 000000000..89e31599a --- /dev/null +++ b/app/assets/stylesheets/screen-auto-rtl.rtlcss.scss @@ -0,0 +1,3 @@ +@use "common" with ( + $color-mode-type: media-query +); diff --git a/app/assets/stylesheets/screen-ltr.scss b/app/assets/stylesheets/screen-ltr.scss deleted file mode 100644 index c525060af..000000000 --- a/app/assets/stylesheets/screen-ltr.scss +++ /dev/null @@ -1 +0,0 @@ -@import "common"; diff --git a/app/assets/stylesheets/screen-manual-ltr.scss b/app/assets/stylesheets/screen-manual-ltr.scss new file mode 100644 index 000000000..00f65f79a --- /dev/null +++ b/app/assets/stylesheets/screen-manual-ltr.scss @@ -0,0 +1,3 @@ +@use "common" with ( + $color-mode-type: data +); diff --git a/app/assets/stylesheets/screen-manual-rtl.rtlcss.scss b/app/assets/stylesheets/screen-manual-rtl.rtlcss.scss new file mode 100644 index 000000000..00f65f79a --- /dev/null +++ b/app/assets/stylesheets/screen-manual-rtl.rtlcss.scss @@ -0,0 +1,3 @@ +@use "common" with ( + $color-mode-type: data +); diff --git a/app/assets/stylesheets/screen-rtl.rtlcss.scss b/app/assets/stylesheets/screen-rtl.rtlcss.scss deleted file mode 100644 index c525060af..000000000 --- a/app/assets/stylesheets/screen-rtl.rtlcss.scss +++ /dev/null @@ -1 +0,0 @@ -@import "common"; diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7ce804ced..56d9a6763 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -281,7 +281,15 @@ class ApplicationController < ActionController::Base 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) diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index 3c691612a..8cab52223 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -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" %> diff --git a/app/views/layouts/site.html.erb b/app/views/layouts/site.html.erb index 7c921658d..dd573d476 100644 --- a/app/views/layouts/site.html.erb +++ b/app/views/layouts/site.html.erb @@ -1,5 +1,5 @@ - +<%= 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" %> <%= render :partial => "layouts/header" %> @@ -8,4 +8,4 @@ <% end -%> - +<% end %>