File: D:/HostingSpaces/SBogers10/ste.komma.pro/resources/js/global/resizeHandler.js
/* ==========================================================================
Resize handler
- Handler the objects which are or need to be recalculated on resize
========================================================================== */
const ResizeHandler = {
time: Date.now(),
timeout: null,
waitThrottle: 1000,
waitDebounce: 500,
//Initialisation
init: function () {
// Trigger start up resize
ResizeHandler.triggerOnInit();
// Throttle Resize
window.addEventListener('resize', function () {
if ((ResizeHandler.time + ResizeHandler.waitThrottle - Date.now()) < 0) {
ResizeHandler.triggerThrottle();
ResizeHandler.time = Date.now();
}
});
// Smooth Resize
window.addEventListener('resize', function () {
ResizeHandler.triggerSmooth();
});
// Debounce Resize
window.addEventListener('resize', function () {
if(isset(ResizeHandler.timeout)) clearTimeout(ResizeHandler.timeout);
ResizeHandler.timeout = setTimeout(ResizeHandler.triggerDebounce, ResizeHandler.waitDebounce);
});
},
// Trigger on start up
// All function should be in here
triggerOnInit: function () {
ResizeHandler.trainingCardTypeSet();
// console.log('Initial Resize');
},
// Trigger resize functions with throttle (preferred)
triggerThrottle: function () {
// console.log('Throttled Resize');
},
// Trigger resize on debounce
triggerDebounce: function () {
// console.log('Debounce Resize');
ResizeHandler.trainingCardTypeSet();
},
// Trigger resize on the flight
triggerSmooth: function () {
// console.log('Smooth Resize');
},
// ------------------------------ CUSTOM SCROLL HANDLERS ------------------------------------
// Example function
// resizeWhatDoesItCostAdvantageFigure: function () {
// var el = document.querySelector('.advantages-own-guiding-row figure');
// if(isset(el)){
// el.style.maxHeight = 'none';
// el.style.maxHeight = el.offsetHeight + 'px';
// }
// },
trainingCardTypeSet(){
const trainingCards = document.querySelectorAll('.js-training-card');
if (window.matchMedia('(min-width: 780px)').matches) {
// Wide viewport
for(let i = 0; i < trainingCards.length; i++){
const trainingCard = trainingCards[i];
if (trainingCard.classList.contains('c-training-card--summary')) {
trainingCard.classList.remove('c-training-card--summary');
}
}
} else {
// Small viewport
for(let i = 0; i < trainingCards.length; i++){
const trainingCard = trainingCards[i];
trainingCard.classList.add('c-training-card--summary');
}
}
},
};
ResizeHandler.init();
export default ResizeHandler;