Skip to content

Commit 21917ce

Browse files
author
Joseph Lowinske
committed
refactor search input rendering functionality into separate script; fix broken clear-search functionality
1 parent e52e52f commit 21917ce

File tree

6 files changed

+40
-42
lines changed

6 files changed

+40
-42
lines changed

_includes/sidebar.html

+3-36
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
easing: 'swing'
3939
}
4040
};
41-
41+
4242
{% if page.version.version == 'v2.1' %}
4343
if ($(window).width() >= 992) {
4444
$('#mysidebar .tier-1').addClass('active--expand');
@@ -102,7 +102,6 @@
102102
</form>
103103
</div>
104104
</li>
105-
106105
<script>
107106
(function () {
108107
var baseUrl = "{{ site.baseurl }}";
@@ -236,41 +235,9 @@
236235
location.href = $(this).val();
237236
});
238237
</script>
238+
239+
<script src="{{ 'js/searchInputRendering.js' | relative_url }}"></script>
239240
</div>
240241

241242
<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above.-->
242243
<script>$("#mysidebar").find("li.active").parents('li').toggleClass("active");</script>
243-
244-
{% if page.url == '/search.html' %}
245-
<script>
246-
$(document).ready(function() {
247-
// this will make search appear instead of header in collapsed docs menu
248-
$('.collapsed-header').hide();
249-
$('.search-wrap').show();
250-
251-
// this will remove the class with custom styling for search page,
252-
// so when we close the menu it reverts to normal styling
253-
// needs to happen if any of these elements are clicked
254-
$('.sidenav-arrow, #search-input, .clear-search').on('click', function() {
255-
if ($('#mysidebar').hasClass('nav--search')) {
256-
$('#mysidebar').removeClass('nav--search').addClass('nav--home');
257-
}
258-
});
259-
260-
// set search input value to query string
261-
$('#search-input').val(QueryString.q.replace('+', ' '));
262-
263-
// on load, show close button if search input
264-
if ($('#search-input').val() != '') $('.clear-search').show();
265-
266-
$('.clear-search').on('click', function() {
267-
$('#search-input').val('');
268-
$(this).hide();
269-
});
270-
271-
$('#search-input').on('input', function() {
272-
if ($(this).val() != '') $('.clear-search').show();
273-
});
274-
});
275-
</script>
276-
{% endif %}

css/components/_search.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@
7272
height: 38px;
7373
width: 35px;
7474
border-radius: 50%;
75-
cursor: pointer;
7675
outline: none;
76+
cursor: pointer;
7777

7878
@include at-query($min, $screen-md) { right: 0; }
7979

8080
&:before, &:after {
8181
content: '';
8282
position: absolute;
83-
height: 2px;
83+
height: 1px;
8484
width: 11px;
8585
top: 50%;
8686
left: 6px;

css/customstyles.css

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/customstyles.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/searchInputRendering.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$(document).ready(function() {
2+
// this will make search appear instead of header in collapsed docs menu
3+
$('.collapsed-header').hide();
4+
$('.search-wrap').show();
5+
6+
// this will remove the class with custom styling for search page,
7+
// so when we close the menu it reverts to normal styling
8+
// needs to happen if any of these elements are clicked
9+
$('.sidenav-arrow, #search-input, .clear-search').on('click', function() {
10+
if ($('#mysidebar').hasClass('nav--search')) {
11+
$('#mysidebar').removeClass('nav--search').addClass('nav--home');
12+
}
13+
});
14+
15+
// on load, show close button if search input
16+
if ($('#search-input').val() != '') $('.clear-search').show();
17+
18+
$('.clear-search').on('click', function() {
19+
$('#search-input').val('');
20+
$(this).hide();
21+
});
22+
23+
$('#search-input').on('input', function() {
24+
if ($(this).val() != '') {
25+
$('.clear-search').show();
26+
} else {
27+
$('.clear-search').hide();
28+
}
29+
});
30+
});

search.html

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}();
3232

3333
document.title = 'Search - ' + QueryString.q;
34+
$('#search-input').val(QueryString.q.replace('+', ' '));
3435

3536
var client = algoliasearch('BH4D9OD16A', '5a93998460e4910a8769500d325250cb');
3637
var index = client.initIndex('cockroachlabs');

0 commit comments

Comments
 (0)