Commit c597b5d0 authored by Robert Speicher's avatar Robert Speicher

Fix Profile > Design live-updating

`ui_blue` wasn't added to the list of classes to remove, so if a user
changed to that theme, any subsequent changes wouldn't be live-updated.

This change refactors Gitlab::Theme a bit to make it harder for this to
happen in the future with new themes.
parent 3f2f40aa
// Remove body class for any previous theme, re-add current one // Remove body class for any previous theme, re-add current one
$('body').removeClass('ui_basic ui_mars ui_modern ui_gray ui_color light_theme dark_theme') $('body').removeClass('<%= Gitlab::Theme.body_classes %>')
$('body').addClass('<%= app_theme %> <%= theme_type %>') $('body').addClass('<%= app_theme %> <%= theme_type %>')
// Re-render the header to reflect the new theme // Re-render the header to reflect the new theme
......
...@@ -7,33 +7,44 @@ module Gitlab ...@@ -7,33 +7,44 @@ module Gitlab
COLOR = 5 unless const_defined?(:COLOR) COLOR = 5 unless const_defined?(:COLOR)
BLUE = 6 unless const_defined?(:BLUE) BLUE = 6 unless const_defined?(:BLUE)
def self.css_class_by_id(id) def self.classes
themes = { @classes ||= {
BASIC => "ui_basic", BASIC => 'ui_basic',
MARS => "ui_mars", MARS => 'ui_mars',
MODERN => "ui_modern", MODERN => 'ui_modern',
GRAY => "ui_gray", GRAY => 'ui_gray',
COLOR => "ui_color", COLOR => 'ui_color',
BLUE => "ui_blue" BLUE => 'ui_blue'
} }
end
def self.css_class_by_id(id)
id ||= Gitlab.config.gitlab.default_theme id ||= Gitlab.config.gitlab.default_theme
classes[id]
themes[id]
end end
def self.type_css_class_by_id(id) def self.types
types = { @types ||= {
BASIC => 'light_theme', BASIC => 'light_theme',
MARS => 'dark_theme', MARS => 'dark_theme',
MODERN => 'dark_theme', MODERN => 'dark_theme',
GRAY => 'dark_theme', GRAY => 'dark_theme',
COLOR => 'dark_theme' COLOR => 'dark_theme',
BLUE => 'light_theme'
} }
end
def self.type_css_class_by_id(id)
id ||= Gitlab.config.gitlab.default_theme id ||= Gitlab.config.gitlab.default_theme
types[id] types[id]
end end
# Convenience method to get a space-separated String of all the theme
# classes that mighty be applied to the `body` element
#
# Returns a String
def self.body_classes
(classes.values + types.values).uniq.join(' ')
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment