Skip to content

Detect theme changes on all docs.rs pages #1123

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
merged 1 commit into from
Oct 26, 2020

Conversation

Nemo157
Copy link
Member

@Nemo157 Nemo157 commented Oct 26, 2020

This allows us to change non-rustdoc pages if another open tab is looking at a rustdoc page and changes the theme.

This allows us to change non-rustdoc pages if another open tab is
looking at a rustdoc page and changes the theme
Comment on lines +5 to +16
window.addEventListener('storage', function (ev) {
if (ev.key === 'rustdoc-theme') {
applyTheme(ev.newValue);
}
});

// see ../static/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);
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both of these listeners? Could we only listen to storage and get rid of the iframe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we miss out on knowing when this current window changes the theme, we would only update when another window changes it.

@jyn514 jyn514 merged commit 00ba0b2 into rust-lang:master Oct 26, 2020
@Nemo157 Nemo157 deleted the detect-on-all-pages branch October 26, 2020 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants