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

Add a pop up dialog box for Polls/Survey done ! #702 🌟🌟🌟 #724

Closed
wants to merge 1 commit into from
Closed
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
204 changes: 204 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,210 @@ <h2>Feedback Form</h2>

</script>
</div>

Copy link
Owner

@swaraj-das swaraj-das Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've told everyone multiple times: don’t add CSS or JavaScript directly in HTML file. It will be harder to manage for index.html . When I have to take over the project after your PR, it creates unnecessary issues and makes my job harder. Follow the project structure properly. Let’s keep it clean—separate HTML, CSS, and JavaScript. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swaraj-das okay wait I will give a new PR soon,

But you never told me 😓😓


<style>

body {

font-family: Arial, sans-serif;
}


/* Polls Popup Styles */
.popups {

display: none; /* Hidden by default */
position: fixed; /* Stay in place */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
background-color: rgba(0, 0, 0, 0.5); /* Black background with opacity */
justify-content: center; /* Center the popup */
align-items: center; /* Center the popup */
z-index: 1000; /* Sit on top */

}

.popups-content {

background: linear-gradient(#ff459f, #ff9532);
padding: 20px;
border-radius: 5px;
max-width: 400px;
text-align: center;

}

/* Set poll options to stack vertically */
#pollOptions {

display: flex;
flex-direction: column; /* Stack buttons vertically */
align-items: center; /* Center the buttons */

}

.poll-button,
.vote-button {

display: block; /* Change to block for full-width */
margin: 5px 0; /* Add vertical margin */
padding: 10px 15px;
border: none;
border-radius: 5px;
color: white;
cursor: pointer;
transition: background-color 0.3s;
width: 100%; /* Full width */
text-align: center;
font-size: 15px;
background: #1c525f;

}

.poll-button {

background-color: rgba(16, 22, 26, .4); /* Green */

}

.poll-button:hover {

background-color: #be264c; /* Darker green */
border: none;

}

.poll-button.selected {

background-color: #b92248; /* Blue for selected */
border: 1px solid black !important; /* 1px black border when selected */
outline: none !important;

}

.vote-button {

background: linear-gradient(135deg, #c7c400, #ff393d, #ff3c76, #f5f100b9);
border: 1px solid #000000;

}

.vote-button:hover {

background-color: #d32f2f; /* Darker red */

}

.uppercase {


font-size: 18px;
color: #000000;

}

#result {

margin-top: 10px; /* Space above result text */
word-wrap: break-word; /* Allow long text to wrap */
overflow: hidden; /* Prevent overflow */
max-height: 50px; /* Limit height */
color: #000000; /* Text color */
text-align: center; /* Center align the text */
font-size: 15px;

}


</style>
</head>
<body>

<!-- Poll Pop-up -->
<div class="popups" id="pollPopup">
<div class="popups-content">
<h2 class="uppercase">What type of Gaming Accessory are you Most Interested in?</h2>
<div id="pollOptions">
<button class="poll-button" data-value="Game Controllers">Game Controllers</button>
<button class="poll-button" data-value="VR Accessories">VR Accessories</button>
<button class="poll-button" data-value="Gaming Keyboard">Gaming Keyboard</button>
<button class="poll-button" data-value="Gaming Headphones">Gaming Headphones</button>
<button class="poll-button" style="display: none;" data-value="Option4">Option4</button>
<button class="poll-button" style="display: none;" data-value="Option5">Option5</button>
</div>
<button id="voteButton" class="vote-button">Vote</button>
<p id="result"></p> <!-- Result display -->
</div>
</div>

<script>
// Check if the user has already voted in this session
const hasVoted = sessionStorage.getItem('hasVoted');

// Show the poll popup after a delay, only if the user hasn't voted
function checkAndDisplayPollPopup() {
if (!hasVoted) {
document.getElementById('pollPopup').style.display = 'flex'; // Show poll
}
}

// Set timeout for poll display
setTimeout(checkAndDisplayPollPopup, 10000);

// Manage user selections and votes
const pollButtons = document.querySelectorAll('.poll-button[data-value]');
let selectedValue = '';

// Handle clicks on poll buttons
pollButtons.forEach(button => {
button.addEventListener('click', function() {
pollButtons.forEach(btn => btn.classList.remove('selected')); // Clear previous selections
button.classList.add('selected'); // Highlight selected button
selectedValue = button.getAttribute('data-value'); // Store selected value
});
});

// Handle voting process
document.getElementById('voteButton').addEventListener('click', function() {
if (selectedValue) {
document.getElementById('result').innerHTML = `You voted for: ${selectedValue}<br>Thank you!`; // Show result
sessionStorage.setItem('hasVoted', 'true'); // Save voting status
setTimeout(() => {
document.getElementById('pollPopup').style.display = 'none'; // Hide poll
}, 2000);
} else {
alert("Please select an option!"); // Alert if no option is selected
}
});

// Function to manage button focus for accessibility
function handleFocus(event) {
event.target.style.border = '2px solid #0058ff'; // Optional highlight effect
}

// Attach focus event for accessibility improvement
pollButtons.forEach(button => {
button.addEventListener('focus', handleFocus);
});

// Function to remove focus style
function handleBlur(event) {
event.target.style.border = ''; // Remove highlight effect
}

// Attach blur event for accessibility improvement
pollButtons.forEach(button => {
button.addEventListener('blur', handleBlur);
});

// Log when the script has loaded
console.log("Poll script initialized and ready!");
</script>


</body>


Expand Down
Loading