julienmonnerie/public/assets/js/app.js

183 lines
4.5 KiB
JavaScript
Raw Normal View History

2022-08-02 18:50:27 +02:00
import Splide from '@splidejs/splide';
2022-06-17 17:51:59 +02:00
// ----------------------------------------------------------------------------
// DATA
// ----------------------------------------------------------------------------
2022-08-02 18:50:27 +02:00
// UTILS
const body = document.body;
2022-08-03 14:55:32 +02:00
// SPLIDE SLIDER
2022-08-02 18:50:27 +02:00
2022-08-03 14:55:32 +02:00
let splideSlider = document.querySelector('.splide');
2022-08-03 16:49:26 +02:00
const logoIcon = document.querySelector('.logo__icon');
2022-08-02 18:50:27 +02:00
2022-08-03 14:55:32 +02:00
// EXHIBITION IFRAME
2022-07-22 17:53:26 +02:00
const sidebar = document.querySelector('.sidebar');
2022-07-28 18:59:14 +02:00
const sidebarNavLinks = document.querySelectorAll('.sidebar__nav-link--internal');
const exhibitionIframe = document.querySelector('.exhibition');
2022-07-22 17:53:26 +02:00
2022-06-17 17:51:59 +02:00
// ----------------------------------------------------------------------------
2022-07-28 18:59:14 +02:00
// LOGIC
2022-06-17 17:51:59 +02:00
// ----------------------------------------------------------------------------
2022-07-28 18:59:14 +02:00
// UTILS
// Enable CSS :active pseudo-class in Safari Mobile
function enableActivePseudoClass() {
document.addEventListener("touchstart", function() {},false);
}
2022-06-17 17:51:59 +02:00
// Convert rem to pixels by getting font-size CSS property
function convertRemToPixels(rem) {
2022-08-02 18:50:27 +02:00
let fontSize = parseFloat(window.getComputedStyle(body).getPropertyValue('font-size'));
return rem * fontSize;
2022-06-17 17:51:59 +02:00
}
2022-08-03 14:55:32 +02:00
// SPLIDE SLIDER
2022-08-02 18:50:27 +02:00
function setUpSlider() {
2022-08-03 14:55:32 +02:00
if (splideSlider) {
splideSlider = new Splide('.splide', {
2022-08-02 18:50:27 +02:00
type: 'fade',
rewind: true,
rewindByDrag: true,
speed: 400,
fixedWidth: '100vw',
fixedHeight: '100vh',
arrows: false,
pagination: false,
easing: 'ease-in-out',
drag: true,
wheel: true
}).mount();
}
}
function goToNextSlideOnClick() {
2022-08-03 14:55:32 +02:00
if (splideSlider) {
splideSlider.on('click', function(e) {
splideSlider.go('>');
2022-08-02 18:50:27 +02:00
});
}
}
2022-08-03 16:49:26 +02:00
function turnLogoIconToWhite() {
if (logoIcon) {
logoIcon.classList.add('logo__icon--white');
}
}
function turnLogoIconToBlack() {
if (logoIcon) {
logoIcon.classList.remove('logo__icon--white');
}
}
function editLogoColorOnSlideActive() {
if (splideSlider) {
splideSlider.on('active', function(e) {
if (e.slide.getAttribute('data-logo-color') === 'white') {
turnLogoIconToWhite();
} else if (e.slide.getAttribute('data-logo-color') === 'black') {
turnLogoIconToBlack();
}
});
}
}
2022-08-01 16:59:46 +02:00
function enableLogoIconRotation() {
if (logoIcon) {
logoIcon.classList.add('logo__icon--rotate-horizontal-bottom');
}
}
function disableLogoIconRotation() {
if (logoIcon) {
logoIcon.classList.remove('logo__icon--rotate-horizontal-bottom');
}
}
2022-07-22 17:53:26 +02:00
2022-08-03 14:55:32 +02:00
function rotateLogoOnSliderMove() {
if (splideSlider && logoIcon) {
splideSlider.on('move', function(e) {
logoIcon.removeEventListener('animationiteration', disableLogoIconRotation);
enableLogoIconRotation();
});
splideSlider.on('moved', function(e) {
logoIcon.addEventListener('animationiteration', disableLogoIconRotation);
});
}
}
// EXHIBITION IFRAME
2022-07-22 17:53:26 +02:00
function slimDownSidebar() {
2022-07-28 18:59:14 +02:00
if (sidebar && !sidebar.classList.contains('sidebar--slimmed')) {
2022-07-22 17:53:26 +02:00
sidebar.classList.add('sidebar--slimmed');
}
}
2022-08-01 16:59:46 +02:00
function enableExhibitionIframeVisibility() {
if (exhibitionIframe) {
exhibitionIframe.classList.add('exhibition--visible');
}
}
2022-07-28 18:59:14 +02:00
2022-08-01 16:59:46 +02:00
function disableExhibitionIframeVisibility() {
if (exhibitionIframe) {
exhibitionIframe.classList.remove('exhibition--visible');
2022-07-28 18:59:14 +02:00
}
}
2022-08-01 16:59:46 +02:00
function editBackgroundColor(sidebarNavLink) {
if (body && sidebar) {
if (sidebarNavLink.getAttribute('data-background') === 'feldgrau') {
body.classList.remove('body--white-background');
sidebar.classList.remove('sidebar--white-background');
} else if (sidebarNavLink.getAttribute('data-background') === 'white') {
body.classList.add('body--white-background');
sidebar.classList.add('sidebar--white-background');
2022-07-28 18:59:14 +02:00
}
}
}
function loadExhibitionIframe() {
if (sidebarNavLinks.length > 0 && exhibitionIframe) {
2022-07-22 17:53:26 +02:00
for (let i = 0; i < sidebarNavLinks.length; i++) {
2022-07-28 18:59:14 +02:00
sidebarNavLinks[i].addEventListener('click', function(e) {
2022-08-01 16:59:46 +02:00
logoIcon.removeEventListener('animationiteration', disableLogoIconRotation);
2022-07-28 18:59:14 +02:00
enableLogoIconRotation();
2022-08-01 16:59:46 +02:00
disableExhibitionIframeVisibility();
2022-07-28 18:59:14 +02:00
exhibitionIframe.addEventListener('load', function(e) {
2022-08-01 16:59:46 +02:00
logoIcon.addEventListener('animationiteration', disableLogoIconRotation);
2022-07-28 18:59:14 +02:00
slimDownSidebar();
2022-08-01 16:59:46 +02:00
enableExhibitionIframeVisibility();
editBackgroundColor(sidebarNavLinks[i]);
2022-07-28 18:59:14 +02:00
});
});
2022-07-22 17:53:26 +02:00
}
}
}
2022-06-17 17:51:59 +02:00
// ----------------------------------------------------------------------------
// PROGRAM
// ----------------------------------------------------------------------------
2022-07-28 18:59:14 +02:00
// UTILS
enableActivePseudoClass();
2022-07-22 17:53:26 +02:00
2022-08-03 14:55:32 +02:00
// SPLIDE SLIDER
2022-08-02 18:50:27 +02:00
setUpSlider();
goToNextSlideOnClick();
2022-08-03 16:49:26 +02:00
editLogoColorOnSlideActive();
2022-08-03 14:55:32 +02:00
rotateLogoOnSliderMove();
2022-08-02 18:50:27 +02:00
2022-08-03 14:55:32 +02:00
// EXHIBITION IFRAME
2022-07-22 17:53:26 +02:00
2022-07-28 18:59:14 +02:00
loadExhibitionIframe();