var COMPILER_TARGET_DEFAULT = {if !VISITOR_USE_TINY_BUILD || $__wcf->user->userID}true{else}false{/if};
{/if}
- {if $__wcf->getStyleHandler()->getStyle()->hasDarkMode}
+ {if $__wcf->getStyleHandler()->getColorScheme() === 'system'}
{
- let colorScheme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
- try {
- const value = localStorage.getItem("wsc_colorScheme");
- if (value === "light" || value === "dark") {
- colorScheme = value;
- }
- } catch {}
-
+ const colorScheme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
document.documentElement.dataset.colorScheme = colorScheme;
}
{/if}
import { PageMenuMainProvider } from "./Ui/Page/Menu/Main/Provider";
import { whenFirstSeen } from "./LazyLoader";
import { adoptPageOverlayContainer } from "./Helper/PageOverlay";
+import User from "./User"
import type { ColorScheme } from "./Controller/Style/ColorScheme";
DomChangeListener.add("WoltLabSuite/Core/Bootstrap", () => initA11y);
- if (options.colorScheme === "system") {
- void import("./Controller/Style/ColorScheme").then(({ setup }) => setup());
+ if (options.colorScheme === "system" && User.userId) {
+ void import("./Controller/Style/ColorScheme").then(({ setup }) => setup(options.colorScheme));
}
whenFirstSeen("[data-report-content]", () => {
* @copyright 2001-2023 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.0
+ * @woltlabExcludeBundle tiny
*/
import { getPhrase } from "WoltLabSuite/Core/Language";
} else {
applySystemScheme();
}
-
- try {
- localStorage.setItem("wsc_colorScheme", currentScheme);
- } catch {
- /* Ignore any errors when accessing the `localStorage`. */
- }
}
function applySystemScheme(): void {
});
}
-export function setup(): void {
+export function setup(colorScheme: ColorScheme): void {
const button = document.querySelector<HTMLElement>(".jsButtonStyleColorScheme");
if (button) {
- initializeButton(button);
- }
-
- try {
- const value = localStorage.getItem("wsc_colorScheme");
- if (value === "light" || value === "dark") {
- currentScheme = value;
- }
- } catch {
- /* Ignore any errors when accessing the `localStorage`. */
+ //initializeButton(button);
}
+ currentScheme = colorScheme;
themeColor = document.querySelector('meta[name="theme-color"]')!;
mediaQuery = matchMedia("(prefers-color-scheme: dark)");
<html
dir="{@$__wcf->getLanguage()->getPageDirection()}"
lang="{$__wcf->getLanguage()->getBcp47()}"
- data-color-scheme="system"
+ data-color-scheme="{$__wcf->getStyleHandler()->getColorScheme()}"
>
<head>
<meta charset="utf-8">
{* Unlike the frontend, this option must be defined in the ACP at all times. *}
var COMPILER_TARGET_DEFAULT = true;
+ {if $__wcf->getStyleHandler()->getColorScheme() === 'system'}
{
- let colorScheme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
- try {
- const value = localStorage.getItem("wsc_colorScheme");
- if (value === "light" || value === "dark") {
- colorScheme = value;
- }
- } catch {}
-
+ const colorScheme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
document.documentElement.dataset.colorScheme = colorScheme;
}
+ {/if}
</script>
<script data-eager="true" src="{$__wcf->getPath()}js/WoltLabSuite/WebComponent.js?v={@LAST_UPDATE_TIME}"></script>
AcpBootstrap.setup({
bootstrap: {
- enableMobileMenu: {if PACKAGE_ID && $__isLogin|empty}true{else}false{/if}
+ colorScheme: '{@$__wcf->getStyleHandler()->getColorScheme()|encodeJS}',
+ enableMobileMenu: {if PACKAGE_ID && $__isLogin|empty}true{else}false{/if},
}
});
});
* @copyright 2001-2022 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
-define(["require", "exports", "tslib", "./Core", "./Date/Picker", "./Devtools", "./Dom/Change/Listener", "./Environment", "./Event/Handler", "./Form/XsrfToken", "./Language", "./Ui/Dialog", "./Ui/Dropdown/Simple", "./Ui/Mobile", "./Ui/Page/Action", "./Ui/TabMenu", "./Ui/Tooltip", "./Ui/Page/JumpTo", "./Ui/Password", "./Ui/Empty", "./Ui/Object/Action", "./Ui/Object/Action/Delete", "./Ui/Object/Action/Toggle", "./Ui/Search", "./LazyLoader", "./Helper/PageOverlay", "perfect-scrollbar"], function (require, exports, tslib_1, Core, Picker_1, Devtools_1, Listener_1, Environment, EventHandler, XsrfToken, Language, Dialog_1, Simple_1, UiMobile, UiPageAction, UiTabMenu, UiTooltip, UiPageJumpTo, UiPassword, UiEmpty, UiObjectAction, UiObjectActionDelete, UiObjectActionToggle, Search_1, LazyLoader_1, PageOverlay_1) {
+define(["require", "exports", "tslib", "./Core", "./Date/Picker", "./Devtools", "./Dom/Change/Listener", "./Environment", "./Event/Handler", "./Form/XsrfToken", "./Language", "./Ui/Dialog", "./Ui/Dropdown/Simple", "./Ui/Mobile", "./Ui/Page/Action", "./Ui/TabMenu", "./Ui/Tooltip", "./Ui/Page/JumpTo", "./Ui/Password", "./Ui/Empty", "./Ui/Object/Action", "./Ui/Object/Action/Delete", "./Ui/Object/Action/Toggle", "./Ui/Search", "./LazyLoader", "./Helper/PageOverlay", "./User", "perfect-scrollbar"], function (require, exports, tslib_1, Core, Picker_1, Devtools_1, Listener_1, Environment, EventHandler, XsrfToken, Language, Dialog_1, Simple_1, UiMobile, UiPageAction, UiTabMenu, UiTooltip, UiPageJumpTo, UiPassword, UiEmpty, UiObjectAction, UiObjectActionDelete, UiObjectActionToggle, Search_1, LazyLoader_1, PageOverlay_1, User_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setup = void 0;
UiObjectAction = tslib_1.__importStar(UiObjectAction);
UiObjectActionDelete = tslib_1.__importStar(UiObjectActionDelete);
UiObjectActionToggle = tslib_1.__importStar(UiObjectActionToggle);
+ User_1 = tslib_1.__importDefault(User_1);
// non strict equals by intent
if (window.WCF == null) {
window.WCF = {};
});
initA11y();
Listener_1.default.add("WoltLabSuite/Core/Bootstrap", () => initA11y);
- if (options.colorScheme === "system") {
- void new Promise((resolve_1, reject_1) => { require(["./Controller/Style/ColorScheme"], resolve_1, reject_1); }).then(tslib_1.__importStar).then(({ setup }) => setup());
+ if (options.colorScheme === "system" && User_1.default.userId) {
+ void new Promise((resolve_1, reject_1) => { require(["./Controller/Style/ColorScheme"], resolve_1, reject_1); }).then(tslib_1.__importStar).then(({ setup }) => setup(options.colorScheme));
}
(0, LazyLoader_1.whenFirstSeen)("[data-report-content]", () => {
void new Promise((resolve_2, reject_2) => { require(["./Ui/Moderation/Report"], resolve_2, reject_2); }).then(tslib_1.__importStar).then(({ setup }) => setup());
* @copyright 2001-2023 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.0
+ * @woltlabExcludeBundle tiny
*/
define(["require", "exports", "WoltLabSuite/Core/Language", "../../Ui/Dropdown/Builder", "../../Ui/Dropdown/Simple"], function (require, exports, Language_1, Builder_1, Simple_1) {
"use strict";
else {
applySystemScheme();
}
- try {
- localStorage.setItem("wsc_colorScheme", currentScheme);
- }
- catch {
- /* Ignore any errors when accessing the `localStorage`. */
- }
}
function applySystemScheme() {
if (currentScheme === "system") {
}
});
}
- function setup() {
+ function setup(colorScheme) {
const button = document.querySelector(".jsButtonStyleColorScheme");
if (button) {
- initializeButton(button);
- }
- try {
- const value = localStorage.getItem("wsc_colorScheme");
- if (value === "light" || value === "dark") {
- currentScheme = value;
- }
- }
- catch {
- /* Ignore any errors when accessing the `localStorage`. */
+ //initializeButton(button);
}
+ currentScheme = colorScheme;
themeColor = document.querySelector('meta[name="theme-color"]');
mediaQuery = matchMedia("(prefers-color-scheme: dark)");
mediaQuery.addEventListener("change", () => {
}
/**
- * The color scheme is 'light' for styles without a dark mode. For styles
- * with a dark mode, the special value 'system' is used to indicate that
- * the client is able to negotiate a color scheme.
+ * Returns the preferred color scheme of the user. For guests this value
+ * will always be 'system' to indicate that the device preferences should
+ * be used to negotiate the color scheme.
*
* @since 6.0
*/
public function getColorScheme(): string
{
- if ($this->getStyle()->hasDarkMode) {
+ if (!WCF::getUser()->userID) {
return 'system';
}
- return 'light';
+ return WCF::getUser()->getUserOption('colorScheme');
}
}