Skip to content

Commit

Permalink
better way to do this JS suggested by reviewer; we might be able to e…
Browse files Browse the repository at this point in the history
…liminate the JS entirely, but in the meantime let's commit this improvement
  • Loading branch information
cellio committed Oct 11, 2024
1 parent 3416db5 commit ebcb474
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
<% sticky_header = user_preference('sticky_header', community: false) == 'true' %>

<script>
$(document).ready(function () {
$('a[data-header-slide="#search-slide"]').on('click', focusSearch);
});
const toggleSearchFocus = () => {
const $input = $('#search');

var search = false;
function focusSearch() {
search = !search;
if (search) {
$('#search').focus();
}
if ($input.is(':focus')) {
$input.blur();
} else {
$input.focus();
}
};

$(() => {
$('a[data-header-slide="#search-slide"]').on('click', toggleSearchFocus);
});
</script>

<header class="header is-small has-margin-0<%=' is-dark' if SiteSetting['SiteHeaderIsDark'] %><%= ' sticky' if sticky_header %>">
Expand Down

0 comments on commit ebcb474

Please sign in to comment.