Files
itzmineydev/src/app/tos/tos.component.ts
T
2026-03-16 00:20:57 +01:00

116 lines
3.1 KiB
TypeScript

import {AfterViewInit, Component, OnInit,} from '@angular/core';
import {DeviceDetectorService} from '../shared/services/device-detector.service';
import {Title} from '@angular/platform-browser';
import {NgIf} from '@angular/common';
import {TranslatePipe} from '@ngx-translate/core';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
@Component({
selector: 'app-services',
imports: [
NgIf,
TranslatePipe,
ParallaxComponent
],
templateUrl: './tos.component.html',
styleUrl: './tos.component.css'
})
export class TosComponent implements OnInit, AfterViewInit {
isMobile: boolean = false;
activeSection: string = '';
copiedSection: string | null = null;
constructor(
private deviceService: DeviceDetectorService,
private titleService: Title
) {}
scrollToSection(event: Event, targetId: string): void {
event.preventDefault();
const target = document.getElementById(targetId);
if (target) {
window.scrollTo({
top: target.offsetTop + 80,
behavior: 'smooth'
});
}
}
ngOnInit() {
this.titleService.setTitle('Terms of Service | itzMiney');
this.isMobile = this.deviceService.isMobile;
}
ngAfterViewInit() {
this.initScrollTracking();
}
initScrollTracking(): void {
const sections = Array.from(document.querySelectorAll('section')) as HTMLElement[];
const updateActiveSection = () => {
let closestSection: string | null = null;
let minDistance = Number.MAX_VALUE;
const viewportCenter = window.scrollY + window.innerHeight / 10;
sections.forEach(section => {
const rect = section.getBoundingClientRect();
const sectionTop = window.scrollY + rect.top;
const distance = Math.abs(viewportCenter - sectionTop);
if (distance < minDistance) {
minDistance = distance;
closestSection = section.id;
}
});
if (closestSection && closestSection !== this.activeSection) {
this.activeSection = closestSection;
document.querySelectorAll('.floating-nav a').forEach(link => {
link.classList.remove('active');
});
const activeLink = document.querySelector(`a[href="#${closestSection}"]`);
if (activeLink) {
activeLink.classList.add('active');
}
}
requestAnimationFrame(updateActiveSection);
};
requestAnimationFrame(updateActiveSection);
}
copySectionLink(sectionId: string): void {
const url = `${window.location.origin}${window.location.pathname}#${sectionId}`;
navigator.clipboard.writeText(url).then(() => {
this.copiedSection = sectionId;
setTimeout(() => {
this.copiedSection = null;
}, 2000);
});
}
copyToClipboard(text: string): void {
navigator.clipboard.writeText(text).then(() => {
if (text.includes('@')) {
this.copiedSection = 'email';
} else if (text.includes('+')) {
this.copiedSection = 'phone';
}
// Reset the copied section after 2 seconds
setTimeout(() => {
this.copiedSection = null;
}, 2000);
});
}
}