@ -1,8 +1,19 @@
document . addEventListener ( "DOMContentLoaded" , ( ) => {
document . addEventListener ( "DOMContentLoaded" , ( ) => {
const searchBar = document . getElementById ( "search-bar" ) ;
const searchBar = document . getElementById ( "search-bar" ) ;
const countrySelect = document . getElementById ( "result-country" ) ;
const arrowKeys = [ 37 , 38 , 39 , 40 ] ;
const arrowKeys = [ 37 , 38 , 39 , 40 ] ;
let searchValue = searchBar . value ;
let searchValue = searchBar . value ;
countrySelect . onchange = ( ) => {
let str = window . location . href ;
n = str . lastIndexOf ( "search" ) ;
if ( n > 0 ) {
str = str . substring ( 0 , n ) +
` search?q= ${ searchBar . value } &country= ${ countrySelect . value } ` ;
window . location . href = str ;
}
}
searchBar . addEventListener ( "keyup" , function ( event ) {
searchBar . addEventListener ( "keyup" , function ( event ) {
if ( event . keyCode === 13 ) {
if ( event . keyCode === 13 ) {
document . getElementById ( "search-form" ) . submit ( ) ;
document . getElementById ( "search-form" ) . submit ( ) ;