<?php /** * Tawk.to * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to support@tawk.to so we can send you a copy immediately. * * @copyright Copyright (c) 2016 Tawk.to * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ ?> <!--Start of Tawk.to Script--><script type="text/javascript">
    var Tawk_API = Tawk_API || {};
    var Tawk_LoadStart = null;
    var tawkLoadDelay = <?= (int) $block->getLoadDelayMs() ?>;
    var tawkForceShowWidget = <?= $block->shouldForceShowWidget() ? 'true' : 'false' ?>;

    function handleCookiebotPosition(isChatOpen) {
        var styleId = 'tawk-cookiebot-fix';
        var styleEl = document.getElementById(styleId);

        if (!styleEl) {
            styleEl = document.createElement('style');
            styleEl.id = styleId;
            document.head.appendChild(styleEl);
        }

        const transformValue = isChatOpen ? '-45px' : '0';
        styleEl.innerHTML = '@media (max-width: 768px) { #CookiebotWidget { ' +
            `transform: translateY(${transformValue}) !important }}`
    }

    Tawk_API.onChatMaximized = function () {
        handleCookiebotPosition(true);
    }

    Tawk_API.onChatMinimized = function () {
        handleCookiebotPosition(false);
    }

    Tawk_API.onLoad = function () {
        if (tawkForceShowWidget && window.Tawk_API && typeof window.Tawk_API.showWidget === 'function') {
            window.Tawk_API.showWidget();
        }
    }

    function loadTawkWidget() {
        if (window.__tawkWidgetLoaded) {
            return;
        }

        window.__tawkWidgetLoaded = true;
        Tawk_LoadStart = new Date();

        var s1 = document.createElement("script");
        var s0 = document.getElementsByTagName("script")[0];
        s1.async = true;
        s1.setAttribute('fetchpriority', 'low');
        s1.src = '<?= $block->escapeUrl($block->getEmbedUrl()) ?>';
        s1.charset = 'UTF-8';
        s1.setAttribute('crossorigin', '*');
        s0.parentNode.insertBefore(s1, s0);
    }

    function scheduleTawkWidgetLoad() {
        if (document.readyState === 'complete') {
            setTimeout(loadTawkWidget, tawkLoadDelay);
            return;
        }

        window.addEventListener('load', function () {
            setTimeout(loadTawkWidget, tawkLoadDelay);
        }, { once: true });
    }

    <?php $customer_details = $block->getCurrentCustomerDetails(); ?> <?php if ($customer_details !== null): ?>
    Tawk_API.visitor = {
        name : '<?= $block->escapeJs($customer_details['name']); ?>',
        email : '<?= $block->escapeJs($customer_details['email']); ?>'
    };
    <?php endif; ?> scheduleTawkWidgetLoad();</script><!--End of Tawk.to Script-->