Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
improve fallback behavior more
Browse files Browse the repository at this point in the history
  • Loading branch information
literalpie committed Oct 17, 2020
1 parent e656bf0 commit d8fb3f6
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": ["../Assets/ts/theme-switching.ts"],
"compilerOptions": {
"outFile": "../Resources/all.js"
"outFile": "../Sources/swift-doc/Resources/all.js"
}
}
4 changes: 4 additions & 0 deletions Assets/css/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ select {
outline: 0;
z-index: 9;
}

& option {
color: #3c3c43;
}
}

input[type="file"] {
Expand Down
7 changes: 6 additions & 1 deletion Assets/ts/theme-switching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ function updateDropdownLabel(systemTheme: "light" | "dark") {
function checkThemingSupport() {
const darkQuery = window.matchMedia('(prefers-color-scheme: dark)');
const lightQuery = window.matchMedia('(prefers-color-scheme: light)');
// If neither query matches, we know that the browser doesn't support theming
// If neither query matches, we know that the browser doesn't support theming.
if (!darkQuery.matches && !lightQuery.matches) {
const themeOptionAuto = window.document.getElementById('theme-option-auto');
// IE doesn't support element.remove()
themeOptionAuto.parentNode.removeChild(themeOptionAuto);
}
// If the browser does not support css properties, we do not allow theme switching.
const customProperty = getComputedStyle(document.body).getPropertyValue("--body");
if (!customProperty) {
(document.querySelector(".theme-select-container") as HTMLDivElement).style.display = 'none';
}
}
79 changes: 0 additions & 79 deletions Resources/all.js

This file was deleted.

1 change: 0 additions & 1 deletion Resources/all.min.css

This file was deleted.

8 changes: 6 additions & 2 deletions Sources/swift-doc/Resources/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@ function setPickedTheme(newTheme) {
function updateDropdownLabel(systemTheme) {
window.document.getElementById('theme-option-auto').innerText = "Auto (" + systemTheme + ")";
}

/**
* Checks whether color-scheme is a supported feature of the browser.
* If it is not, removes the auto option from the dropdown.
*/
function checkThemingSupport() {
var darkQuery = window.matchMedia('(prefers-color-scheme: dark)');
var lightQuery = window.matchMedia('(prefers-color-scheme: light)');
// If neither query matches, we know that the browser doesn't support theming
// If neither query matches, we know that the browser doesn't support theming.
if (!darkQuery.matches && !lightQuery.matches) {
var themeOptionAuto = window.document.getElementById('theme-option-auto');
// IE doesn't support element.remove()
themeOptionAuto.parentNode.removeChild(themeOptionAuto);
}
// If the browser does not support css properties, we do not allow theme switching.
var customProperty = getComputedStyle(document.body).getPropertyValue("--body");
if (!customProperty) {
document.querySelector(".theme-select-container").style.display = 'none';
}
}
2 changes: 1 addition & 1 deletion Sources/swift-doc/Resources/all.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Sources/swift-doc/Subcommands/Generate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func fetchRemoteJS() throws -> Data {
// When using Swift Package Manager versions that don't support bundled resources, just hide the theme select drop-down.
let fallbackJS = """
var hideThemeSelect = function() {
document.querySelector(".theme-select-container").hidden = true;
document.querySelector(".theme-select-container").style.display = "none";
}
// hiding the element in `requestAnimationFrame` causes the function to be called after the element exists,
// but fast enough that the element does not flash on the screen.
Expand Down

0 comments on commit d8fb3f6

Please sign in to comment.