Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Focus search box when pressing slash#131

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
hugovk wants to merge2 commits intopython:mainfromhugovk:search-focus
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletionpython_docs_theme/layout.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ <h3>{{ _('Navigation') }}</h3>
{%- if builder != "htmlhelp" %}
<div class="inline-search" role="search">
<form class="inline-search" action="{{ pathto('search') }}" method="get">
<input placeholder="{{ _('Quick search') }}" aria-label="{{ _('Quick search') }}" type="search" name="q" />
<input placeholder="{{ _('Quick search') }}" aria-label="{{ _('Quick search') }}" type="search" name="q"id="search-box"/>
<input type="submit" value="{{ _('Go') }}" />
</form>
</div>
Expand DownExpand Up@@ -76,6 +76,7 @@ <h3>{{ _('Navigation') }}</h3>
{%- if not embedded %}
<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/menu.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/search-focus.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/themetoggle.js', 1) }}"></script>
{%- endif -%}
{%- endif -%}
Expand Down
21 changes: 21 additions & 0 deletionspython_docs_theme/static/search-focus.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
function isInputFocused() {
const activeElement = document.activeElement;
return (
activeElement.tagName === 'INPUT' ||
activeElement.tagName === 'TEXTAREA' ||
activeElement.isContentEditable
);
}

document.addEventListener('keydown', function(event) {
if (event.key === '/') {
if (!isInputFocused()) {
// Prevent "/" from being entered in the search box
event.preventDefault();

// Set the focus on the search box
const searchBox = document.getElementById('search-box');
searchBox.focus();
}
}
});

[8]ページ先頭

©2009-2025 Movatter.jp