Skip to content

Commit

Permalink
improvements in code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
michivonah committed Sep 7, 2024
1 parent 1b71879 commit 00ec2ab
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 290 deletions.
238 changes: 1 addition & 237 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<link rel="apple-touch-icon" sizes="167x167" href="assets/logo/favicon_256.png">
<link rel="canonical" href="https://michivonah.ch">
<script src="https://unpkg.com/[email protected]/dist/aos.js" async></script>
<script src="script.js" async></script>
<script src="https://unpkg.com/akar-icons-fonts"></script>
<script src="main.js" defer></script>
<link rel="stylesheet" type="text/css" href="style.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/dist/aos.css" media="screen"/>
<meta charset="UTF-8">
Expand Down Expand Up @@ -45,9 +45,6 @@
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="manifest" href="manifest.json">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<script defer src="https://data.mchvnh.ch/script.js" data-website-id="9b188ed8-77b0-4238-aef5-c1b3d48106e4"></script>

</head>
Expand Down Expand Up @@ -348,14 +345,6 @@ <h1 class="sectionTitle">Contact me</h1>
</div>

<div id="footerExpanded">
<div id="imprint">
<h3>Imprint <i class="ai-paper navicons"></i></h3>
<p><i class="ai-person"></i> Michael von Ah</p>
<p><i class="ai-location"></i> Obwalden, Switzerland</p>
<p><i class="ai-envelope"></i> [email protected]</p>
<p><i class="ai-phone"></i> 078 247 15 16 (for messages, don&prime;t use for calling)</p>
</div>

<div id="copyright">
<h3>Copyright <i class="ai-copy navicons"></i></h3>
<p>The content of this page was created by me or I have the rights to use it here.</p>
Expand All @@ -378,233 +367,8 @@ <h3>Copyright <i class="ai-copy navicons"></i></h3>
</div>
</div>

<div id="cookieBanner">
<div id="cookieImg">
<p id="cookieIcon">&#127850;</p>
</div>
<div id="cookieHint">
<h3>Hey, this site uses cookies!</h3>
<p>Don't worry, no cookies are used at the moment. This is just a preparation of the hint for later. Because at the moment this website is still under development.</p>
<button onclick="useCookie(true)">Accept!</button>
<button onclick="useCookie(false)">Stop!</button>
</div>
</div>

<div id="scroll-top">
<i class="ai-chevron-up"></i>
</div>


<script>
// Loading
window.addEventListener('load', () => {
document.getElementById('scroll-top').style.display = "none";
// check if site is released
//var timeToRelease = new Date('August 7, 2022 12:00:00').getTime() - new Date().getTime();
//if(timeToRelease > 0 && window.location.hostname == 'michivonah.ch') window.location = "https://michivonah.ch/countdown.html";
age(16, 9, 2005);
toggleSocialmedia();
// Check cookie banner
//localStorage.removeItem('cookies');
if(localStorage.getItem('cookies') != null){
document.getElementById('cookieBanner').style.display = "none";
}
// random home img
randomHomeImg();
AOS.init({disable: 'mobile'});
//AOS.init({disable: true});
// hide loadingscreen
document.getElementById('loadingScreen').style.display = "none";
});

document.getElementById('scroll-top').addEventListener("click", function(){
scrollToTop();
});

function scrollToTop(){
window.scroll(0, 0);
}

function scrollDown(){
window.scroll(0, window.innerHeight - 56);
}

function toggleSection(sectionName, type){
var section = document.getElementById(sectionName);
if(section.style.display == "block" || section.style.display == "flex"){
section.style.display = "none";
}
else{
section.style.display = type;
}
}


function toggleClass(className){
var elements = document.getElementsByClassName(className);
for(var i = 0; i < elements.length; i++){
if(elements[i].style.display == "block"){
elements[i].style.display = "none";
}
else{
elements[i].style.display = "block";
}
}
}

function closeNavbar(){
if(document.getElementById('closeNavbarPlaceholder').style.display == "block"){
document.getElementById("navbar-links").style.display = "none";
document.getElementById("closeNavbarPlaceholder").style.display = "none";
}
}

function toggleSocialmedia(){
var tabs = document.getElementsByClassName('socialTab');
for(var i = 0; i < tabs.length; i++){
var currentTabId = tabs[i].id;
var currentRadioButton = currentTabId.replace("social", "sm");;
var state = document.getElementById(currentRadioButton).checked;
if(state == true) document.getElementById(tabs[i].id).style.display = "block";
else document.getElementById(tabs[i].id).style.display = "none";
}
}

function toggleQuestion(){
if(event.target.tagName == "DIV"){
if(event.target.getElementsByTagName('p')[0].style.display == "none"){
event.target.getElementsByTagName('p')[0].style.display = "block";
event.target.getElementsByTagName('i')[0].style.transform = "rotate(180deg)";
}
else{
event.target.getElementsByTagName('p')[0].style.display = "none";
event.target.getElementsByTagName('i')[0].style.transform = "rotate(0deg)";
}
}
else if(event.target.tagName == "H3" || event.target.tagName == "I"){
if(event.target.parentElement.getElementsByTagName('p')[0].style.display == "none"){
event.target.parentElement.getElementsByTagName('p')[0].style.display = "block";
event.target.parentElement.getElementsByTagName('i')[0].style.transform = "rotate(180deg)";
}
else{
event.target.parentElement.getElementsByTagName('p')[0].style.display = "none";
event.target.parentElement.getElementsByTagName('i')[0].style.transform = "rotate(0deg)";
}
}
else console.log("An error occurred while opening this section. Element: {0}", event.target);
}

function checkForm(){
console.log();
var requiredFields = ['surname-field', 'lastname-field', 'email-field', 'message-text', 'terms'];
var errorCount = 0;
for(var i = 0; i < requiredFields.length; i++){
var currentElement = document.getElementById(requiredFields[i]);
currentElement.style.animation = null;
if(currentElement.checkValidity() == true){
currentElement.style.background = "var(--theme1)";
currentElement.style.animation = null;
}
else{
currentElement.classList.add("animate");
currentElement.style.background = "var(--red)";
currentElement.style.animation = "shake 250ms ease";
currentElement.classList.remove("animate");
errorCount++;
}
}
if(document.getElementById('honeypot').checked === true) errorCount++;
if(errorCount <= 0){
var name = document.getElementById('surname-field').value + " " + document.getElementById('lastname-field').value;
sendWhatsapp(name, document.getElementById('email-field').value, document.getElementById('subject-field').value, document.getElementById('message-text').value);
//document.getElementById("contact-form").submit();
}
}

function useCookie(usersChoice){
let cookieBanner = document.getElementById('cookieBanner');
cookieBanner.style.display = "none";
if(usersChoice == true){
localStorage.setItem('cookies', true);
}
else{
localStorage.setItem('cookies', false);
}
}

function showQrcode(src, imgId, old){
// src = 'assets/socialmedia/insta-code.png'
// old = assets/socialmedia/michi_pb.jpeg
// img = document.getElementById('insta1Img')
var src = "https://api.qrserver.com/v1/create-qr-code/?size=900x900&format=png&margin=0&data=http://insta.michivonah.ch/";
var image = document.getElementById(imgId).src;
if(image != src) document.getElementById(imgId).src = src;
else document.getElementById(imgId).src = old;
}

function sendWhatsapp(name, mail, subject, text){
var mail = mail.replaceAll('@', '%40');
var subject = subject.replaceAll(' ', '%20');
var text = text.replaceAll(' ', '%20');
var text = text.replaceAll('?', '%3F');
var text = text.replaceAll('!', '%21');
var whatsappUrl = "https://wa.me/41782471516?text=Name%3A%20" + name + "%0AE-Mail%3A%20" + mail + "%0ASubject%3A%20" + subject + "%0AMessage%3A%20" + text;
window.open(whatsappUrl);
}

function randomHomeImg(){
var homeImg = document.getElementById('homeImg');
var num = Math.floor(Math.random() * (4 - 1) + 1);
homeImg.src = "assets/bitmojis/home_" + num + ".png";
}

function age(birthday, birthmonth, birthyear){
var birthmonth = birthmonth - 1;
var ageText = document.getElementById('age');
var date = new Date();
var year = date.getFullYear();
if(date.getMonth() == birthmonth){
if(date.getDate() >= birthday){
ageText.innerHTML = Number(year) - birthyear;
}
else{
ageText.innerHTML = Number(year) - birthyear - 1;
}
}
else if(date.getMonth() >= birthmonth){
ageText.innerHTML = Number(year) - birthyear;
}
else if(date.getMonth() <= birthmonth){
ageText.innerHTML = Number(year) - birthyear - 1;
}
}

window.addEventListener('scroll', function(e) {
var navbar = document.getElementById('navbar');
var scrollTop = document.getElementById('scroll-top');
if(this.scrollY > 20){
navbar.style.background = "var(--theme1)";
navbar.style.color = "#fff";
scrollTop.style.display = "flex";
}
else{
if(window.innerWidth <= 640){
if(document.getElementById('navbar-links').style.display == "block"){
navbar.style.background = "var(--theme1)";
scrollTop.style.display = "none";
}
else{
navbar.style.background = "transparent";
scrollTop.style.display = "none";
}
}
else{
navbar.style.background = "transparent";
scrollTop.style.display = "none";
}
}
});

</script>
</body>
</html>
Loading

0 comments on commit 00ec2ab

Please sign in to comment.