@@ -32,14 +32,18 @@ const currentCategory = alphabetData[alphabet as keyof AlphabetsData];
3232 <BackButton />
3333 <article class =" tv container__typing" >
3434 <div class =" letter" >A</div >
35- <div class =" emoji" >{ currentCategory .icon } </div >
36- <div class =" spelling animation" id =" spelling" ></div >
35+ <div class =" content__display" >
36+ <div class =" emoji" >{ currentCategory .icon } </div >
37+ <div class =" image__container" ></div >
38+ </div >
39+ <div class =" spelling" id =" spelling" ></div >
3740 <div class =" description" id =" description" ></div >
3841 </article >
3942
4043 <script define:vars ={ { alphabetData: currentCategory .data , category: alphabet }} >
4144 const letterDiv = document.querySelector(".letter");
4245 const emojiDiv = document.querySelector(".emoji");
46+ const imageContainer = document.querySelector(".image__container");
4347 const spellDiv = document.querySelector(".spelling");
4448 const descriptionDiv = document.querySelector(".description");
4549
@@ -59,22 +63,62 @@ const currentCategory = alphabetData[alphabet as keyof AlphabetsData];
5963 const drawInfo = (letter, color) => {
6064 const info = alphabetData.find((item) => item.letter === letter);
6165 if (info) {
62- // Display text
6366 spellDiv.innerHTML = info.text;
6467 spellDiv.style.color = color;
65- document.documentElement.style.setProperty("--steps", info.text.length);
6668
67- // Display description
68- descriptionDiv.innerHTML = info.description;
69- descriptionDiv.style.color = color;
69+ document.documentElement.style.setProperty("--steps", info.text.length * 2);
7070
71- // Animation handling
71+ // Animation handling to spelling
7272 spellDiv.classList.remove("animation");
73- void spellDiv.offsetWidth;
7473 spellDiv.classList.add("animation");
74+
75+ if (info.description && info.description.trim() !== "") {
76+ descriptionDiv.innerHTML = info.description;
77+ descriptionDiv.style.color = color;
78+ document.documentElement.style.setProperty("--steps-desc", info.description.length * 2);
79+
80+ // Animation handling for description
81+ descriptionDiv.classList.remove("animation");
82+ descriptionDiv.classList.add("animation");
83+ } else {
84+ descriptionDiv.classList.remove("animation");
85+ descriptionDiv.innerHTML = "";
86+ }
87+
88+ if (info.image) {
89+ const img = new Image();
90+ img.onload = function () {
91+ emojiDiv.style.display = "none";
92+ imageContainer.style.display = "flex";
93+ imageContainer.innerHTML = "";
94+ imageContainer.appendChild(img);
95+
96+ img.style.width = "auto";
97+ img.style.height = "auto";
98+ img.style.maxWidth = "100%";
99+ img.style.maxHeight = "100%";
100+ };
101+ img.onerror = function () {
102+ emojiDiv.style.display = "block";
103+ imageContainer.style.display = "none";
104+ };
105+ img.src = `/assets/images/alphabets/${category}/${info.image}`;
106+ img.alt = info.text;
107+
108+ emojiDiv.style.display = "block";
109+ imageContainer.style.display = "none";
110+ } else {
111+ emojiDiv.style.display = "block";
112+ imageContainer.style.display = "none";
113+ }
75114 }
76115 };
77116
117+ window.addEventListener("DOMContentLoaded", () => {
118+ spellDiv.classList.remove("animation");
119+ descriptionDiv.classList.remove("animation");
120+ });
121+
78122 const colorBox = ["#FF6B6B", "#4ECDC4", "#45B7D1", "#96CEB4", "#FFEEAD", "#D4A5A5", "#9B59B6", "#3498DB"];
79123 const random = (arr) => arr[Math.floor(Math.random() * arr.length)];
80124 const isAlphabet = (keyCode) => keyCode >= 65 && keyCode <= 90;
@@ -88,7 +132,7 @@ const currentCategory = alphabetData[alphabet as keyof AlphabetsData];
88132 if (isAlphabet(keyCode)) {
89133 const keyCapital = key.toUpperCase();
90134 drawLetter(keyCapital, color);
91- drawInfo(keyCapital, color); // Pass color as parameter
135+ drawInfo(keyCapital, color);
92136 }
93137 },
94138 false
0 commit comments