File size: 2,634 Bytes
ab38bab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
// MCP Website JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Newsletter subscription form
const newsletterForm = document.getElementById('newsletter-form');
if (newsletterForm) {
newsletterForm.addEventListener('submit', function(e) {
e.preventDefault();
const email = this.querySelector('input[type="email"]').value;
// In a real implementation, this would send the email to a server
// For demonstration purposes, we'll show an alert
alert(`Thank you for subscribing with ${email}! You'll receive MCP updates soon.`);
this.reset();
});
}
// Smooth scrolling for navigation links
const navLinks = document.querySelectorAll('nav a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
// Add active class to navigation items on scroll
const sections = document.querySelectorAll('section[id]');
window.addEventListener('scroll', function() {
const scrollPosition = window.scrollY + 150;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
document.querySelector(`nav a[href="#${sectionId}"]`).classList.add('active');
} else {
document.querySelector(`nav a[href="#${sectionId}"]`).classList.remove('active');
}
});
});
// Create a simple syntax highlighting effect for code blocks
const codeBlocks = document.querySelectorAll('pre code');
codeBlocks.forEach(block => {
// Simple keyword highlighting
const keywords = ['import', 'const', 'let', 'var', 'function', 'return', 'async', 'await', 'new', 'class'];
const punctuation = ['{', '}', '[', ']', '(', ')', ',', ';', '.', ':'];
const strings = ['"', "'", '`'];
// Get the text content
let content = block.textContent;
// This is a very simple implementation - in a real-world scenario,
// you would use a proper syntax highlighting library like Prism.js or highlight.js
// For now, we'll just add a CSS class to the block to enable some basic styling
block.classList.add('syntax-highlighted');
});
});
|