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

responsiveness1 #6

Merged
merged 1 commit into from
Nov 13, 2024
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
21 changes: 19 additions & 2 deletions scripts/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,31 @@ function showGameEndModal(message) {
}

function initializeTouchAndClickEvents() {
// Add click handlers to all squares
document.querySelectorAll('.square').forEach(square => {
// Add click handler for desktop
square.addEventListener('click', handleSquareClick);

// Prevent default touch behavior that might interfere with our logic
square.addEventListener('touchstart', (e) => {
e.preventDefault();
handleSquareClick(e);
});

// Prevent any default touch behaviors that might interfere
square.addEventListener('touchend', (e) => {
e.preventDefault();
});
});
}

function handleSquareClick(event) {
const square = event.currentTarget;
// Get the actual square element, whether from touch or click
const square = event.target.classList.contains('square') ?
event.target :
event.target.closest('.square');

if (!square) return;

const piece = square.querySelector('.piece');

// If no piece is selected
Expand Down
24 changes: 7 additions & 17 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,16 @@ h1{

/* Add touch support */
@media (hover: none) {
.square:hover {
background-color: inherit;
}

.square.touch-selected {
background-color: #c8e6c9;
}
}

.selected-square {
background-color: rgba(255, 255, 0, 0.4) !important;
}

/* Improve touch targets */
@media (hover: none) {
.square:hover {
background-color: inherit;
.square {
touch-action: none;
}

.piece {
-webkit-tap-highlight-color: transparent;
touch-action: none;
}

.selected-square {
background-color: rgba(255, 255, 0, 0.4) !important;
}
}