Skip to content
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

Activate tabs based on browser's operating system #1216

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Nov 9, 2023

For #1196.

After #1205 and #1206, we now have Unix/macOS/Windows tabs for https://devguide.python.org/ and https://devguide.python.org/testing/run-write-tests/.

This PR adds some JavaScript to check the browser's operating system, and then activates the relevant tab:

I've tested:

  • macOS with Chrome, Safari, Firefox, Opera -> macOS tab
  • Android with Chrome and Samsung Internet -> Unix tab (default)

Would be good if some other people could test:

  • Linux/Firefox -> Unix tab
  • Windows/Edge/Opera -> Windows tab
  • iPhone/iPad -> Unix tab (default)
  • Anything else? -> Unix tab (default)

📚 Documentation preview 📚: https://cpython-devguide--1216.org.readthedocs.build/

activateTab(getOS());
});
</script>

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it's better to include this in every page that uses tabs or just once at the top level:

  • if we do it for each page, we need to duplicate the function call for each page, and remember to add this whenever OS-specific tabs are added to a page.
  • if we do it at the top level, it will be executed for each page, even when not needed

Another option would be contributing this upstream, and add a flag to enable/disable it. It should also possible to include this snippet of HTML in an rst |substitution| to avoid code duplication, even if it might be overkill.

FWIW I tested on Linux/Firefox and I get "Unix" tabs (my window.navigator.platform is "Linux x86_64").

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wasn't sure about including for all or just the required pages. It probably doesn't matter much either way, it's only a small bit of JS.

I thought about contributing upstream, but tabs can be about anything, not only operating systems. Although as you mention, a flag would help. Another complication is the OS->tab mappings. For example, we have "Unix" shown for Linux.

Thanks for testing Linux!

@hugovk
Copy link
Member Author

hugovk commented Nov 10, 2023

@hugovk hugovk merged commit 01cb216 into python:main Nov 14, 2023
5 checks passed
@hugovk hugovk deleted the activate-os-tab branch November 14, 2023 15:19
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