Skip to content

Commit

Permalink
Darkmode could not be disabled (#8004)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skrypt authored Dec 15, 2020
1 parent 6834238 commit 749bde3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,32 @@ var observer = new MutationObserver(function (mutations) {
}
isCompactExplicit = adminPreferences.isCompactExplicit;

if (adminPreferences.darkMode){
html.setAttribute('data-theme', 'darkmode');
}
else
if(html.getAttribute('data-darkmode') === 'True')
{
html.setAttribute('data-theme', 'default');
if (adminPreferences.darkMode){
html.setAttribute('data-theme', 'darkmode');
}
else
{
html.setAttribute('data-theme', 'default');
}
}
}
else
{
body.classList.add('no-admin-preferences');

// Automatically sets darkmode based on OS preferences
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
{
html.setAttribute('data-theme', 'darkmode');
}
else
if(html.getAttribute('data-darkmode') === 'True')
{
html.setAttribute('data-theme', 'default');
// Automatically sets darkmode based on OS preferences
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
{
html.setAttribute('data-theme', 'darkmode');
}
else
{
html.setAttribute('data-theme', 'default');
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Themes/TheAdmin/Views/Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var darkMode = await DarkModeService.IsDarkModeAsync();
}
<!DOCTYPE html>
<html lang="@Orchard.CultureName()" dir="@Orchard.CultureDir()" data-theme="@DarkModeService.CurrentTheme">
<html lang="@Orchard.CultureName()" dir="@Orchard.CultureDir()" data-theme="@DarkModeService.CurrentTheme" data-darkmode="@adminSettings.DisplayDarkMode">
<head>
<title>@RenderTitleSegments(Site.SiteName, "before")</title>
<meta charset="utf-8">
Expand Down
25 changes: 15 additions & 10 deletions src/OrchardCore.Themes/TheAdmin/wwwroot/Scripts/TheAdmin-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ var observer = new MutationObserver(function (mutations) {

isCompactExplicit = adminPreferences.isCompactExplicit;

if (adminPreferences.darkMode) {
html.setAttribute('data-theme', 'darkmode');
} else {
html.setAttribute('data-theme', 'default');
if (html.getAttribute('data-darkmode') === 'True') {
if (adminPreferences.darkMode) {
html.setAttribute('data-theme', 'darkmode');
} else {
html.setAttribute('data-theme', 'default');
}
}
} else {
body.classList.add('no-admin-preferences'); // Automatically sets darkmode based on OS preferences

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
html.setAttribute('data-theme', 'darkmode');
} else {
html.setAttribute('data-theme', 'default');
body.classList.add('no-admin-preferences');

if (html.getAttribute('data-darkmode') === 'True') {
// Automatically sets darkmode based on OS preferences
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
html.setAttribute('data-theme', 'darkmode');
} else {
html.setAttribute('data-theme', 'default');
}
}
} // we're done:

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 749bde3

Please sign in to comment.