forked from plone/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_shortcut.js
More file actions
35 lines (30 loc) · 1011 Bytes
/
search_shortcut.js
File metadata and controls
35 lines (30 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Add shortcut `ctrl+k` to focus on search field
*/
$(document).ready(() => {
if (window.location.pathname === '/search.html') {
$('form.bd-search .input-group').hide(); // Hide Sidebar Search field
$(document).keydown(function(event) {
if ((event.ctrlKey || event.metaKey) && event.key == "k") {
event.preventDefault();
$('#q').focus();
}
});
} else {
$(document).keydown(function(event) {
if ((event.ctrlKey || event.metaKey) && event.key == "k") {
event.preventDefault();
$('#search-input').focus();
}
});
}
// if OS isn't Mac change visual indication of search field
if (navigator.platform.indexOf('Mac') === -1) {
$('#search-shortcut').html("^");
$('#search-page-shortcut').html("^");
}
});
function onReset() {
$('#search-form').trigger('reset');
$('#search-form').trigger('submit');
}