Skip to content

Commit 89ce72f

Browse files
committed
search hotkey
1 parent 085f9ab commit 89ce72f

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

layouts/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ <h3 class="color-blue search-result-title">${item._highlightResult.title.value}<
304304
$(".search-overlay").addClass("d-none");
305305
$(".search-overlay").removeClass("d-block");
306306
});
307+
308+
$("a[title='Search']").on("click", function (e) {
309+
setTimeout(() => $("input.ais-SearchBox-input").focus(), 50);
310+
});
311+
312+
if(window.location.hash == "#search") {
313+
setTimeout(() => $("input.ais-SearchBox-input").focus(), 50);
314+
}
307315
});
308316
</script>
309317
<!-- /Search -->

layouts/partials/header.html

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<div class="navbar-div">
99
<a class="navbar-brand" href="{{ site.Home.RelPermalink }}">
1010
{{ with site.Params.logo}}
11-
<img width="{{site.Params.logo_width}}" class="img-fluid" src="{{ . | relURL }}" alt="{{ site.Title }}" style="min-width: {{site.Params.logo_width}};">
11+
<img width="{{site.Params.logo_width}}" class="img-fluid" src="{{ . | relURL }}" alt="{{ site.Title }}"
12+
style="min-width: {{site.Params.logo_width}};">
1213
{{ else }}{{site.Title}}{{end}}
1314
</a>
1415
</div>
@@ -29,23 +30,25 @@
2930
<a class="nav-link dropdown-toggle d-none d-xl-block" href="{{ .URL | relURL }}" role="button">
3031
{{ .Name }}
3132
</a>
32-
<a class="nav-link dropdown-toggle d-block d-xl-none" href="{{ .URL | relURL }}" role="button" data-toggle="dropdown" >
33+
<a class="nav-link dropdown-toggle d-block d-xl-none" href="{{ .URL | relURL }}" role="button"
34+
data-toggle="dropdown">
3335
{{ .Name }}
3436
</a>
3537
<div class="dropdown-menu shadow-lg" style="padding: 1rem 0.25rem;">
3638
{{ range .Children }}
3739
{{if .Params.subtitle}}
3840
<p class="mb-0 mt-1 ml-3" style="color:#005aa7; font-weight:550; font-size:13px;">{{.Params.subtitle}}</p>
3941
{{end}}
40-
<a class="dropdown-item mr-4" href="{{ .URL | relURL }}" target="{{ .Params.target }}" title="{{ .Name }}" style="padding: 0.75rem 1.5rem;color: #005aa7;">
42+
<a class="dropdown-item mr-4" href="{{ .URL | relURL }}" target="{{ .Params.target }}" title="{{ .Name }}"
43+
style="padding: 0.75rem 1.5rem;color: #005aa7;">
4144
{{if .Params.icon}}
4245
<i class="fas {{.Params.icon}} col-2 pl-0"></i>
4346
{{end}}
4447
{{ if .Params.Featured }}
4548
<div class="mb-1 text-center rounded" style="padding: 0.5rem 0.5rem; background-color: #dfeaf4;">
46-
{{ end }}
49+
{{ end }}
4750
{{.Pre}}{{ .Name }}{{.Post}}
48-
{{ if .Params.Featured }}
51+
{{ if .Params.Featured }}
4952
</div>
5053
{{ end }}
5154
</a>
@@ -61,7 +64,11 @@
6164

6265
<!-- Search -->
6366
<li class="nav-item">
64-
<a class="nav-link" href='{{ if eq .Site.Language.Lang "en" }}{{else}}/nl{{end}}/#search' title="Search"><i class="fas fa-search"></i></a>
67+
<a style="max-width: 200px;" class="nav-link rounded-lg bg-lightblue py-1 my-1 mx-auto"
68+
href='{{ if eq .Site.Language.Lang "en" }}{{else}}/nl{{end}}/#search' title="Search"><i
69+
class="fas fa-search d-inline" id="search-hotkeys"></i>
70+
<p class="d-inline ml-2" id="search-hotkeys-text"></p>
71+
</a>
6572
</li>
6673
<!-- /Search -->
6774

@@ -76,7 +83,8 @@
7683
</div>
7784
<!-- Rounded switch -->
7885
<label class="switch d-inline-block mx-1">
79-
<input type="checkbox" disabled aria-checked={{if eq .Site.Language.Lang "en" }} "true" checked {{else}} "false" {{ end }} id="lang-toggle" role="switch">
86+
<input type="checkbox" disabled aria-checked={{if eq .Site.Language.Lang "en" }} "true" checked
87+
{{else}} "false" {{ end }} id="lang-toggle" role="switch">
8088
<span class="slider round"></span>
8189
</label>
8290
<div class="d-inline" {{ if eq .Site.Language.Lang "nl" }} style="font-weight: 350;" {{ end}}>
@@ -98,5 +106,29 @@
98106
</div>
99107

100108
</header>
109+
<script>
110+
docReady(function () {
111+
console.log(navigator.platform);
112+
if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
113+
const isMac = navigator.platform.indexOf('Mac') >= 0;
114+
if (isMac) {
115+
$("#search-hotkeys-text").text("[⌘] + [\\]");
116+
}
117+
else {
118+
$("#search-hotkeys-text").text("[Ctrl] + [\\]");
119+
}
120+
$("a[title='Search']").addClass("rounded-lg bg-lightblue");
121+
122+
$(window).keydown(function (k) {
101123

124+
console.log(k);
125+
if (k.which == 220 && (k.ctrlKey == true && !isMac || k.metaKey == true && isMac)) {
126+
$("a[title='Search']")[0].click();
127+
k.preventDefault();
128+
return false;
129+
}
130+
});
131+
}
132+
});
133+
</script>
102134
{{ "<!-- /navigation -->" | safeHTML }}

0 commit comments

Comments
 (0)