main.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. $(document).ready(function () {
  2. var tableau = [
  3. {hanzi: "我",
  4. pinyin: "wǒ",
  5. francais: "je"},
  6. {hanzi: "你",
  7. pinyin: "nǐ",
  8. francais: "tu"},
  9. {hanzi: "他",
  10. pinyin: "tā",
  11. francais: "il, lui"},
  12. {hanzi: "好",
  13. pinyin: "hǎo",
  14. francais: "aller bien, être bien"},
  15. {hanzi: "你好",
  16. pinyin: "nǐhǎo",
  17. francais: "bonjour"},
  18. {hanzi: "很",
  19. pinyin: "hěn",
  20. francais: "très"},
  21. {hanzi: "吗",
  22. pinyin: "ma",
  23. francais: "particule interrogative simple"},
  24. {hanzi: "呢",
  25. pinyin: "ne",
  26. francais: "particule interrogative qui reprend la question"}];
  27. var tableauBoutons = ["#ajB1", "#ajB2", "#ajB3", "#ajB4", "#ajB5", "#ajB6", "#ajB7", "#ajB8"];
  28. var item = 0;
  29. function shuffle(array) {
  30. var m = array.length, t, i;
  31. // While there remain elements to shuffle…
  32. while (m) {
  33. // Pick a remaining element…
  34. i = Math.floor(Math.random() * m--);
  35. // And swap it with the current element.
  36. t = array[m];
  37. array[m] = array[i];
  38. array[i] = t;
  39. }
  40. return array;
  41. }
  42. function displayDimensions() {
  43. var tailleFontePx = $(".fonteQuestion").css("font-size");
  44. console.log("taillefontepx: ", tailleFontePx);
  45. var tailleFonte = tailleFontePx.slice(0, -2);
  46. var tailleAire = $("#texteaera").width();
  47. var rapport = 400 / tailleAire;
  48. $(".fonteQuestion").css("font-size", Math.round(32 / rapport));
  49. $(".bouton").css("font-size", Math.round(18 / rapport));
  50. $("#textearea").css("margin", 20 / rapport);
  51. }
  52. // enregistrement du callback du redimenssionnement de la fenêtre
  53. $(window).resize(displayDimensions);
  54. function setFontSize() {
  55. // on récupère la taille de la fonte;
  56. // on récupère la taille de la fenêtre
  57. // on calcule la proportion
  58. // on ajuste la taille de la fonte en fonction de ce ratio
  59. }
  60. function faux(item) {
  61. $(item).css("background-color", "red");
  62. }
  63. function juste(item) {
  64. $(item).css("background-color", "#4CAF50");
  65. }
  66. $("#ajB1").click(function () {
  67. console.log("je teste");
  68. if (item == 0) {
  69. juste($(this))
  70. } else {
  71. faux($(this))
  72. }
  73. });
  74. $("#ajB2").click(function () {
  75. console.log("je teste");
  76. if (item == 1) {
  77. juste($(this))
  78. } else {
  79. faux($(this))
  80. }
  81. });
  82. $("#ajB3").click(function () {
  83. console.log("je teste");
  84. console.log("je teste");
  85. if (item == 2) {
  86. juste($(this))
  87. } else {
  88. faux($(this))
  89. }
  90. });
  91. $("#ajB4").click(function () {
  92. console.log("je teste");
  93. console.log("je teste");
  94. if (item == 3) {
  95. juste($(this))
  96. } else {
  97. faux($(this))
  98. }
  99. });
  100. $("#ajB5").click(function () {
  101. console.log("je teste");
  102. console.log("je teste");
  103. if (item == 4) {
  104. juste($(this))
  105. } else {
  106. faux($(this))
  107. }
  108. });
  109. $("#ajB6").click(function () {
  110. console.log("je teste");
  111. console.log("je teste");
  112. if (item == 5) {
  113. juste($(this))
  114. } else {
  115. faux($(this))
  116. }
  117. });
  118. $("#ajB7").click(function () {
  119. console.log("je teste");
  120. console.log("je teste");
  121. if (item == 6) {
  122. juste($(this))
  123. } else {
  124. faux($(this))
  125. }
  126. });
  127. $("#ajB8").click(function () {
  128. console.log("je teste");
  129. console.log("je teste");
  130. if (item == 7) {
  131. juste($(this))
  132. } else {
  133. faux($(this))
  134. }
  135. });
  136. // on mélange les cartes
  137. tableau = shuffle(tableau);
  138. console.log(tableau);
  139. item = Math.floor((Math.random() * 8) + 1);
  140. console.log("nouvel item: ", item);
  141. // DEBUG
  142. console.log("item: ", item);
  143. console.log("**********");
  144. for (var i = 0; i < 8; i++) {
  145. console.log(i + " " + "hanzi " + tableau[i].hanzi + " pinyin " + tableau[i].pinyin + " français " + tableau[i].francais);
  146. }
  147. console.log("**********");
  148. // END DEBUG
  149. // on popularise la question ;)
  150. var txt1 = "<span class='fonteQuestion'>" + tableau[item].hanzi + "</span>";
  151. // DEBUG
  152. console.log("txt1 ", txt1);
  153. // END DEBUG
  154. var txt2 = "<span class='fonteQuestion'>" + tableau[item].pinyin + "</span>";
  155. // DEBUG
  156. console.log("txt2 ", txt2);
  157. // END DEBUG
  158. txt2.innerHTML = tableau[item].pinyin;
  159. $("#pp").append(txt1, txt2);
  160. // on popularise les réponses
  161. for (var i = 0; i < 8; i++) {
  162. $(tableauBoutons[i]).text(tableau[i].francais);
  163. // DEBUG
  164. console.log(i + " " + tableau[i].hanzi + " " + tableau[i].pinyin + " " + tableau[i].francais);
  165. // END DEBUG
  166. }
  167. });