On enter pressed --> navigate

This commit is contained in:
Baptiste Marty 2020-12-06 10:57:01 +01:00
parent e4fb9b60c2
commit d8566245a1
2 changed files with 16 additions and 10 deletions

View file

@ -130,7 +130,6 @@ main{
background-image: linear-gradient( #5EE283, #057B26); background-image: linear-gradient( #5EE283, #057B26);
border-radius: 4vw; border-radius: 4vw;
box-shadow: -0.2vw 0.2vw 0.2vw rgba(255, 255, 255, 0.7); box-shadow: -0.2vw 0.2vw 0.2vw rgba(255, 255, 255, 0.7);
padding:0.8vw 0.8vw 0.5vw 0.8vw;
opacity:0; opacity:0;
animation:fade-text 1s forwards; animation:fade-text 1s forwards;
animation-delay:6s; animation-delay:6s;
@ -138,6 +137,7 @@ main{
} }
#buttonTxt { #buttonTxt {
padding:0.8vw 0.8vw 0.5vw 0.8vw;
text-decoration:none; text-decoration:none;
margin:0; margin:0;
color : black; color : black;

View file

@ -14,16 +14,21 @@ function initError(){
errorTxt.innerText = "" errorTxt.innerText = ""
} }
function handleNavigation(){ function handleNavigation(event){
if(event.keyCode == 13){
pseudo = pseudoInput.value;
console.log(pseudo); console.log(pseudo);
if (pseudo){ if (pseudo){
initError(); initError();
button.childNodes[1].setAttribute("href","etrange_decouverte.html") button.childNodes[1].setAttribute("href","etrange_decouverte.html")
localStorage.setItem("pseudo",pseudo); localStorage.setItem("pseudo",pseudo);
button.childNodes[1].click()
} else { } else {
button.childNodes[1].removeAttribute("href") button.childNodes[1].removeAttribute("href")
errorTxt.innerText = "Veuillez rentrer un pseudo svp" errorTxt.innerText = "Veuillez rentrer un pseudo svp"
} }
}
} }
function handlePseudoChange(event){ function handlePseudoChange(event){
@ -36,4 +41,5 @@ initError();
// event listeners // event listeners
pseudoInput.addEventListener("change",handlePseudoChange) pseudoInput.addEventListener("change",handlePseudoChange)
pseudoInput.addEventListener("keypress",handleNavigation)
button.addEventListener("click",handleNavigation) button.addEventListener("click",handleNavigation)