HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode-site/src/js/components/white-label-cfd-broker/Hero.js
const Hero = () => {
    const images = document.querySelectorAll('.blockHeroImg');

    const containers = document.querySelectorAll('.blockHeroTheme');
    containers.forEach((item) => {
        const image = item.querySelector('.blockHeroImg');
        item.style.height = image.offsetHeight + 'px'
    });

    const itemsM = document.querySelectorAll('.blockHeroThemeItemM');
    const items = document.querySelectorAll('.blockHeroThemeItem');
    const containerItems = document.querySelector('.blockHeroThemeItems');
    const imageEl = document.querySelector('#blockHeroImage');
    const loader = document.querySelector('.blockHeroThemeLoader');
    const progress = document.querySelector('.blockHeroThemeLoaderProgress');

    let prevColor = null;
    let timeOut = null;
    let arrayImage = [];

    const toggleItems = (innerItems) => {
        innerItems.forEach((item) => {
            item.addEventListener('click', () => {
                if (!prevColor) {
                    prevColor = item.dataset.color;
                }

                innerItems.forEach((innerItem) => {
                    if (innerItem.classList.contains('active')) {
                        prevColor = innerItem.dataset.color;
                        innerItem.classList.remove('active');
                    }
                });

                item.classList.add('active');

                if (images.length >= 2) {
                    images.forEach((img) => {
                        if (img.dataset.color === item.dataset.color) {
                            img.classList.add('active');
                        } else {
                            if (!timeOut && img.dataset.color === prevColor) {
                                img.classList.add('hide');

                                timeOut = setTimeout(() => {
                                    img.classList.remove('hide');
                                    img.classList.remove('active');

                                    clearTimeout(timeOut);
                                    timeOut = null;
                                }, 300);
                            }
                        }
                    });
                } else {
                    loader.style.opacity = 1;
                    progress.style.width = 0;
                    containerItems.style.pointerEvents = 'none';

                    const img = new Image();

                    img.onChangeSize = function (loaded, total) {
                        loader.style.opacity = 1;
                        progress.style.width = parseInt((loaded / total) * 100) + '%';

                        if (parseInt((loaded / total) * 100) >= 95) {
                            imageEl.style.opacity = 0;
                        }

                        if (parseInt((loaded / total) * 100) === 100) {
                            imageEl.style.opacity = 1;
                        }
                    }

                    img.onload = function () {
                        containerItems.style.pointerEvents = 'all';

                        if (!arrayImage.map(image => image.color).includes(item.dataset.color)) {
                            arrayImage.push({color: item.dataset.color, src: img.src});
                        }

                        const findImage =  arrayImage.find(image => image.color === item.dataset.color);

                        if (findImage) {
                            imageEl.src = findImage.src;
                        }

                        loader.style.opacity = 0;

                        let timeout = setTimeout(() => {
                            progress.style.width = 0;
                            clearTimeout(timeout);
                        }, 500);
                    }

                    img.load(`../../../assets/white-label-cfd-broker/hero/CTA_pic_${item.dataset.color}.png`);
                }
            });
        });
    }

    toggleItems(items);
    toggleItems(itemsM);
};

export default Hero;