Skip to content

Commit ebc035c

Browse files
authored
Merge pull request #79 from phukon/master
feat: add hotkey access for searchbar
2 parents 4940866 + 710c503 commit ebc035c

File tree

4 files changed

+75
-22
lines changed

4 files changed

+75
-22
lines changed

layouts/_default/baseof.html

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
<head>
44
{{ partial "head.html" . }}
55
</head>
6-
<body class="td-{{ .Kind }}{{ with .Page.Params.body_class }} {{ . }}{{ end }}">
7-
<header>
8-
{{ partial "navbar.html" . }}
9-
</header>
6+
<body
7+
class="td-{{ .Kind }}{{ with .Page.Params.body_class }} {{ . }}{{ end }}"
8+
>
9+
<header>{{ partial "navbar.html" . }}</header>
1010
<div class="container-fluid td-default td-outer">
11-
<main role="main" class="td-main">
12-
{{ block "main" . }}{{ end }}
13-
</main>
11+
<main role="main" class="td-main">{{ block "main" . }}{{ end }}</main>
1412
{{ partial "footer.html" . }}
1513
</div>
16-
{{ partialCached "scripts.html" . }}
17-
{{ partial "image-modal.html" . }}
14+
{{ partialCached "scripts.html" . }} {{ partial "image-modal.html" . }}
1815
</body>
19-
</html>
16+
</html>

layouts/docs/baseof.html

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<!doctype html>
22
<html itemscope itemtype="http://schema.org/WebPage" lang="{{ .Site.Language.Lang }}" class="no-js">
33
<head>
4-
{{ partial "head.html" . }}
5-
{{ partial "favicon.html" . }}
4+
{{ partial "head.html" . }} {{ partial "favicon.html" . }}
65
</head>
7-
<body class="td-{{ .Kind }}{{ with .Page.Params.body_class }} {{ . }}{{ end }}">
6+
<body
7+
class="td-{{ .Kind }}{{ with .Page.Params.body_class }} {{ . }}{{ end }}"
8+
>
89
<header>
910
{{ partial "navbar.html" . }}
1011
</header>
@@ -15,20 +16,18 @@
1516
{{ partial "sidebar.html" . }}
1617
</aside>
1718
<aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none">
18-
{{ partial "page-meta-links.html" . }}
19-
{{ partial "toc.html" . }}
20-
{{ partial "taxonomy_terms_clouds.html" . }}
19+
{{ partial "page-meta-links.html" . }} {{ partial "toc.html" . }} {{
20+
partial "taxonomy_terms_clouds.html" . }}
2121
</aside>
2222
<main class="col-12 col-md-9 col-xl-8 ps-md-5" role="main">
23-
{{ partial "version-banner.html" . }}
24-
{{ if not .Site.Params.ui.breadcrumb_disable }}{{ partial "breadcrumb.html" . }}{{ end }}
25-
{{ block "main" . }}{{ end }}
23+
{{ partial "version-banner.html" . }} {{ if not
24+
.Site.Params.ui.breadcrumb_disable }}{{ partial "breadcrumb.html" .
25+
}}{{ end }} {{ block "main" . }}{{ end }}
2626
</main>
2727
</div>
2828
</div>
2929
{{ partial "footer.html" . }}
3030
</div>
31-
{{ partial "scripts.html" . }}
32-
{{ partial "image-modal.html" . }}
31+
{{ partial "scripts.html" . }} {{ partial "image-modal.html" . }}
3332
</body>
34-
</html>
33+
</html>

layouts/partials/footer.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<footer class="footer">
2+
<!-- Hotkey func -->
3+
{{partial "hotkey.html" .}}
4+
<!----------------->
25
<div class="row footer-top">
36
<div class="col-lg-6">
47
<a href="/">

layouts/partials/hotkey.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<style>
2+
#iconParent {
3+
width: 100%;
4+
display: flex;
5+
justify-content: flex-end;
6+
}
7+
8+
#promptChild {
9+
position: relative;
10+
right: -70px;
11+
top: -1.5px;
12+
font-size: 16px;
13+
font-weight: bold;
14+
color: black;
15+
background-color: #cccccc;
16+
border-radius: 6px;
17+
padding: 0px 8px;
18+
}
19+
</style>
20+
<script>
21+
function focusSearchBar() {
22+
var searchBar = document.querySelector(".td-search-input");
23+
if (searchBar) {
24+
searchBar.focus();
25+
}
26+
}
27+
28+
document.addEventListener("keydown", function (event) {
29+
if (event.key === "/") {
30+
event.preventDefault();
31+
focusSearchBar();
32+
}
33+
});
34+
35+
document.addEventListener("DOMContentLoaded", function () {
36+
var parent = document.createElement("div");
37+
parent.id = "iconParent";
38+
39+
var prompt = document.createElement("span");
40+
prompt.textContent = "/";
41+
prompt.id = "promptChild";
42+
parent.appendChild(prompt);
43+
44+
var searchElement = document.querySelector(".td-search__icon");
45+
if (searchElement) {
46+
searchElement.appendChild(parent);
47+
}
48+
49+
var inputElement = document.querySelector(".td-search-input");
50+
if (inputElement) {
51+
inputElement.placeholder = "Search";
52+
}
53+
});
54+
</script>

0 commit comments

Comments
 (0)