forked from OpenUserJS/OpenUserJS.org
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearchBar.html
More file actions
51 lines (42 loc) · 1.33 KB
/
searchBar.html
File metadata and controls
51 lines (42 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script type="text/javascript">
(function () {
'use strict';
function onInput(aEv) {
var container = aEv.target.parentNode.querySelector('.form-control-clear');
if (container) {
if (aEv.target.value) {
container.classList.remove('hidden');
} else {
container.classList.add('hidden');
}
}
}
function onClick(aEv) {
var container = aEv.target.parentNode.querySelector('.has-clear input[type="text"]');
var ev = new Event('input');
if (container) {
aEv.target.classList.add('hidden');
container.value = '';
container.dispatchEvent(ev);
container.focus();
}
}
function onDOMContentLoaded(aEv) {
var i = null;
var thisNode = null;
var nodes = null;
var ev = new Event('input');
nodes = document.querySelectorAll('.has-clear input[type="text"]');
for (i = 0; thisNode = nodes[i++];) {
thisNode.addEventListener('input', onInput);
thisNode.dispatchEvent(ev);
}
nodes = document.querySelectorAll('.form-control-clear');
for (i = 0; thisNode = nodes[i++];) {
thisNode.addEventListener('click', onClick);
thisNode.dispatchEvent(ev);
}
}
document.addEventListener('DOMContentLoaded', onDOMContentLoaded);
})();
</script>