import './bootstrap'; //import 'resources/js/app.js'; import '@fortawesome/fontawesome-free/css/all.min.css'; //Countdown date (adjust this date to your desired countdown target) const countdownDate = new Date('2024-08-17T11:00:00').getTime(); //Update the countdown every second const countdownElement = document.getElementById('countdown'); const countdownTimer = setInterval(() => { //Get the current date and time const now = new Date().getTime(); //Calculate the time remaining const distance = countdownDate - now; //Calculate days, hours, minutes, and seconds const days = Math.floor(distance / (1000 * 60 * 60 * 24)); const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((distance % (1000 * 60)) / 1000); //Format the countdown into a string const countdownHTML = `
${days}
:
${hours.toString().padStart(2, '0')}
:
${minutes.toString().padStart(2, '0')}
:
${seconds.toString().padStart(2, '0')}
Hari
Jam
Minit
Saat
`; //Display the countdown in the element countdownElement.innerHTML = countdownHTML; //If the countdown is over, clear the timer and display a message if (distance < 0) { clearInterval(countdownTimer); countdownElement.innerHTML = 'Majlis berlangsung'; } }, 1000); // Update every second (1000 milliseconds) document.addEventListener('DOMContentLoaded', function () { imageLoading() reset() // reset everrything to ensure smooth sessionStorage.setItem("initial-load", "true"); // will be used by click event }); document.addEventListener('click', function () { let initLoad = sessionStorage.getItem("initial-load") // parts is intro cover let parts = document.getElementsByClassName("part"); for (let part of parts) { part.classList.add("shadow-lg") } let body = document.querySelector("body"); body.classList.remove("no-scroll"); // the intro - only done once and if (initLoad == "true") { playMusic(); sessionStorage.removeItem("initial-load") // delay timer to have that umpph feels my G setTimeout(() => { // smooth scroll only happen for first render smoothScrollBy(100, 3500); }, 600) } }); function smoothScrollBy(distance, duration) { const start = window.pageYOffset; const startTime = performance.now(); function scroll() { const now = performance.now(); const time = Math.min(1, (now - startTime) / duration); const timeFunction = time * (2 - time); // Ease out effect window.scrollTo(0, start + timeFunction * distance); if (time < 1) { requestAnimationFrame(scroll); } } requestAnimationFrame(scroll); } // to ensure all images is loaded before starting animation and gimmick function imageLoading() { const images = document.querySelectorAll("img"); let loadedCount = 0; const totalImages = images.length; images.forEach(image => { if (image.complete) { loadedCount++; } else { image.addEventListener("load", () => { loadedCount++; checkAllImagesLoaded(); }); image.addEventListener("error", () => { loadedCount++; checkAllImagesLoaded(); }); } }); function checkAllImagesLoaded() { if (loadedCount === totalImages) { let loading = document.getElementById("loading"); loading.remove(); // parts is intro cover let parts = document.getElementsByClassName("part"); for (let part of parts) { part.classList.remove("hidden") } } } //somehow the server work so fast, script doesn't have much time to set the load eventlistener //thus we check here, to ensure checkAllImagesLoaded run checkAllImagesLoaded(); } function reset() { // reset to top let body = document.querySelector("body"); body.classList.remove("no-scroll"); window.scrollTo(0, 0); setTimeout(() => { body.classList.add("no-scroll"); }, 400) } function playMusic(){ var audioElement = document.getElementById('player'); var hasPlayed = false; if (!hasPlayed) { console.log('play') var playPromise = audioElement.play(); if (playPromise !== undefined) { playPromise.then(function() { // Automatic playback started! hasPlayed = true; // Prevent further attempts to play }).catch(function(error) { // Automatic playback failed. console.log('Autoplay failed: ' + error); }); } } }