No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

aide_ami.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //------------------ Variables ------------------//
  2. let p_counter = 0;
  3. let texts = document.getElementsByClassName("textWillAppear");
  4. let questions = document.getElementsByClassName('questionWillAppear');
  5. let button = document.getElementById("button1");
  6. let friendInput = document.getElementById("friendInput");
  7. let friendPseudo = '';
  8. let inputBox = document.getElementById("inputBox");
  9. let errorMsg = inputBox.childNodes[1];
  10. let buttonBox = document.getElementById("buttons");
  11. let arrow = document.getElementById("arrow");
  12. let space = document.getElementById("space");
  13. let NB_TEXTS = texts.length;
  14. let NB_QUESTIONS = questions.length;
  15. let NB_BUTTONS = 1;
  16. let NB_ELEMENTS_TO_APPEAR = NB_TEXTS + NB_QUESTIONS + NB_BUTTONS;
  17. //------------------ Fonctions ------------------//
  18. //gère les apparitions et disparitions des textes
  19. function makeNextTextAppear(event) {
  20. if (p_counter < NB_ELEMENTS_TO_APPEAR) {
  21. if (event.keyCode == 13 || event.keyCode == 32) {
  22. if(p_counter < 1) {
  23. texts[p_counter].style.cssText = "animation: fade 2s forwards;";
  24. }
  25. if (p_counter >= 1 && p_counter < 5) {
  26. questions[p_counter-1].style.cssText = "animation: fade 2s forwards;";
  27. }
  28. if(p_counter >= 5 && p_counter < 7) {
  29. texts[p_counter-NB_QUESTIONS].style.cssText = "animation: fade 2s forwards;";
  30. }
  31. if(p_counter == 7) {
  32. button.style.cssText = "animation: fade 2s forwards;";
  33. arrow.style.cssText = "animation: fade-reverse 2s forwards;"
  34. space.style.cssText = "animation: fade-reverse 2s forwards;"
  35. }
  36. p_counter += 1;
  37. }
  38. }
  39. }
  40. function handleInputChange (event) {
  41. friendPseudo = event.target.value;
  42. console.log(friendPseudo);
  43. }
  44. //fonction pour gérer le bouton (qui est en fait un lien customisé)
  45. function handleButtonClicked(event) {
  46. if (friendPseudo) {
  47. errorMsg.innerHTML = '';
  48. localStorage.setItem("friendPseudo", friendPseudo);
  49. button.setAttribute('href', './couloir_ami.html');
  50. button.click();
  51. } else {
  52. //desactive le lien
  53. button.removeAttribute('href');
  54. //on enleve l'event listener pour pas pouvoir spam le bouton
  55. button.removeEventListener("click", handleButtonClicked);
  56. //faire clignoter le message d'erreur
  57. let repeater = setInterval(() => {
  58. friendInput.setAttribute("placeholder", "");
  59. setTimeout(() => {
  60. friendInput.setAttribute("placeholder", "Et votre ami ?");
  61. }, 100);
  62. }, 200);
  63. setTimeout(() => {
  64. clearInterval(repeater);
  65. button.addEventListener("click", handleButtonClicked);
  66. }, 1000);
  67. }
  68. }
  69. //------------------ Gestion events ------------------//
  70. //Pour pas faire apparaitre le texte avant que la premiere phrase soit apparue
  71. setTimeout(() => {
  72. document.addEventListener("keypress", makeNextTextAppear);
  73. }, 2000);
  74. friendInput.addEventListener("input", handleInputChange);
  75. button.addEventListener("click", handleButtonClicked);