Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

styling span #18

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</div>
<div id="content" class="content hidden">
<div class="logoContainer">
<img src="assets/jumanjiLogo.png" alt="Logo" id="inLogo">
<img src="assets/jumanjiLogo.png" alt="Logo" id="inLogo" />
</div>
<div class="start-page">
<div class="bab1"></div>
Expand All @@ -39,7 +39,7 @@
</div>
</div>
</div>
<audio id="sound"><source src="sound/jumanji.mp3" /></audio>
<audio id="sound"><source src="sound/Soundtrack Jumanji.mp3" /></audio>
<div class="madLibsEdit"></div>
<div class="madLibsPreview"></div>
</div>
Expand Down
47 changes: 28 additions & 19 deletions madlibs.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ const soundBtn = () => {
opacity == 1 ? (icon.style.opacity = "0%") : (icon.style.opacity = "100%");
};

// Parsing the story
function parseStory(rawStory) {
// Your code here.
rawStory = rawStory.replace(/\./g, " .");
rawStory = rawStory.replace(/\,/g, " ,");
let arrWord = rawStory.split(" ");
let storyToObj = [];
arrWord.forEach((item) => {
arrWord.forEach(item => {
if (item.match(/[[a-zA-Z]]/g)) {
let key = item.split("[");
switch (key[1]) {
Expand Down Expand Up @@ -114,16 +115,22 @@ function parseStory(rawStory) {
* You'll want to use the results of parseStory() to display the story on the page.
*
*/
// Using querySelector to select a specific element
const body = document.querySelector("body");
const container = document.createElement("div");
const edit = document.querySelector(".madLibsEdit"); // Using querySelector to select a specific element
const pre = document.querySelector(".madLibsPreview"); // Using querySelector to select a specific element
const edit = document.querySelector(".madLibsEdit");
const pre = document.querySelector(".madLibsPreview");
// creating a play and reset buttons
const playMusic = document.createElement("button");
playMusic.id = "musicButton";
const resetBtn = document.createElement("button");
playMusic.id = "musicButton";
resetBtn.id = "resetButton";
playMusic.textContent = "Play";
resetBtn.textContent = "Reset";
// selecting the sound button in the start page
const soundCheckBtn = document.querySelector(".sound-btn");
const sound = document.getElementById("sound");
// adding click event to soundCheckBtn
soundCheckBtn.addEventListener("click", () => {
if (sound.paused) {
sound.play();
Expand All @@ -132,10 +139,9 @@ soundCheckBtn.addEventListener("click", () => {
sound.pause();
}
});
body.append(container);
playMusic.textContent = "Play";
resetBtn.textContent = "Reset";

body.append(container);
// adding click event to play/pause button
playMusic.addEventListener("click", () => {
if (sound.paused) {
sound.play();
Expand All @@ -150,6 +156,8 @@ container.setAttribute("class", "container");
container.appendChild(edit);
container.appendChild(pre);

// showing the story

function madlibsEdit(processedStory) {
const editPara = document.createElement("p");
editPara.className = "editText";
Expand All @@ -161,34 +169,34 @@ function madlibsEdit(processedStory) {
if (item.pos) {
const input = document.createElement("input");
const span = document.createElement("span");

span.setAttribute("class", "opacity");
// adding style to the preview words
span.setAttribute("class", "spanText");
// adding styling to the input
input.setAttribute("class", "input");
editPara.appendChild(input);
previewPara.appendChild(span);
input.setAttribute("class", "input");
// Constraining user inputs;
input.setAttribute("placeholder", item.pos);
input.setAttribute("maxlength", "20");
input.style.width = "80px";
span.innerHTML = ` ${item.pos}`;

input.addEventListener("input", (e) => {
// event listener for live update in the preview
input.addEventListener("input", e => {
if (e.target.value === "") {
span.innerHTML = ` ${item.pos}`;
span.classList.remove("noopacity");
} else {
span.innerHTML = ` ${e.target.value}`;
span.classList.add("noopacity");
}
});
// Highlighting currently focused input
input.addEventListener("focus", function () {
input.style.backgroundColor = "green";
input.style.backgroundColor = "#b9ddb8b8";
});

// input blur
input.addEventListener("blur", function () {
input.style.backgroundColor = "#ecd599";
});

// reseting all the inputs when button is clicked
resetBtn.addEventListener("click", () => {
input.value = "";
input.setAttribute("placeholder", item.pos);
Expand All @@ -200,8 +208,9 @@ function madlibsEdit(processedStory) {
editPara.append(` ${item.word} `);
previewPara.append(` ${item.word} `);
}
// HotKeys event
newArr.forEach((input, i) => {
input.addEventListener("keypress", (e) => {
input.addEventListener("keypress", e => {
if (e.key === "Enter") {
if (i < newArr.length - 1) {
newArr[i + 1].focus();
Expand All @@ -218,6 +227,6 @@ function madlibsEdit(processedStory) {

getRawStory()
.then(parseStory)
.then((processedStory) => {
.then(processedStory => {
madlibsEdit(processedStory);
});
4 changes: 0 additions & 4 deletions sound/24655.mp3:Zone.Identifier

This file was deleted.

Binary file added sound/Soundtrack Jumanji.mp3
Binary file not shown.
9 changes: 8 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ button {
background-size: cover;
object-fit: initial;
line-height: 1.7;
border-radius: 5px;
}
.madLibsPreview {
background-image: url("assets/paper2.jpg");
Expand All @@ -244,6 +245,12 @@ button {
font-weight: 600;
}

/* styling the span */
.spanText {
color: white;
text-shadow: 2px 2px 4px rgba(3, 155, 0, 0.72);
}

/* styling for the logo on the main page */

.logoContainer {
Expand All @@ -263,7 +270,7 @@ button {
font-size: inherit;
border-radius: 5px;
padding: none;
width: auto;
width: 80px;
}

/* style for music and reset button */
Expand Down