Skip to content

Commit

Permalink
fix: search functionality keeps the current tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Hunam6 committed Apr 13, 2021
1 parent ec20452 commit e097e44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions views/all.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,11 @@
<script>
//Search functionality
function search() {
location.search = 'q=' + document.querySelector('#search-bar').value.replace(' ', '+')
let params = new URLSearchParams(location.search)
params.set('q', document.querySelector('#search-bar').value.replace(' ', '+'))
location.search = params.toString()
}
document.querySelector('#search-bar').addEventListener('keyup', (e) => event.keyCode === 13 ? document.querySelector('#search').click() : null)
document.querySelector('#search-bar').addEventListener('keyup', e => event.keyCode === 13 ? search() : null)
//Previous & next buttons
function prev() {
Expand All @@ -425,7 +427,7 @@
//TODO: when hover an other menu item then #current "un-hover" the #current element
//Menu links
document.querySelectorAll('.menu').forEach(el => el.setAttribute('href', location.search + el.getAttribute('href')))
document.querySelectorAll('.menu').forEach(el => el.setAttribute('href', location.search.split('&')[0] + el.getAttribute('href')))
</script>
</body>

Expand Down
8 changes: 5 additions & 3 deletions views/images.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,16 @@
<script>
//Search functionality
function search() {
location.search = 'q=' + document.querySelector('#search-bar').value.replace(' ', '+')
let params = new URLSearchParams(location.search)
params.set('q', document.querySelector('#search-bar').value.replace(' ', '+'))
location.search = params.toString()
}
document.querySelector('#search-bar').addEventListener('keyup', (e) => event.keyCode === 13 ? document.querySelector('#search').click() : null)
document.querySelector('#search-bar').addEventListener('keyup', e => event.keyCode === 13 ? search() : null)
//TODO: when hover an other menu item then #current "un-hover" the #current element
//Menu links
document.querySelectorAll('.menu').forEach(el => el.setAttribute('href', location.search + el.getAttribute('href')))
document.querySelectorAll('.menu').forEach(el => el.setAttribute('href', location.search.split('&')[0] + el.getAttribute('href')))
</script>
</body>

Expand Down

0 comments on commit e097e44

Please sign in to comment.