diff options
Diffstat (limited to 'src/App.svelte')
| -rw-r--r-- | src/App.svelte | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/src/App.svelte b/src/App.svelte index dc81785..2086708 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -15,7 +15,7 @@ }) ); - let france = France + let france = France; let currentDepGuessed = -1; let listGuesses = [] let codeSelected; @@ -30,6 +30,9 @@ let canImprove = true; let feedbackString = ""; + let fr_svg; // France SVG binding + let info; // tooltip div binding + function addClassGuess(dep, className) { if(["75", "92", "93", "94"].includes(dep)) { addClassGuess(dep + "-bis", className) @@ -55,6 +58,7 @@ winCount = 0; guessCount = 0; + // Clean the map of any previous style for(let dep of listDep) { removeClassGuess(dep, "win") removeClassGuess(dep, "miss") @@ -113,7 +117,6 @@ autocomplete.value = ""; } - function replaceSlide({ duration = 200, pixels = 200} = {}) { function send(node) { return function() { @@ -149,6 +152,38 @@ function showConfetti() { jsConfetti.addConfetti() } + + function initTooltip() { + /** + * Set the tooltip event listener to show the department name on hover. + */ + const deps = fr_svg.getElementsByTagName("path"); + + for(let dep of deps) { + if(dep.id.startsWith("dep_")) { + const code = dep.id.slice(4).replace("-bis", ""); + + dep.addEventListener("mouseenter", () => { + info.classList.add("active") + info.innerHTML = `<b>${departements[code]['name']}</b>` + }); + + dep.addEventListener("mouseleave", () => { + info.classList.remove("active") + }); + dep.addEventListener("mousemove", e => { + // info.style.transform = "translate3d(" + e.layerX + "px," + e.layerY + "px, 0)"; + info.style.top = `${e.pageY - 70}px`; + info.style.left = `${e.pageX - 0}px`; + }); + } + } + } + + onMount(() => { + initTooltip(); + }); + </script> <main> @@ -160,7 +195,7 @@ <h3>Devine quel est ce département : </h3> {/if} - <svelte:component this={france}/> + <svelte:component this={france} bind:svg={fr_svg}/> {#if currentDepGuessed == -1} <div class="response" in:receive out:send> @@ -174,7 +209,7 @@ {/if} </div> {/if} - <button type="button" on:click={start}>{ guessCount > 0 ? "Restart" : "Start" }</button> + <button type="button" on:click={start}>{ guessCount > 0 ? "Recommencer" : "Démarrer" }</button> </div> {:else} <div class="response" in:receive out:send> @@ -203,6 +238,8 @@ <div>{feedbackString}</div> </div> {/if} + + <div class="tooltip" bind:this={info}>Hello</div> </main> <style> @@ -227,5 +264,4 @@ .guessCode { height: 45px; } - </style> |