-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67bb125
commit 7293e89
Showing
6 changed files
with
146 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.jersey-10-regular { | ||
font-family: "Jersey 10", sans-serif; | ||
font-weight: 400; | ||
font-style: normal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,80 @@ | ||
document.addEventListener('DOMContentLoaded', function () { | ||
const games = [ | ||
{ href: 'https://www.google.com', name: 'Game Title 1' }, | ||
{ href: 'https://www.google.com', name: 'Game Title 2' }, | ||
// Add more games as needed | ||
] | ||
|
||
// Function to generate game list dynamically | ||
// Function to generate game list dynamically | ||
function generateGameList() { | ||
const gameList = document.getElementById('gameList') | ||
const games = gameList.querySelectorAll('li') | ||
let selectedGameIndex = 0 | ||
games.forEach((game, index) => { | ||
const listItem = document.createElement('li') | ||
listItem.className = 'game-item' | ||
if (index === 0) { | ||
listItem.classList.add('selected') | ||
} | ||
listItem.onclick = function () { | ||
toggleSelection(this) | ||
} | ||
|
||
function selectGame(index) { | ||
console.log('index', index) | ||
// Create the div for overlapping with the arrow | ||
const overlapDiv = document.createElement('div') | ||
overlapDiv.className = 'overlap' | ||
|
||
// Remove the selected class from all games | ||
games.forEach((game) => game.classList.remove('selected')) | ||
const arrowImg = document.createElement('img') | ||
arrowImg.src = 'arrow.png' | ||
arrowImg.alt = 'Down' | ||
arrowImg.className = 'arrow' | ||
|
||
// Add the selected class to the specified game | ||
games[index].classList.add('selected') | ||
const gameLink = document.createElement('a') | ||
gameLink.href = game.href | ||
gameLink.textContent = game.name | ||
|
||
// Focus on the selected game link for keyboard accessibility | ||
games[index].querySelector('a').focus() | ||
listItem.appendChild(overlapDiv) // Append the overlap div | ||
listItem.appendChild(arrowImg) | ||
listItem.appendChild(gameLink) | ||
gameList.appendChild(listItem) | ||
}) | ||
} | ||
|
||
// Update the selected game index | ||
selectedGameIndex = index | ||
} | ||
// Call the function to generate the game list | ||
generateGameList() | ||
|
||
// Select the first game by default | ||
selectGame(selectedGameIndex) | ||
// Function to toggle selection | ||
function toggleSelection(item) { | ||
const selected = document.querySelector('.selected') | ||
if (selected !== item) { | ||
selected.classList.remove('selected') | ||
selected.querySelector('.arrow').style.display = 'none' | ||
item.classList.add('selected') | ||
item.querySelector('.arrow').style.display = 'inline' | ||
|
||
// Function to handle navigation to the selected game link | ||
function navigateToSelectedGame() { | ||
const selectedGameLink = games[selectedGameIndex].querySelector('a') | ||
if (selectedGameLink) { | ||
window.location.href = selectedGameLink.href | ||
} | ||
const selectSound = document.getElementById('selectSound') | ||
selectSound.play() | ||
} | ||
} | ||
|
||
document.addEventListener('keydown', function (event) { | ||
if (event.key === 'ArrowUp') { | ||
if (selectedGameIndex > 0) { | ||
console.log('-') | ||
selectGame(selectedGameIndex - 1) | ||
} | ||
} else if (event.key === 'ArrowDown') { | ||
if (selectedGameIndex < games.length - 1) { | ||
console.log('+') | ||
selectGame(selectedGameIndex + 1) | ||
} | ||
} else if (event.key === 'Enter') { | ||
navigateToSelectedGame() | ||
// Add event listener for keyboard navigation | ||
document.addEventListener('keydown', function (event) { | ||
const selected = document.querySelector('.selected') | ||
if (event.key === 'Enter') { | ||
const selectedGame = selected.querySelector('a') | ||
if (selectedGame) { | ||
const startSound = document.getElementById('startSound') | ||
startSound.play() | ||
window.location.href = selectedGame.href | ||
// Play the start sound | ||
} | ||
}) | ||
|
||
// Add click event listeners to the game list items | ||
games.forEach((game, index) => { | ||
game.addEventListener('click', function () { | ||
selectGame(index) | ||
navigateToSelectedGame() | ||
}) | ||
}) | ||
} else if (event.key === 'ArrowUp') { | ||
const prev = selected.previousElementSibling | ||
if (prev) { | ||
toggleSelection(prev) | ||
} | ||
} else if (event.key === 'ArrowDown') { | ||
const next = selected.nextElementSibling | ||
if (next) { | ||
toggleSelection(next) | ||
} | ||
} | ||
}) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters