FIX: Set class on color scheme links in bootstrap (#13594)

Exposes to Ember CLI environment the feature provided in the production env by `lib/stylesheet/manager.rb:295`.

Fixes development env compatibility with discourse-color-scheme-toggle.
This commit is contained in:
Jarek Radosz 2021-07-01 10:58:26 +02:00 committed by GitHub
parent eb898e5523
commit e4aa02365c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -65,6 +65,9 @@ function head(buffer, bootstrap) {
if (s.theme_id) { if (s.theme_id) {
attrs.push(`data-theme-id="${s.theme_id}"`); attrs.push(`data-theme-id="${s.theme_id}"`);
} }
if (s.class) {
attrs.push(`class="${s.class}"`);
}
let link = `<link rel="stylesheet" type="text/css" href="${ let link = `<link rel="stylesheet" type="text/css" href="${
s.href s.href
}" ${attrs.join(" ")}></script>\n`; }" ${attrs.join(" ")}></script>\n`;

View File

@ -17,8 +17,10 @@ class BootstrapController < ApplicationController
end end
@stylesheets = [] @stylesheets = []
add_scheme(scheme_id, 'all')
add_scheme(dark_scheme_id, '(prefers-color-scheme: dark)') add_scheme(scheme_id, "all", "light-scheme")
add_scheme(dark_scheme_id, "(prefers-color-scheme: dark)", "dark-scheme")
if rtl? if rtl?
add_style(mobile_view? ? :mobile_rtl : :desktop_rtl) add_style(mobile_view? ? :mobile_rtl : :desktop_rtl)
else else
@ -73,11 +75,11 @@ class BootstrapController < ApplicationController
end end
private private
def add_scheme(scheme_id, media) def add_scheme(scheme_id, media, css_class)
return if scheme_id.to_i == -1 return if scheme_id.to_i == -1
if style = Stylesheet::Manager.new(theme_id: theme_id).color_scheme_stylesheet_details(scheme_id, media) if style = Stylesheet::Manager.new(theme_id: theme_id).color_scheme_stylesheet_details(scheme_id, media)
@stylesheets << { href: style[:new_href], media: media } @stylesheets << { href: style[:new_href], media: media, class: css_class }
end end
end end