Skip to content

Commit e7a2ff4

Browse files
committed
Update
1 parent 6c0f792 commit e7a2ff4

File tree

2 files changed

+75
-15
lines changed

2 files changed

+75
-15
lines changed

_static/css/custom2.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@
3535
.pytorch-left-menu li.toctree-l1.current > a:before {
3636
content: "";
3737
}
38+
39+
/* search radio button*/
40+
41+
input[type="radio"] {
42+
accent-color: #ee4c2c;
43+
}

_templates/layout.html

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{% extends "!layout.html" %}
22

3-
43
<!-- Overrides needed for the multilevel nav -->
54
{% block menu %}
65
{% if 'singlehtml' not in builder %}
@@ -30,23 +29,78 @@
3029
{%- endblock %}
3130

3231
{% block sidebartitle %}
33-
{% if theme_display_version %}
34-
{%- set nav_version = version %}
35-
{% if READTHEDOCS and current_version %}
36-
{%- set nav_version = current_version %}
37-
{% endif %}
38-
{% if nav_version %}
39-
<div class="version">
40-
{{ nav_version }}
41-
</div>
42-
{% endif %}
32+
33+
{% if theme_display_version %}
34+
{%- set nav_version = version %}
35+
{% if READTHEDOCS and current_version %}
36+
{%- set nav_version = current_version %}
4337
{% endif %}
44-
<div class="searchbox">
45-
<script async src="https://cse.google.com/cse.js?cx=e65585f8c3ea1440e"></script>
46-
<div class="gcse-search"></div>
38+
{% if nav_version %}
39+
<div class="version">
40+
{{ nav_version }}
41+
</div>
42+
{% endif %}
43+
{% endif %}
44+
45+
<!-- Search box -->
46+
<div id="searchBox">
47+
<div class="searchbox" id="googleSearchBox">
48+
<script async src="https://cse.google.com/cse.js?cx=e65585f8c3ea1440e"></script>
49+
<div class="gcse-search"></div>
4750
</div>
48-
{% endblock %}
51+
<div id="sphinxSearchBox" style="display: none;">
52+
<div role="search">
53+
<form id="rtd-search-form" class="wy-form" action="{{ pathto('search') }}" method="get">
54+
<input type="text" name="q" placeholder="Search {{ search_project }}" />
55+
<input type="hidden" name="check_keywords" value="yes" />
56+
<input type="hidden" name="area" value="default" />
57+
</form>
58+
</div>
59+
</div>
60+
</div>
61+
<!-- Radio buttons for search selection -->
62+
<form id="searchForm">
63+
<label>
64+
<input type="radio" name="searchType" value="google" checked>
65+
Google Search
66+
</label>
67+
<label>
68+
<input type="radio" name="searchType" value="sphinx">
69+
Sphinx Search
70+
</label>
71+
</form>
72+
73+
<script>
74+
document.addEventListener('DOMContentLoaded', function() {
75+
const searchForm = document.getElementById('searchForm');
76+
const googleSearchBox = document.getElementById('googleSearchBox');
77+
const sphinxSearchBox = document.getElementById('sphinxSearchBox');
78+
// Function to toggle search box visibility
79+
function toggleSearchBox(searchType) {
80+
googleSearchBox.style.display = searchType === 'google' ? 'block' : 'none';
81+
sphinxSearchBox.style.display = searchType === 'sphinx' ? 'block' : 'none';
82+
}
83+
// Determine the default search type
84+
let defaultSearchType = 'google';
85+
if (window.location.href.startsWith('https://docs-preview.pytorch.org/')) {
86+
defaultSearchType = 'sphinx';
87+
} else {
88+
defaultSearchType = localStorage.getItem('searchType') || 'google';
89+
}
90+
// Set the default search type
91+
document.querySelector(`input[name="searchType"][value="${defaultSearchType}"]`).checked = true;
92+
toggleSearchBox(defaultSearchType);
93+
// Event listener for changes in search type
94+
searchForm.addEventListener('change', function(event) {
95+
const selectedSearchType = event.target.value;
96+
localStorage.setItem('searchType', selectedSearchType);
97+
toggleSearchBox(selectedSearchType);
98+
});
99+
});
100+
</script>
101+
</script>
49102

103+
{% endblock %}
50104

51105
{% block footer %}
52106
{{ super() }}

0 commit comments

Comments
 (0)