Refactor scrolling and enhance UI accessibility.

Replaced inline JavaScript for scrolling and copy functionality with Angular methods. Introduced `ScrollService` for smooth scroll-to-top functionality and added associated styles. Removed unused `isHomePage` method and cleaned up components for better maintainability.
This commit is contained in:
Teriuihi 2025-04-05 21:50:54 +02:00
parent c628f1e05b
commit dee84cc1a9
7 changed files with 87 additions and 10 deletions

View File

@ -35,7 +35,4 @@ export class AppComponent implements OnInit {
this.metaService.updateTag({name: 'keywords', content: this.keywords})
}
public isHomePage(): boolean {
return this.router.url === '/';
}
}

View File

@ -18,7 +18,7 @@
<h2 style="color: white;"><span class="player-count">Loading...</span></h2>
<h2 style="color: white;">Server IP: play.alttd.com</h2>
<!-- TODO make copy be angular not js-->
<button type="button" style="margin-top: 50px;" class="button-outer" onclick="copyToClipboard('play.alttd.com')">
<button type="button" style="margin-top: 50px;" class="button-outer" (click)="copyToClipboard('play.alttd.com')">
<span class="button-inner" id="copybutton">Copy IP</span>
</button>
</section>
@ -140,13 +140,12 @@
<img ngSrc="/public/img/logos/log.png" alt="Alternative Altitude Server Logo" height="129"
width="120">
<h2 style="margin: 20px 0; font-size: 1.8em;">play.alttd.com</h2>
<!-- TODO make this use angular not js-->
<button type="button" class="button-outer" onclick="copyToClipboard('play.alttd.com')">
<button type="button" class="button-outer" (click)="copyToClipboard('play.alttd.com')">
<span class="button-inner" id="copybutton2">Copy IP</span>
</button>
</div>
</section>
<a href="#top" id="scrollupbutton">
<a (click)="this.scrollService.scrollToTop()" class="scroll-up-button, active">
<span></span>
<p style="display: none;">Scroll Down</p>
</a>

View File

@ -1,6 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {ALTITUDE_VERSION} from '../constant';
import {ScrollService} from '../scroll/scroll.service';
@Component({
standalone: false,
@ -9,7 +10,7 @@ import {ALTITUDE_VERSION} from '../constant';
styleUrl: './home.component.scss'
})
export class HomeComponent implements OnInit {
constructor(private titleService: Title) {
constructor(private titleService: Title, public scrollService: ScrollService) {
}
private slides: string[] = ["/public/img/backgrounds/caruselimage2.png",
@ -70,7 +71,7 @@ export class HomeComponent implements OnInit {
return slide == this.slideIndex ? 'active-dot' : 'inactive-dot';
}
scrollToSection(): void {
public scrollToSection(): void {
const element = document.getElementById('scrollingpoint');
if (element) {
element.scrollIntoView({behavior: 'smooth', block: 'start'});

View File

@ -255,7 +255,7 @@
</div>
</div>
</section>
<a href="#top" id="scrollupbutton">
<a href="#top" id="scroll-up-button">
<span></span>
<p style="display: none;">Scroll Down</p>
</a>

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ScrollService } from './scroll.service';
describe('ScrollService', () => {
let service: ScrollService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ScrollService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,14 @@
import {Injectable} from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class ScrollService {
scrollToTop(): void {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
}

View File

@ -337,4 +337,54 @@ tr {
transition: 0.5s background ease;
}
.scroll-up-button.active:hover {
opacity: 1.0;
}
.scroll-up-button.active {
opacity: 0.5;
}
.scroll-up-button {
opacity: 0.0;
width: 60px;
height: 60px;
border-radius: 5px;
background-color: var(--link-color);
position: fixed;
right: 30px;
bottom: 30px;
transition: opacity 0.3s, 0.5s ease;
}
.scroll-up-button span::after {
position: absolute;
top: 50%;
left: 50%;
content: '';
width: 8px;
height: 8px;
margin: -2px 0 0 -5px;
border-left: 2px solid #fff;
border-bottom: 2px solid #fff;
-webkit-transform: rotate(135deg);
transform: rotate(135deg);
box-sizing: border-box;
}
.scroll-up-button span::before {
position: absolute;
top: 0;
left: 0;
z-index: -1;
content: '';
width: 60px;
height: 60px;
box-shadow: 0 0 0 0 rgba(255, 255, 255, .1);
border-radius: 100%;
opacity: 0;
box-sizing: border-box;
}
/* main css end */