1 |
efrain |
1 |
{{!
|
|
|
2 |
This file is part of Moodle - http://moodle.org/
|
|
|
3 |
|
|
|
4 |
Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
it under the terms of the GNU General Public License as published by
|
|
|
6 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
(at your option) any later version.
|
|
|
8 |
|
|
|
9 |
Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
GNU General Public License for more details.
|
|
|
13 |
|
|
|
14 |
You should have received a copy of the GNU General Public License
|
|
|
15 |
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
}}
|
|
|
17 |
{{!
|
|
|
18 |
@template core/search_input_navbar
|
|
|
19 |
|
|
|
20 |
Navbar search input template.
|
|
|
21 |
|
|
|
22 |
Example context (json):
|
|
|
23 |
{
|
|
|
24 |
"action": "https://moodle.local/admin/search.php",
|
|
|
25 |
"inputname": "search",
|
|
|
26 |
"searchstring": "Search",
|
|
|
27 |
"hiddenfields": [
|
|
|
28 |
{
|
|
|
29 |
"name": "cmid",
|
|
|
30 |
"value": "11"
|
|
|
31 |
}
|
|
|
32 |
]
|
|
|
33 |
}
|
|
|
34 |
}}
|
|
|
35 |
<div id="searchinput-navbar-{{uniqid}}" class="simplesearchform">
|
|
|
36 |
<div class="collapse" id="searchform-navbar">
|
|
|
37 |
<form autocomplete="off" action="{{{ action }}}" method="get" accept-charset="utf-8" class="mform d-flex flex-wrap align-items-center searchform-navbar">
|
|
|
38 |
{{#hiddenfields}}
|
|
|
39 |
<input type="hidden" name="{{ name }}" value="{{ value }}">
|
|
|
40 |
{{/hiddenfields}}
|
1441 |
ariadna |
41 |
<div class="input-group" {{#grouplabel}}role="group" aria-labelledby="searchgrouplabel-{{uniqid}}"{{/grouplabel}}>
|
|
|
42 |
{{#grouplabel}}
|
|
|
43 |
<span id="searchgrouplabel-{{uniqid}}" class="visually-hidden">{{{ . }}}</span>
|
|
|
44 |
{{/grouplabel}}
|
|
|
45 |
<input type="text"
|
|
|
46 |
id="searchinput-{{uniqid}}"
|
|
|
47 |
class="form-control withclear"
|
|
|
48 |
placeholder="{{{ searchstring }}}"
|
|
|
49 |
aria-label="{{{ searchstring }}}"
|
|
|
50 |
name="{{{ inputname }}}"
|
|
|
51 |
data-region="input"
|
|
|
52 |
autocomplete="off"
|
|
|
53 |
>
|
1 |
efrain |
54 |
<label for="searchinput-{{uniqid}}">
|
1441 |
ariadna |
55 |
<span class="visually-hidden">{{{ searchstring }}}</span>
|
1 |
efrain |
56 |
</label>
|
1441 |
ariadna |
57 |
<a class="btn btn-close"
|
|
|
58 |
data-action="closesearch"
|
|
|
59 |
data-bs-toggle="collapse"
|
|
|
60 |
href="#searchform-navbar"
|
|
|
61 |
role="button"
|
|
|
62 |
title="{{#str}} closebuttontitle {{/str}}"
|
|
|
63 |
>
|
|
|
64 |
<span class="visually-hidden">{{#str}} closebuttontitle {{/str}}</span>
|
|
|
65 |
</a>
|
|
|
66 |
<button type="submit" class="btn btn-submit" data-action="submit" title="{{#str}}performsearch, search{{/str}}">
|
|
|
67 |
{{#pix}} a/search, core {{/pix}}
|
|
|
68 |
<span class="visually-hidden">{{#str}}performsearch, search{{/str}}</span>
|
|
|
69 |
</button>
|
1 |
efrain |
70 |
</div>
|
|
|
71 |
</form>
|
|
|
72 |
</div>
|
|
|
73 |
<a
|
1441 |
ariadna |
74 |
class="rounded-0 nav-link icon-no-margin"
|
|
|
75 |
data-bs-toggle="collapse"
|
1 |
efrain |
76 |
data-action="opensearch"
|
|
|
77 |
href="#searchform-navbar"
|
|
|
78 |
role="button"
|
|
|
79 |
aria-expanded="false"
|
|
|
80 |
aria-controls="searchform-navbar"
|
|
|
81 |
title="{{#str}} togglesearch {{/str}}"
|
|
|
82 |
>
|
|
|
83 |
{{#pix}} a/search, core {{/pix}}
|
1441 |
ariadna |
84 |
<span class="visually-hidden">{{#str}} togglesearch {{/str}}</span>
|
1 |
efrain |
85 |
</a>
|
|
|
86 |
</div>
|
|
|
87 |
|
|
|
88 |
{{#js}}
|
|
|
89 |
require(
|
|
|
90 |
[
|
|
|
91 |
'jquery',
|
|
|
92 |
],
|
|
|
93 |
function(
|
|
|
94 |
$
|
|
|
95 |
) {
|
1441 |
ariadna |
96 |
const container = document.getElementById('searchform-navbar');
|
|
|
97 |
const opensearch = container.parentElement.querySelector('[data-action="opensearch"]');
|
|
|
98 |
const input = container.querySelector('[data-region="input"]');
|
|
|
99 |
const submit = container.querySelector('[data-action="submit"]');
|
1 |
efrain |
100 |
|
1441 |
ariadna |
101 |
submit.addEventListener('click', (e) => {
|
|
|
102 |
if (input.valUE === '') {
|
1 |
efrain |
103 |
e.preventDefault();
|
|
|
104 |
}
|
|
|
105 |
});
|
1441 |
ariadna |
106 |
|
|
|
107 |
container.addEventListener('hidden.bs.collapse', () => {
|
|
|
108 |
opensearch.classList.remove('d-none');
|
|
|
109 |
input.value = '';
|
1 |
efrain |
110 |
});
|
1441 |
ariadna |
111 |
|
|
|
112 |
container.addEventListener('show.bs.collapse', () => {
|
|
|
113 |
opensearch.classList.add('d-none');
|
1 |
efrain |
114 |
});
|
1441 |
ariadna |
115 |
|
|
|
116 |
container.addEventListener('shown.bs.collapse', () => {
|
1 |
efrain |
117 |
input.focus();
|
|
|
118 |
});
|
|
|
119 |
});
|
|
|
120 |
{{/js}}
|