Skip to content

Commit e69fac5

Browse files
committed
Search: Replace dropdown with radio buttons. Add reset button.
1 parent 45a6666 commit e69fac5

File tree

3 files changed

+61
-34
lines changed

3 files changed

+61
-34
lines changed

docs/_static/custom.css

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ p.search-summary {
152152
list-style-type: none;
153153
padding-left: 0;
154154
}
155-
#search-results ul li {
156-
margin-bottom: 2rem;
157-
padding: 2px 0 5px 2rem;
158-
}
159155
#search-results ul li h3 {
160156
margin: 0.75rem 0 .5rem;
161157
font-size: 1.5rem;
@@ -176,6 +172,17 @@ p.search-summary {
176172

177173
text-overflow: ellipsis;
178174
}
175+
#search-results ul li,
176+
ul.search li {
177+
margin-bottom: 2rem;
178+
padding: 2px 0 5px 4rem;
179+
background-image: url(file.svg);
180+
background-blend-mode: hue;
181+
background-color: violetred;
182+
background-repeat: no-repeat;
183+
background-position: 0px 8px;
184+
background-size: 56px;
185+
}
179186
ul.search li p.context {
180187
margin-left: 0;
181188
}

docs/_static/searchtools.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,12 @@ var Search = {
7575

7676
init : function() {
7777
var params = $.getQueryParameters();
78+
let doc_section = params.doc_section ? params.doc_section[0] : 'all';
79+
$('input[id="doc_section_' + doc_section + '"]').prop("checked", true)
7880
if (params.q) {
7981
var query = params.q[0];
8082
$('input[name="q"]')[0].value = query;
8183
$('input[name="q"]')[1].value = query;
82-
if (params.doc_section) {
83-
var doc_section = params.doc_section[0];
84-
$('select[name="doc_section"]')[0].value = doc_section;
85-
}
8684
this.performSearch(query, doc_section);
8785
}
8886
},
@@ -234,7 +232,7 @@ var Search = {
234232

235233
// Enrich item with parent doc_section title
236234
for (i = 0; i < results.length; i++)
237-
results[i][6] = results[i][6] || 'TODO Documentation title';
235+
results[i][6] = results[i][6] || 'Plone Documentation';
238236

239237
// now sort the results by score (in opposite order of appearance, since the
240238
// display function below uses pop() to retrieve items) and then
@@ -255,24 +253,21 @@ var Search = {
255253
});
256254

257255
function _getBreadcrumbs(item, linkUrl) {
258-
let path = item[0];
259256
let parentTitles = item[6];
260-
let markup = path.split('/')
257+
let path = item[0].split('/')
261258
.slice(0, -1);
262-
markup = markup.map((el, index) => {
259+
path = path.map((el, index) => {
263260
return {
264-
"path": markup.slice(0, index+1).join('/'),
261+
"path": path.slice(0, index+1).join('/'),
265262
"title": parentTitles[index]
266263
}
267264
})
268-
markup = markup
269-
.map((el) => {
270-
let foo = `<a href="/${el.path}"> ${el.title}</a>`
271-
return foo;
265+
let markup = path
266+
.map((el, idx) => {
267+
return idx===0 ? `<a href="/${el.path}"><b>${el.title}</b></a>` : `<a href="/${el.path}">${el.title}</a>`
272268
})
273269
markup.push(`<span class="lastbreadcrumb">${item[1]}</span>`)
274-
markup = markup.join('<span class="pathseparator">&gt;</span>');
275-
return markup
270+
return markup.join('<span class="pathseparator">&gt;</span>');
276271
}
277272

278273
// Print the results.
@@ -587,7 +582,14 @@ var Search = {
587582

588583
$(document).ready(function() {
589584
Search.init();
590-
$('select[name="doc_section"]').change(function() {
585+
$('#q').focus();
586+
$('input[name="doc_section"]').change(function() {
591587
this.form.submit();
592588
});
589+
590+
function clearSearchField() {
591+
$('#q').val('');
592+
this.form.submit();
593+
}
594+
$( "button.clear_search" ).on( "click", clearSearchField );
593595
});

docs/_templates/search.html

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,52 @@ <h1 id="search-documentation">{{ _('Search') }}</h1>
4444
action=""
4545
method="get"
4646
id="search-form"
47-
class="form-inline"
47+
class=""
4848
>
49-
<div class="input-group mr-2 mb-1">
50-
<input
51-
type="text" name="q" id="q"
52-
class="form-control"
53-
placeholder="Search the docs…"
54-
aria-labelledby="search-documentation" value="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
55-
<label for="q" class="sr-only">Search string</label>
49+
<div class="row">
50+
<div class="input-group col-sm-6 mb-2">
51+
<input
52+
type="text" name="q" id="q"
53+
class="form-control"
54+
placeholder="Search the docs…"
55+
aria-labelledby="search-documentation" value="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
56+
<label for="q" class="sr-only">Search string</label>
5657
<div class="input-group-append">
5758
<button type="submit" class="btn btn-primary">{{ _('search') }}</button>
5859
</div>
60+
<div class="input-group-append">
61+
<button
62+
type="button"
63+
class="clear_search btn btn-primary"
64+
>{{ _('clear') }}</button>
65+
</div>
66+
</div>
5967
</div>
6068

61-
<div class="form-group mb-1">
62-
<label for="doc_section" class="sr-only">Filter by section</label>
63-
<select name="doc_section" id="doc_section" class="custom-select" >
64-
<option value="all">All Documentation</option>
69+
<div class="form-row mb-2">
70+
<label for="doc_section" class="col">Filter by section</label>
71+
<div class="col-sm-10">
72+
<div class="form-check">
73+
<input class="form-check-input" type="radio" name="doc_section" id="doc_section_all" value="all">
74+
<label class="form-check-label" for="doc_section_all">
75+
All Documentation
76+
</label>
77+
</div>
6578
{% for id, title in
6679
[
6780
["backend","Backend"],
6881
["classic-ui","Classic UI"],
6982
["volto","Frontend"],
7083
["contributing","Contributing"],
7184
] %}
72-
<option value="{{id}}">{{ title }}</option>
85+
<div class="form-check">
86+
<input class="form-check-input" type="radio" name="doc_section" id="doc_section_{{id}}" value="{{id}}">
87+
<label class="form-check-label" for="doc_section_{{id}}">
88+
{{title}}
89+
</label>
90+
</div>
7391
{% endfor %}
74-
</select>
92+
</div>
7593
</div>
7694

7795
<span id="search-progress" style="padding-left: 10px"></span>

0 commit comments

Comments
 (0)