Commit 57e4a73c authored by Aran Gilman's avatar Aran Gilman Committed by Commit Bot

Rewrite getClassFromElement() in a functional style.

This is part of a series of changes re-implementing (and hopefully
improving upon) cleanup performed in https://crrev.com/c/1922788. The
intent is to reduce the number of changes not directly related to the
new feature when relanding the CL.

Bug: 1027612

Change-Id: Ibbc6967e43695f348f53655e46d05a547f8bd2ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144674Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Aran Gilman <gilmanmh@google.com>
Auto-Submit: Aran Gilman <gilmanmh@google.com>
Cr-Commit-Position: refs/heads/master@{#758997}
parent 49a07dd7
...@@ -80,14 +80,10 @@ function useTheme(theme) { ...@@ -80,14 +80,10 @@ function useTheme(theme) {
updateToolbarColor(theme); updateToolbarColor(theme);
} }
function getClassFromElement(element, classList) { function getPageTheme() {
let foundClass = classList[0]; const cls = Array.from(document.body.classList)
classList.forEach((cls) => { .find((cls) => themeClasses.includes(cls));
if (element.classList.contains(cls)) { return cls ? cls : themeClasses[0];
foundClass = cls;
}
});
return foundClass;
} }
function updateToolbarColor(theme) { function updateToolbarColor(theme) {
...@@ -166,7 +162,9 @@ class FontSizeSlider { ...@@ -166,7 +162,9 @@ class FontSizeSlider {
const fontSizeSlider = new FontSizeSlider( const fontSizeSlider = new FontSizeSlider(
$('font-size-selection'), [14, 15, 16, 18, 20, 24, 28, 32, 40, 48]); $('font-size-selection'), [14, 15, 16, 18, 20, 24, 28, 32, 40, 48]);
updateToolbarColor(getClassFromElement(document.body, themeClasses)); // Set the toolbar color to match the page's theme.
updateToolbarColor(getPageTheme());
maybeSetWebFont(); maybeSetWebFont();
// The zooming speed relative to pinching speed. // The zooming speed relative to pinching speed.
......
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