Download script.ts from adiiii12/yasiodev-clone-code-coffee: direct link, hf CLI and curl.
- Browser
- Download file 2.64 kB
-
https://huggingface.co/spaces/adiiii12/yasiodev-clone-code-coffee/resolve/main/script.ts
- Command line
-
hf download hf://spaces/adiiii12/yasiodev-clone-code-coffee/script.ts
-
curl -L -o script.ts https://huggingface.co/spaces/adiiii12/yasiodev-clone-code-coffee/resolve/main/script.ts
2.64 kB
| ```typescript | |
| interface CustomElement extends HTMLElement { | |
| style: CSSStyleDeclaration; | |
| } | |
| document.addEventListener('DOMContentLoaded', (): void => { | |
| // Mobile menu toggle | |
| const mobileMenuButton: HTMLButtonElement | null = document.querySelector('button[class*="md:hidden"]'); | |
| const navLinks: HTMLElement | null = document.querySelector('nav'); | |
| if (mobileMenuButton && navLinks) { | |
| mobileMenuButton.addEventListener('click', (): void => { | |
| navLinks.classList.toggle('hidden'); | |
| navLinks.classList.toggle('flex'); | |
| navLinks.classList.toggle('flex-col'); | |
| navLinks.classList.toggle('absolute'); | |
| navLinks.classList.toggle('top-16'); | |
| navLinks.classList.toggle('right-4'); | |
| navLinks.classList.toggle('bg-gray-800'); | |
| navLinks.classList.toggle('p-4'); | |
| navLinks.classList.toggle('rounded-lg'); | |
| navLinks.classList.toggle('shadow-xl'); | |
| }); | |
| } | |
| // Smooth scrolling for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach((anchor: HTMLAnchorElement): void => { | |
| anchor.addEventListener('click', function(e: MouseEvent): void { | |
| e.preventDefault(); | |
| const href: string | null = this.getAttribute('href'); | |
| if (href) { | |
| const target: HTMLElement | null = document.querySelector(href); | |
| if (target) { | |
| target.scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| } | |
| } | |
| }); | |
| }); | |
| // Add floating animation to elements | |
| const floatingElements: NodeListOf<CustomElement> = document.querySelectorAll('.floating'); | |
| floatingElements.forEach((el: CustomElement, index: number): void => { | |
| el.style.animationDelay = `${index * 0.5}s`; | |
| }); | |
| // Dark mode toggle (optional) | |
| const darkModeToggle: HTMLButtonElement = document.createElement('button'); | |
| darkModeToggle.innerHTML = '<i class="fas fa-moon"></i>'; | |
| darkModeToggle.className = 'fixed bottom-4 right-4 bg-gray-800 p-3 rounded-full shadow-lg'; | |
| document.body.appendChild(darkModeToggle); | |
| darkModeToggle.addEventListener('click', (): void => { | |
| document.body.classList.toggle('dark'); | |
| const icon: HTMLElement | null = darkModeToggle.querySelector('i'); | |
| if (icon) { | |
| if (document.body.classList.contains('dark')) { | |
| icon.classList.replace('fa-moon', 'fa-sun'); | |
| } else { | |
| icon.classList.replace('fa-sun', 'fa-moon'); | |
| } | |
| } | |
| }); | |
| }); | |
| ``` |