Spaces:
Running

powerpact / script.js
Dhaneshm46's picture
GreenAppleGrids is a decentralized energy trading platform for India’s power market, enabling peer-to-peer transactions of electricity under open-access regulations. The platform operates as a **dual-mode PPA marketplace**, supporting both **Physical Open Access PPAs** (long-term renewable power purchase agreements with actual energy delivery) and **Financial VPPAs** (Virtual Power Purchase Agreements, i.e. contract-for-difference deals without physical delivery). This allows corporate consumers to procure renewable energy either through direct supply or via financial hedging mechanisms.
3ea6844 verified
Raw History Blame Contribute Delete
3.42 kB
// Initialize tooltips
document.addEventListener('DOMContentLoaded', function() {
// Initialize any tooltips
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Mobile menu toggle functionality
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
if(mobileMenuButton && mobileMenu) {
mobileMenuButton.addEventListener('click', function() {
mobileMenu.classList.toggle('hidden');
});
}
});
// Form validation for login/register
function validateForm(formId) {
const form = document.getElementById(formId);
if(form) {
form.addEventListener('submit', function(e) {
let isValid = true;
const inputs = form.querySelectorAll('input[required]');
inputs.forEach(input => {
if(!input.value.trim()) {
isValid = false;
input.classList.add('border-red-500');
} else {
input.classList.remove('border-red-500');
}
});
if(!isValid) {
e.preventDefault();
const errorElement = form.querySelector('.form-error');
if(errorElement) {
errorElement.classList.remove('hidden');
}
}
});
}
}
// Initialize form validation on page load
document.addEventListener('DOMContentLoaded', function() {
validateForm('login-form');
validateForm('register-form');
});
// Dark mode toggle
function toggleDarkMode() {
const html = document.documentElement;
html.classList.toggle('dark');
localStorage.setItem('darkMode', html.classList.contains('dark'));
}
// Check for saved dark mode preference
if (localStorage.getItem('darkMode') === 'true') {
document.documentElement.classList.add('dark');
}
// API fetch example for marketplace data
async function fetchMarketplaceData() {
try {
const response = await fetch('/api/marketplace');
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching marketplace data:', error);
return [];
}
}
// Initialize charts (using Chart.js if included)
function initCharts() {
const ctx = document.getElementById('energyChart');
if(ctx) {
new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{
label: 'Energy Generated (kWh)',
data: [12000, 19000, 3000, 5000, 2000, 3000],
borderColor: '#22c55e',
backgroundColor: 'rgba(34, 197, 94, 0.1)',
tension: 0.1,
fill: true
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
}
},
scales: {
y: {
beginAtZero: true
}
}
}
});
}
}
// Call any initialization functions when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
initCharts();
});