From d2845859c71ea1cdec2347fb33b1261dbd72e44e Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Tue, 9 Jun 2020 00:30:24 -0400 Subject: [PATCH] Open search when shortcut key is pressed --- resources/skins.citizen.scripts/search.js | 25 +++++++++++++++++++ .../skins.citizen.scripts/searchfocus.js | 19 -------------- .../skins.citizen.styles.search/search.less | 1 + skin.json | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 resources/skins.citizen.scripts/search.js delete mode 100644 resources/skins.citizen.scripts/searchfocus.js diff --git a/resources/skins.citizen.scripts/search.js b/resources/skins.citizen.scripts/search.js new file mode 100644 index 00000000..2ef8e82a --- /dev/null +++ b/resources/skins.citizen.scripts/search.js @@ -0,0 +1,25 @@ +/* + * Citizen - Search JS + * https://starcitizen.tools + * + * Focus on search input when checkbox is toggled + * Open the search box when the input is in focus + */ + +var searchToggle = document.getElementById( 'search-toggle' ), + searchInput = document.getElementById( 'searchInput' ); + +function searchInputFocus() { + if ( searchToggle.checked !== false ) { + searchInput.focus(); + } +} + +function searchToggleCheck() { + if ( searchToggle.checked === false ) { + searchToggle.checked = true; + } +} + +searchToggle.addEventListener( 'click', searchInputFocus ); +searchInput.addEventListener( 'focus', searchToggleCheck ); diff --git a/resources/skins.citizen.scripts/searchfocus.js b/resources/skins.citizen.scripts/searchfocus.js deleted file mode 100644 index 931f31b1..00000000 --- a/resources/skins.citizen.scripts/searchfocus.js +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Citizen - Search focus JS - * https://starcitizen.tools - * - * Focus on search input when checkbox is toggled - * TODO: Clean up all the JS files after the skin is converted to Mustache - */ - -var searchToggle = document.getElementById( 'search-toggle' ); - -function searchInputFocus() { - var searchInput = document.getElementById( 'searchInput' ); - - if ( searchToggle.checked !== false ) { - searchInput.focus(); - } -} - -searchToggle.addEventListener( 'click', searchInputFocus ); diff --git a/resources/skins.citizen.styles.search/search.less b/resources/skins.citizen.styles.search/search.less index 10cdcfe3..c3978e8d 100644 --- a/resources/skins.citizen.styles.search/search.less +++ b/resources/skins.citizen.styles.search/search.less @@ -13,6 +13,7 @@ } .suggestions-dropdown { + padding-top: 4px; width: @search-bar-width; max-width: calc( ~'100vw -'@icon-box-size + @icon-padding * 2 + @margin-side ); display: flex; // Needed to show margin diff --git a/skin.json b/skin.json index 87b1f836..c37e8a2a 100644 --- a/skin.json +++ b/skin.json @@ -200,7 +200,7 @@ "skins.citizen.scripts": { "scripts": [ "resources/skins.citizen.scripts/toc.js", - "resources/skins.citizen.scripts/searchfocus.js" + "resources/skins.citizen.scripts/search.js" ] }, "skins.citizen.scripts.search": {