From 2d6ff0c272c00917374930cad2f6ca5f7f5810fb Mon Sep 17 00:00:00 2001
From: Iniyal Palanisamy <123928113+IniyalPalanisamy@users.noreply.github.com>
Date: Fri, 18 Oct 2024 20:56:59 +0530
Subject: [PATCH] Update badge-list.js
Unique IDs: Each QR download button and canvas now has a unique ID based on the index.
Event Listener for QR Code: Added an event listener for the QR code download button.
---
js/badge-list.js | 66 +++++++++++++++++++++++++++---------------------
1 file changed, 37 insertions(+), 29 deletions(-)
diff --git a/js/badge-list.js b/js/badge-list.js
index c9f6e55..81a5045 100644
--- a/js/badge-list.js
+++ b/js/badge-list.js
@@ -1,8 +1,8 @@
+const slider = document.getElementById('badge-slider');
-
- const slider = document.getElementById('badge-slider');
-
- badgeList.forEach((badge) => {
+// Ensure badgeList is defined and has data
+if (badgeList && badgeList.length > 0) {
+ badgeList.forEach((badge, index) => {
const slide = document.createElement('div');
slide.classList.add('badge-slide');
@@ -15,21 +15,21 @@
Issued on: ${badge.issuedOn} at ${badge.issuedAt}
Share your badge:
-
-
+
-
+
@@ -37,28 +37,36 @@
`;
slider.appendChild(slide);
+
+ // Add event listener for QR code download button
+ const qrButton = document.getElementById(`download-qr-button-${index}`);
+ qrButton.addEventListener('click', () => {
+ // Implement QR code generation and download logic here
+ console.log(`Downloading QR Code for ${badge.title}`);
+ });
});
+}
- let currentIndex = 0;
+let currentIndex = 0;
- document.getElementById('next-btn').addEventListener('click', () => {
- if (currentIndex < badgeList.length - 1) {
- currentIndex++;
- } else {
- currentIndex = 0;
- }
- updateSliderPosition();
- });
+document.getElementById('next-btn').addEventListener('click', () => {
+ if (currentIndex < badgeList.length - 1) {
+ currentIndex++;
+ } else {
+ currentIndex = 0;
+ }
+ updateSliderPosition();
+});
- document.getElementById('prev-btn').addEventListener('click', () => {
- if (currentIndex > 0) {
- currentIndex--;
- } else {
- currentIndex = badgeList.length - 1;
- }
- updateSliderPosition();
- });
+document.getElementById('prev-btn').addEventListener('click', () => {
+ if (currentIndex > 0) {
+ currentIndex--;
+ } else {
+ currentIndex = badgeList.length - 1;
+ }
+ updateSliderPosition();
+});
- function updateSliderPosition() {
- slider.style.transform = `translateX(-${currentIndex * 100}%)`;
- }
\ No newline at end of file
+function updateSliderPosition() {
+ slider.style.transform = `translateX(-${currentIndex * 100}%)`;
+}