-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.js
45 lines (33 loc) · 1.17 KB
/
search.js
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
function search_debug(searchOBJS,sOBJS,inputLc,input) {
if (searchOBJS.includes('#')) {/*Checks that the first arguement is a class .*/
console.error('search.js: search function only accepts an class as second argument')
return false
}
if (sOBJS[0] == undefined) {
console.warn('search.js: The given class does not have any elements associated with it .')
return false
}
if (inputLc == undefined) {
console.error('search.js: The given id for the input does not have a element associated with it .')
return false
}
console.log('search.js :No errors in the arguments .')
}
function search(searchOBJS,input,options={debug:true}) {
let sOBJS = document.querySelectorAll(searchOBJS)
let inputLc = document.querySelectorAll(input)[0] /*Lc stands for local*/
if (options.debug) {
return search_debug(searchOBJS,sOBJS,inputLc,input)
}
inputLc.addEventListener('input',()=>{
for(var i = 0 ; i < sOBJS.length ; i++ ){
if (!(sOBJS[i].innerHTML.includes(inputLc.value))) {
sOBJS[i].style.position = 'absolute'
sOBJS[i].style.visibility = 'hidden'
}else {
sOBJS[i].style.position = 'relative'
sOBJS[i].style.visibility = 'visible'
}
}
})
}