From 12b476eb7c98981a0b3fd3f536c95d9a4d4cceb7 Mon Sep 17 00:00:00 2001 From: Andrew Leonard Date: Wed, 29 May 2024 01:18:27 -0400 Subject: [PATCH 1/6] Dynamically sets the search shortcut key based on platform This addresses issue #2437 --- _layouts/default.liquid | 1 + assets/js/shortcut-key.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 assets/js/shortcut-key.js diff --git a/_layouts/default.liquid b/_layouts/default.liquid index 3f4af10e524a..e7e6b8411ffd 100644 --- a/_layouts/default.liquid +++ b/_layouts/default.liquid @@ -13,6 +13,7 @@ {% endif %} {% include head.liquid %} + diff --git a/assets/js/shortcut-key.js b/assets/js/shortcut-key.js new file mode 100644 index 000000000000..5028272e2984 --- /dev/null +++ b/assets/js/shortcut-key.js @@ -0,0 +1,12 @@ +// Check if the user is on a Mac and update the shortcut key for search accordingly + +var isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; +document.addEventListener('readystatechange', function () { + if (document.readyState === 'interactive') { + var shortcutKeyElement = document.querySelector('#search-toggle .nav-link'); + if (shortcutKeyElement && isMac) { + // use the unicode for command key + shortcutKeyElement.innerHTML = "⌘ k "; + } + } +}); From 07b633ab2aded8a9aed3f7884eb5f6a540741995 Mon Sep 17 00:00:00 2001 From: Andrew Leonard Date: Wed, 29 May 2024 17:23:34 -0400 Subject: [PATCH 2/6] moves search shortcut logic into an automatically called function --- assets/js/shortcut-key.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/assets/js/shortcut-key.js b/assets/js/shortcut-key.js index 5028272e2984..6d7e3e9e461a 100644 --- a/assets/js/shortcut-key.js +++ b/assets/js/shortcut-key.js @@ -1,12 +1,13 @@ // Check if the user is on a Mac and update the shortcut key for search accordingly - -var isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; -document.addEventListener('readystatechange', function () { - if (document.readyState === 'interactive') { - var shortcutKeyElement = document.querySelector('#search-toggle .nav-link'); - if (shortcutKeyElement && isMac) { - // use the unicode for command key - shortcutKeyElement.innerHTML = "⌘ k "; +(function () { + var isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; + document.addEventListener('readystatechange', function () { + if (document.readyState === 'interactive') { + let shortcutKeyElement = document.querySelector('#search-toggle .nav-link'); + if (shortcutKeyElement && isMac) { + // use the unicode for command key + shortcutKeyElement.innerHTML = "⌘ k "; + } } - } -}); + }); +})(); \ No newline at end of file From c62fe89cea8f6806977e30642c6f7b8c49c8079c Mon Sep 17 00:00:00 2001 From: Andrew Leonard Date: Wed, 29 May 2024 18:18:14 -0400 Subject: [PATCH 3/6] uses let instead of var --- assets/js/shortcut-key.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/shortcut-key.js b/assets/js/shortcut-key.js index 6d7e3e9e461a..d1a085b9cfbd 100644 --- a/assets/js/shortcut-key.js +++ b/assets/js/shortcut-key.js @@ -1,6 +1,6 @@ // Check if the user is on a Mac and update the shortcut key for search accordingly (function () { - var isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; + let isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; document.addEventListener('readystatechange', function () { if (document.readyState === 'interactive') { let shortcutKeyElement = document.querySelector('#search-toggle .nav-link'); From e66525d06cee78f5ee07534d9fa85352614a77c6 Mon Sep 17 00:00:00 2001 From: Andrew Leonard Date: Fri, 31 May 2024 12:25:02 -0400 Subject: [PATCH 4/6] fixes prettier errors --- assets/js/shortcut-key.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/js/shortcut-key.js b/assets/js/shortcut-key.js index d1a085b9cfbd..1e72a392d521 100644 --- a/assets/js/shortcut-key.js +++ b/assets/js/shortcut-key.js @@ -1,13 +1,13 @@ // Check if the user is on a Mac and update the shortcut key for search accordingly (function () { - let isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; - document.addEventListener('readystatechange', function () { - if (document.readyState === 'interactive') { - let shortcutKeyElement = document.querySelector('#search-toggle .nav-link'); + let isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0; + document.addEventListener("readystatechange", function () { + if (document.readyState === "interactive") { + let shortcutKeyElement = document.querySelector("#search-toggle .nav-link"); if (shortcutKeyElement && isMac) { - // use the unicode for command key - shortcutKeyElement.innerHTML = "⌘ k "; + // use the unicode for command key + shortcutKeyElement.innerHTML = "⌘ k "; } } }); -})(); \ No newline at end of file +})(); From 1426455892edc7f338da9ad2bc28b4074607849b Mon Sep 17 00:00:00 2001 From: Andrew Leonard Date: Fri, 31 May 2024 12:33:48 -0400 Subject: [PATCH 5/6] Moves shortcut key js script to bottom of body --- _layouts/default.liquid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_layouts/default.liquid b/_layouts/default.liquid index e7e6b8411ffd..e519ec2d93ef 100644 --- a/_layouts/default.liquid +++ b/_layouts/default.liquid @@ -13,7 +13,6 @@ {% endif %} {% include head.liquid %} - @@ -74,5 +73,6 @@ {% include scripts/jekyll_tabs.liquid %} {% include scripts/back_to_top.liquid %} {% include scripts/search.liquid %} + From d5bd15d8de8992d4e881f37b848d20e57a23c03d Mon Sep 17 00:00:00 2001 From: Andrew Leonard Date: Fri, 31 May 2024 12:49:25 -0400 Subject: [PATCH 6/6] Updates shortcut key script --- assets/js/shortcut-key.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/assets/js/shortcut-key.js b/assets/js/shortcut-key.js index 1e72a392d521..f8de525aac8e 100644 --- a/assets/js/shortcut-key.js +++ b/assets/js/shortcut-key.js @@ -1,13 +1,11 @@ // Check if the user is on a Mac and update the shortcut key for search accordingly -(function () { - let isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0; - document.addEventListener("readystatechange", function () { - if (document.readyState === "interactive") { - let shortcutKeyElement = document.querySelector("#search-toggle .nav-link"); - if (shortcutKeyElement && isMac) { - // use the unicode for command key - shortcutKeyElement.innerHTML = "⌘ k "; - } +document.onreadystatechange = () => { + if (document.readyState === "interactive") { + let isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0; + let shortcutKeyElement = document.querySelector("#search-toggle .nav-link"); + if (shortcutKeyElement && isMac) { + // use the unicode for command key + shortcutKeyElement.innerHTML = '⌘ k '; } - }); -})(); + } +};