Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ // Add smooth scrolling
+ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
+ anchor.addEventListener('click', function (e) {
+ e.preventDefault();
+ document.querySelector(this.getAttribute('href')).scrollIntoView({
+ behavior: 'smooth'
+ });
+ });
+ });
+
+ // Add table sorting
+ const tables = document.querySelectorAll('table');
+ tables.forEach(table => {
+ const headers = table.querySelectorAll('th');
+ headers.forEach((header, index) => {
+ header.addEventListener('click', () => {
+ sortTable(table, index);
+ });
+ header.style.cursor = 'pointer';
+ });
+ });
+ });
+
+ function sortTable(table, column) {
+ const tbody = table.querySelector('tbody');
+ const rows = Array.from(tbody.querySelectorAll('tr'));
+ const direction = table.dataset.sortDirection === 'asc' ? -1 : 1;
+
+ const sortedRows = rows.sort((a, b) => {
+ const aCol = a.querySelectorAll('td')[column].textContent.trim();
+ const bCol = b.querySelectorAll('td')[column].textContent.trim();
+ return aCol > bCol ? direction : -direction;
+ });
+
+ tbody.innerHTML = '';
+ sortedRows.forEach(row => tbody.appendChild(row));
+
+ table.dataset.sortDirection = direction === 1 ? 'asc' : 'desc';
+ }