mirror of
https://github.com/kogakure/website-astro-stefanimhoff.de.git
synced 2026-02-03 20:15:27 +00:00
fix: move some scripts to central file because of issue with Swup
This commit is contained in:
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
---
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function setActiveLink() {
|
|
||||||
const links = document.querySelectorAll('.navigation a');
|
|
||||||
const currentPath = window.location.pathname;
|
|
||||||
console.log(currentPath);
|
|
||||||
|
|
||||||
links.forEach((link) => {
|
|
||||||
if (link.getAttribute('href') === currentPath) {
|
|
||||||
link.classList.add('is-active');
|
|
||||||
} else {
|
|
||||||
link.classList.remove('is-active');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setActiveLink();
|
|
||||||
</script>
|
|
||||||
@@ -25,23 +25,3 @@ const { text = 'Email', icon = true, ...props } = Astro.props;
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
</TextLink>
|
</TextLink>
|
||||||
|
|
||||||
<script>
|
|
||||||
function handleClick(event: Event) {
|
|
||||||
event.preventDefault();
|
|
||||||
const currentTarget = event.currentTarget;
|
|
||||||
if (currentTarget instanceof HTMLElement) {
|
|
||||||
const { name, domain, tld } = currentTarget.dataset;
|
|
||||||
if (name && domain && tld) {
|
|
||||||
const mailto = `mailto:${name}@${domain}.${tld}`;
|
|
||||||
window.open(mailto, '_blank');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const links = document.querySelectorAll('[data-email-link]');
|
|
||||||
|
|
||||||
links.forEach((link) => {
|
|
||||||
link.addEventListener('click', handleClick);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ import '../styles/sal.css';
|
|||||||
});
|
});
|
||||||
|
|
||||||
setActiveLink();
|
setActiveLink();
|
||||||
|
setUpLink();
|
||||||
|
setEmailLink();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -64,7 +66,41 @@ import '../styles/sal.css';
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setUpLink() {
|
||||||
|
const button = document.getElementById('up-link');
|
||||||
|
button?.addEventListener('click', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
window.scrollTo({
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
behavior: 'smooth',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEmailClick(event: Event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const currentTarget = event.currentTarget;
|
||||||
|
if (currentTarget instanceof HTMLElement) {
|
||||||
|
const { name, domain, tld } = currentTarget.dataset;
|
||||||
|
if (name && domain && tld) {
|
||||||
|
const mailto = `mailto:${name}@${domain}.${tld}`;
|
||||||
|
window.open(mailto, '_blank');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setEmailLink() {
|
||||||
|
const links = document.querySelectorAll('[data-email-link]');
|
||||||
|
|
||||||
|
links.forEach((link) => {
|
||||||
|
link.addEventListener('click', handleEmailClick);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setActiveLink();
|
setActiveLink();
|
||||||
|
setUpLink();
|
||||||
|
setEmailLink();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style is:global>
|
<style is:global>
|
||||||
|
|||||||
@@ -17,16 +17,4 @@ import { Link } from '.';
|
|||||||
<Sprite name="ri:arrow-up-line" class="h-icon-small w-icon-small" />
|
<Sprite name="ri:arrow-up-line" class="h-icon-small w-icon-small" />
|
||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<script>
|
|
||||||
const button = document.getElementById('up-link');
|
|
||||||
button?.addEventListener('click', (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
window.scrollTo({
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
behavior: 'smooth',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
3
types/swup.d.ts
vendored
3
types/swup.d.ts
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
declare module '@swup/a11y-plugin';
|
||||||
declare module '@swup/fade-theme';
|
declare module '@swup/fade-theme';
|
||||||
declare module '@swup/head-plugin';
|
declare module '@swup/head-plugin';
|
||||||
declare module '@swup/a11y-plugin';
|
|
||||||
declare module '@swup/preload-plugin';
|
declare module '@swup/preload-plugin';
|
||||||
|
declare module '@swup/scripts-plugin';
|
||||||
declare module '@swup/scroll-plugin';
|
declare module '@swup/scroll-plugin';
|
||||||
|
|||||||
Reference in New Issue
Block a user