Skip to content

Commit

Permalink
Added debug options
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimeTheFirst committed Dec 4, 2021
1 parent 1c2c852 commit 980b662
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h1>Search.js tutorial</h1>


<br><br><br>
<input type='text' id='searchBar1'> <br>
<input type='text' id='searchBar1' > <br>
<p class='myFAQs'> FAQ answer 1 - this is a test line 28651<p>
<p class='myFAQs'> FAQ answer 2 - this is not a test line 28651546 <p>
<p class='myFAQs'> FAQ answer 3 - 7787 true<p>
Expand Down
4 changes: 2 additions & 2 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<div class="elems">FAQ answer 2 - this is not a test line 28651546</div>
<div class="elems">FAQ answer 3 - 7787 true</div>
<div class="elems">FAQ answer 4 - w87238 false</div>
<input type="text" id="input">
<input type="text" id="input1">
<script>
search('.elems','#input')
search('.elems','.input1')

</script>
</body>
Expand Down
29 changes: 20 additions & 9 deletions search.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
function search(searchOBJS,input) {

if (searchOBJS.includes('#')) {/*Checks that the second arguement is a class .*/
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
}

let sOBJS = document.querySelectorAll(searchOBJS)
if (sOBJS[0] == undefined) {
console.warning('search.js: The given class does not have any elements associated with it .')
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 (inputLc == undefined) {
console.error('search.js: The given id for the input does not have a input associated with it .')

if (options.debug) {
return search_debug(searchOBJS,sOBJS,inputLc,input)
}

console.log('Search :No errors in the arguments .')
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'
console.log(`${sOBJS[i].innerHTML} and input is ${inputLc.value} `)

}else {
sOBJS[i].style.position = 'relative'
sOBJS[i].style.visibility = 'visible'
}
}

})
}
}

0 comments on commit 980b662

Please sign in to comment.