Skip to content

Commit afc56cc

Browse files
authored
Feature: Dynamically sets the search shortcut key based on the user's platform (#2461)
This addresses issue #2437 by: - Adding a new script that dynamically sets the search keyboard shortcut by checking what platform the user is currently using - Loading this script in `default.liquid` <img width="1150" alt="SCR-20240529-cdfe" src="https://github.com/alshedivat/al-folio/assets/16251412/7c4125fc-5028-422f-97d5-0df729e30fa7">
1 parent b35450e commit afc56cc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

_layouts/default.liquid

+1
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,6 @@
7373
{% include scripts/jekyll_tabs.liquid %}
7474
{% include scripts/back_to_top.liquid %}
7575
{% include scripts/search.liquid %}
76+
<script src="{{ '/assets/js/shortcut-key.js' | relative_url }}"></script>
7677
</body>
7778
</html>

assets/js/shortcut-key.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Check if the user is on a Mac and update the shortcut key for search accordingly
2+
document.onreadystatechange = () => {
3+
if (document.readyState === "interactive") {
4+
let isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
5+
let shortcutKeyElement = document.querySelector("#search-toggle .nav-link");
6+
if (shortcutKeyElement && isMac) {
7+
// use the unicode for command key
8+
shortcutKeyElement.innerHTML = '&#x2318; k <i class="ti ti-search"></i>';
9+
}
10+
}
11+
};

0 commit comments

Comments
 (0)