doc: allow pressing / to focus search bar (#10522)
* type / to focus search; rename unused variables * use ev.preventDefault() instead of setTimeout() * delete doc.js_pull/10525/head
parent
21fe91e508
commit
984551227b
|
@ -20,7 +20,7 @@ function setupScrollSpy() {
|
||||||
sectionPositions.push(section.offsetTop);
|
sectionPositions.push(section.offsetTop);
|
||||||
});
|
});
|
||||||
var scrollPos = 0;
|
var scrollPos = 0;
|
||||||
window.addEventListener('scroll', function (e) {
|
window.addEventListener('scroll', function (_) {
|
||||||
// Reset classes
|
// Reset classes
|
||||||
document.querySelectorAll('.doc-toc a[class="active"]').forEach(function (link) {
|
document.querySelectorAll('.doc-toc a[class="active"]').forEach(function (link) {
|
||||||
link.classList.remove('active');
|
link.classList.remove('active');
|
||||||
|
@ -52,7 +52,7 @@ function setupScrollSpy() {
|
||||||
|
|
||||||
function setupMobileToggle() {
|
function setupMobileToggle() {
|
||||||
var toggle = document.getElementById('toggle-menu');
|
var toggle = document.getElementById('toggle-menu');
|
||||||
toggle.addEventListener('click', function (ev) {
|
toggle.addEventListener('click', function (_) {
|
||||||
var docNav = document.querySelector('.doc-nav');
|
var docNav = document.querySelector('.doc-nav');
|
||||||
var isHidden = docNav.classList.contains('hidden');
|
var isHidden = docNav.classList.contains('hidden');
|
||||||
docNav.classList.toggle('hidden');
|
docNav.classList.toggle('hidden');
|
||||||
|
@ -225,3 +225,11 @@ function debounce(func, timeout) {
|
||||||
timer = setTimeout(next, timeout > 0 ? timeout : 300);
|
timer = setTimeout(next, timeout > 0 ? timeout : 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keypress', (ev) => {
|
||||||
|
if (ev.key == '/') {
|
||||||
|
let search = document.getElementById('search');
|
||||||
|
ev.preventDefault();
|
||||||
|
search.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue