mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 11:26:27 +03:00
Activate tabs based on browser's operating system
This commit is contained in:
parent
f9c7bd8611
commit
959b45c945
|
@ -166,6 +166,10 @@ html_static_path = ["resources"]
|
||||||
# directly to the root of the documentation.
|
# directly to the root of the documentation.
|
||||||
# html_extra_path = []
|
# html_extra_path = []
|
||||||
|
|
||||||
|
html_js_files = [
|
||||||
|
"js/activate_tab.js",
|
||||||
|
]
|
||||||
|
|
||||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||||
# using the given strftime format.
|
# using the given strftime format.
|
||||||
# html_last_updated_fmt = '%b %d, %Y'
|
# html_last_updated_fmt = '%b %d, %Y'
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
Installation
|
Installation
|
||||||
============
|
============
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
activateTab(getOS());
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
Warnings
|
Warnings
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|
42
docs/resources/js/activate_tab.js
Normal file
42
docs/resources/js/activate_tab.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
// Based on https://stackoverflow.com/a/38241481/724176
|
||||||
|
function getOS() {
|
||||||
|
const userAgent = window.navigator.userAgent,
|
||||||
|
platform =
|
||||||
|
window.navigator?.userAgentData?.platform || window.navigator.platform,
|
||||||
|
macosPlatforms = ["macOS", "Macintosh", "MacIntel", "MacPPC", "Mac68K"],
|
||||||
|
windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"],
|
||||||
|
iosPlatforms = ["iPhone", "iPad", "iPod"];
|
||||||
|
|
||||||
|
if (macosPlatforms.includes(platform)) {
|
||||||
|
return "macOS";
|
||||||
|
} else if (iosPlatforms.includes(platform)) {
|
||||||
|
return "iOS";
|
||||||
|
} else if (windowsPlatforms.includes(platform)) {
|
||||||
|
return "Windows";
|
||||||
|
} else if (/Android/.test(userAgent)) {
|
||||||
|
return "Android";
|
||||||
|
} else if (/Linux/.test(platform)) {
|
||||||
|
return "Linux";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
function activateTab(tabName) {
|
||||||
|
// Find all label elements containing the specified tab name
|
||||||
|
const labels = document.querySelectorAll(".tab-label");
|
||||||
|
|
||||||
|
labels.forEach((label) => {
|
||||||
|
if (label.textContent.includes(tabName)) {
|
||||||
|
// Find the associated input element using the 'for' attribute
|
||||||
|
const tabInputId = label.getAttribute("for");
|
||||||
|
const tabInput = document.getElementById(tabInputId);
|
||||||
|
|
||||||
|
// Check if the input element exists before attempting to set the "checked" attribute
|
||||||
|
if (tabInput) {
|
||||||
|
// Activate the tab by setting its "checked" attribute to true
|
||||||
|
tabInput.checked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user