diff --git a/datas.js b/datas.js index 7091e56..61f614b 100644 --- a/datas.js +++ b/datas.js @@ -14,16 +14,17 @@ const nombresChinois = [ ]; const pronomsChinois = [ - { hanzi: "我", pinyin: "wǒ", francais: "je / moi" }, - { hanzi: "你", pinyin: "nǐ", francais: "tu / toi" }, - { hanzi: "您", pinyin: "nín", francais: "vous (politesse)" }, - { hanzi: "他", pinyin: "tā", francais: "il / lui" }, - { hanzi: "她", pinyin: "tā", francais: "elle" }, - { hanzi: "它", pinyin: "tā", francais: "il/elle (objet, animal)" }, - { hanzi: "我们", pinyin: "wǒmen", francais: "nous" }, - { hanzi: "你们", pinyin: "nǐmen", francais: "vous (pluriel)" }, - { hanzi: "他们", pinyin: "tāmen", francais: "ils (masculin ou mixte)" }, - { hanzi: "她们", pinyin: "tāmen", francais: "elles (féminin)" }, - { hanzi: "它们", pinyin: "tāmen", francais: "ils/elles (objets, animaux)" } + { hanzi: "它们", pinyin: "tāmen", valeur: "ils/elles (objets, animaux)" }, + { hanzi: "我", pinyin: "wǒ", valeur: "je / moi" }, + { hanzi: "你", pinyin: "nǐ", valeur: "tu / toi" }, + { hanzi: "您", pinyin: "nín", valeur: "vous (politesse)" }, + { hanzi: "他", pinyin: "tā", valeur: "il / lui" }, + { hanzi: "她", pinyin: "tā", valeur: "elle" }, + { hanzi: "它", pinyin: "tā", valeur: "il/elle (objet, animal)" }, + { hanzi: "我们", pinyin: "wǒmen", valeur: "nous" }, + { hanzi: "你们", pinyin: "nǐmen", valeur: "vous (pluriel)" }, + { hanzi: "他们", pinyin: "tāmen", valeur: "ils (masculin ou mixte)" }, + { hanzi: "她们", pinyin: "tāmen", valeur: "elles (féminin)" }, + { hanzi: "它们", pinyin: "tāmen", valeur: "ils/elles (objets, animaux)" } ]; \ No newline at end of file diff --git a/hanzi_1.html b/hanzi_1.html index c386bea..8a3ea09 100644 --- a/hanzi_1.html +++ b/hanzi_1.html @@ -1,19 +1,10 @@ -
-
- -

- \ No newline at end of file diff --git a/hanzi_2.html b/hanzi_2.html index 00a8c5a..56effe6 100644 --- a/hanzi_2.html +++ b/hanzi_2.html @@ -1,19 +1,10 @@ -
-
- -

- \ No newline at end of file diff --git a/hanzi_3.html b/hanzi_3.html index 39b507a..f74a99f 100644 --- a/hanzi_3.html +++ b/hanzi_3.html @@ -1,19 +1,10 @@ -
-
- -

- \ No newline at end of file diff --git a/module_hanzi.js b/module_hanzi.js index 4190cf9..691fba2 100644 --- a/module_hanzi.js +++ b/module_hanzi.js @@ -1,158 +1,122 @@ + } + + // --------------------------------------------------------- + // INITIALISE UN WIDGET + // --------------------------------------------------------- + function init(options = {}) { + let iNb = 0; + const datas = options.datas; + let writers = [], okArray = []; + + function loadNext() { + displayChallenge(options.challengeID, datas[iNb]); + const res = initMultiCanvas(options.canvasID, datas[iNb].hanzi, options.view_settings); + writers = res.writers; + okArray = res.okArray; + startMultiQuiz(writers, okArray); + } + + function handleClick() { + const allOK = checkAll(okArray, options.feedbackID); + if (!allOK) return; + iNb++; + if (iNb >= datas.length) { + document.getElementById(options.feedbackID).textContent = "Fini !"; + document.getElementById(options.button_OK_ID).removeEventListener("click", handleClick); + return; + } + loadNext(); + } + + loadNext(); + document.getElementById(options.button_OK_ID).addEventListener("click", handleClick); + } + + // --------------------------------------------------------- + // AFFICHAGE DU CHALLENGE + // --------------------------------------------------------- + function displayChallenge(divID, item) { + document.getElementById(divID).textContent = + "Écrire : " + item.valeur + " / " + item.pinyin; + } + + // --------------------------------------------------------- + // CRÉATION MULTI-CANVAS + // --------------------------------------------------------- + function initMultiCanvas(containerID, hanzi, view_settings) { + const CHAR_SIZE = 150; + const chars = [...hanzi]; + const container = document.getElementById(containerID); + container.innerHTML = ""; + container.style.cssText = "display:flex;flex-direction:row;flex-wrap:nowrap;align-items:flex-start;gap:12px"; + + const okArray = new Array(chars.length).fill(false); + const writers = chars.map((char, index) => { + const div = document.createElement("div"); + div.id = `${containerID}_${index}`; + container.appendChild(div); + const hw = HanziWriter.create(div.id, char, { + width: CHAR_SIZE, height: CHAR_SIZE, + showCharacter: view_settings?.showCharacter ?? true, + showOutline: view_settings?.showOutline ?? true, + showHintAfterMisses: 1, highlightOnComplete: false, padding: 5 + }); + div.style.cssText = `display:inline-block;width:${CHAR_SIZE}px;height:${CHAR_SIZE}px;flex-shrink:0`; + return hw; + }); + return { writers, okArray }; + } + + // --------------------------------------------------------- + // LANCER UN QUIZ PAR CANVAS + // --------------------------------------------------------- + function startMultiQuiz(writers, okArray) { + writers.forEach((hw, idx) => { + hw.quiz({ + onMistake: () => { okArray[idx] = false; }, + onComplete: () => { okArray[idx] = true; } + }); + }); + } + + // --------------------------------------------------------- + // CHECK GLOBAL + // --------------------------------------------------------- + function checkAll(okArray, feedbackId) { + const el = document.getElementById(feedbackId); + const allOK = okArray.every(Boolean); + el.textContent = allOK ? "✔️ Bravo !" : "❌ Incorrect, continuez !"; + el.style.color = allOK ? "green" : "red"; + return allOK; + } + + // --------------------------------------------------------- + // EXPORT + // --------------------------------------------------------- + return { newWidget, init }; +})(); + \ No newline at end of file diff --git a/styles.html b/styles.html deleted file mode 100644 index 0a0c687..0000000 --- a/styles.html +++ /dev/null @@ -1,17 +0,0 @@ -