-
Notifications
You must be signed in to change notification settings - Fork 210
Namespace docs.rs theme setting #2464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
GuillaumeGomez
merged 6 commits into
rust-lang:master
from
Nemo157:namespace-docs.rs-theme
Mar 19, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f8d1f02
Fix indentation
Nemo157 493b622
Don't pollute the global function namespace with theme functions
Nemo157 3f74bca
Only set theme if configured
Nemo157 276ecce
Use namespaced data variable to store docs.rs' theme
Nemo157 cf814b1
Don't lazy-load storage-change-detection
Nemo157 3c90b37
Add gui-test for theme changing
Nemo157 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// setting local-storage emulates how we detect rustdoc changing the theme, we | ||
// only run this detection on rustdoc pages so must change there before visiting | ||
// other pages | ||
|
||
// on rustdoc pages we only control the .nav-container and its descendants, on | ||
// the crate page we control the whole page | ||
|
||
go-to: |DOC_PATH| + "/sysinfo" | ||
set-local-storage: { "rustdoc-theme": null } | ||
wait-for-css: (".nav-container", { "background-color": "rgb(255, 255, 255)" }) | ||
go-to: |DOC_PATH| + "/crate/sysinfo" | ||
wait-for-css: ("body", { "background-color": "rgb(255, 255, 255)" }) | ||
|
||
go-to: |DOC_PATH| + "/sysinfo" | ||
set-local-storage: { "rustdoc-theme": "ayu" } | ||
wait-for-css: (".nav-container", { "background-color": "rgb(15, 20, 25)" }) | ||
go-to: |DOC_PATH| + "/crate/sysinfo" | ||
wait-for-css: ("body", { "background-color": "rgb(15, 20, 25)" }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<script async src="/-/static/menu.js?{{ docsrs_version() | slugify }}"></script> | ||
<script async src="/-/static/index.js?{{ docsrs_version() | slugify }}"></script> | ||
{# see comment in ../storage-change-detection.html for details #} | ||
<iframe loading="lazy" src="/-/storage-change-detection.html" width="0" height="0" style="display: none"></iframe> | ||
<iframe src="/-/storage-change-detection.html" width="0" height="0" style="display: none"></iframe> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
function applyTheme(theme) { | ||
document.documentElement.dataset.theme = theme; | ||
} | ||
(function() { | ||
function applyTheme(theme) { | ||
if (theme) { | ||
document.documentElement.dataset.docsRsTheme = theme; | ||
} | ||
} | ||
|
||
window.addEventListener('storage', function (ev) { | ||
if (ev.key === 'rustdoc-theme') { | ||
applyTheme(ev.newValue); | ||
} | ||
}); | ||
window.addEventListener('storage', function (ev) { | ||
if (ev.key === 'rustdoc-theme') { | ||
applyTheme(ev.newValue); | ||
} | ||
}); | ||
|
||
// see ./storage-change-detection.html for details | ||
window.addEventListener('message', function (ev) { | ||
if (ev.data && ev.data.storage && ev.data.storage.key === 'rustdoc-theme') { | ||
applyTheme(ev.data.storage.value); | ||
} | ||
}); | ||
// see ./storage-change-detection.html for details | ||
window.addEventListener('message', function (ev) { | ||
if (ev.data && ev.data.storage && ev.data.storage.key === 'rustdoc-theme') { | ||
applyTheme(ev.data.storage.value); | ||
} | ||
}); | ||
|
||
applyTheme(window.localStorage.getItem('rustdoc-theme')); | ||
applyTheme(window.localStorage.getItem('rustdoc-theme')); | ||
})() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.